Consider adding t-string support to Logs API

Đang mở
#5,787 4 bình luận 1 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@herin049 đang làm issue này rồi.

Từ ngày 16/10/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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.

Ngôn ngữ chính
Python
Star
2.7k
Fork
1.1k
Merge trung bình
3 ngày 12 giờ
Pull request đã merge (30 ngày)
16

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của open-telemetry/opentelemetry-python

Tất cả issue của open-telemetry/opentelemetry-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.