Consider adding t-string support to Logs API

未关闭
#5,787 4 条评论 1 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 2 天内回复

@herin049 已经在做这个了。

开始于 2026年10月16日。

评估

这个 Issue 还没有评估数据。

描述

feature-request
Is your feature request related to a problem?

Currently the logs API only supports passing the log body directly as a string that must be eagerly evaluated. That is, if one wishes to dynamically construct a log record body with dynamic content, users must either construct this string eagerly or guard the emit call in an is-enabled check.

# additional boilerplate (unpleasant)
if logger.enabled(severity_number=SeverityNumber.DEBUG, event_name="cache.miss"):
    logger.emit(body=f"cache miss for {expensive_key()}", severity_number=SeverityNumber.DEBUG)

# evaluated eagerly (wasteful) 
logger.emit(body=f"cache miss for {expensive_key()}", severity_number=SeverityNumber.DEBUG)

t-strings (available in Python 3.14+) provide a convenient workaround, for example:

# evaluated lazily (only when logger is enabled)
logger.emit(body=t"cache miss for {expensive_key}", severity_number=SeverityNumber.DEBUG)

The SDK would then evaluate callables in the template expression lazily.

Adding support for t-strings would require a breaking API change if added after log stabilization. It may be worth adding before stabilization to avoid having to make this change later.

Describe the solution you'd like

N/A

Describe alternatives you've considered

No response

Additional Context

No response

Would you like to implement a fix?

Yes

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

主要语言
Python
星标
2.7k
派生
1.1k
平均合并
3 天 12 小时
30 天内合并 PR
16

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

open-telemetry/opentelemetry-python 的其他 Issue

查看 open-telemetry/opentelemetry-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。