logging: exception.message is the exception's first argument, not its message

Đang mở Phù hợp với người mới
#5,353 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Bắt đầu với LoggingHandler._get_attributes trong opentelemetry/instrumentation/logging/handler.py và kiểm tra biểu thức tương tự trong opentelemetry/instrumentation/structlog/__init__.py cũng như handler SDK đã lỗi thời tại opentelemetry/sdk/_logs/_internal/__init__.py. Kiểm tra các bài kiểm thử cho thuộc tính ngoại lệ và so sánh đầu ra log với Span.record_exception cho các ví dụ trong issue. Công việc hoàn tất khi cả ba handler xuất str(exception) nhất quán, kể cả với ngoại lệ có nhiều đối số hoặc không có đối số.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

(Posted by Claude on my behalf)

Describe your environment

OS: Linux
Python version: 3.13
Package version: opentelemetry-instrumentation-logging 0.66b2, opentelemetry-sdk 1.45.2 (the same code is on main)

What happened?

LoggingHandler sets exception.message to str(value.args[0]). For any exception whose message is not its first argument, the exported attribute is wrong, and it disagrees with what Span.record_exception exports for the same exception, which uses str(exception).

Exception str(exc) log exception.message span exception.message
OSError(2, "No such file or directory") [Errno 2] No such file or directory 2 [Errno 2] No such file or directory
ValueError("bad value", 42) ('bad value', 42) bad value ('bad value', 42)
ValueError() (empty) attribute absent (empty)

OSError and its subclasses are the common case: every file and socket error exports its errno as the message.

Steps to Reproduce
import logging

from opentelemetry.instrumentation.logging.handler import LoggingHandler
from opentelemetry.sdk._logs import LoggerProvider
from opentelemetry.sdk._logs.export import InMemoryLogRecordExporter, SimpleLogRecordProcessor

exporter = InMemoryLogRecordExporter()
provider = LoggerProvider()
provider.add_log_record_processor(SimpleLogRecordProcessor(exporter))
log = logging.getLogger("demo")
log.addHandler(LoggingHandler(logger_provider=provider))

try:
    raise OSError(2, "No such file or directory")
except OSError:
    log.exception("failed")

print(exporter.get_finished_logs()[-1].log_record.attributes["exception.message"])
Expected Result

[Errno 2] No such file or directory, i.e. str(exc), as Span.record_exception exports (EXCEPTION_MESSAGE: str(exception) in opentelemetry/sdk/trace/__init__.py).

Actual Result

2

Additional context

The same expression is in three places:

  • opentelemetry/instrumentation/logging/handler.py, LoggingHandler._get_attributes
  • opentelemetry/instrumentation/structlog/__init__.py, StructlogProcessor._get_attributes
  • opentelemetry/sdk/_logs/_internal/__init__.py, the SDK's deprecated LoggingHandler (in opentelemetry-python)
Would you like to implement a fix?

No

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

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-contrib

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

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.