Consider adding t-string support to Logs API

Offen
#5,787 4 Kommentare 1 Reaktion 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

@herin049 arbeitet bereits daran.

Seit 16.10.2026.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
2.7k
Forks
1.1k
Ø Merge
3 T. 12 Std.
Gemergte PRs (30 T.)
16

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus open-telemetry/opentelemetry-python

Alle Issues in open-telemetry/opentelemetry-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.