Consider adding t-string support to Logs API

Aperta
#5,787 4 commenti 1 reazione 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@herin049 ci sta già lavorando.

Dal 16/10/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.

Lingua principale
Python
Stelle
2.7k
Fork
1.1k
Merge medio
3g 12h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di open-telemetry/opentelemetry-python

Tutte le issue di open-telemetry/opentelemetry-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.