logging: exception.message is the exception's first argument, not its message
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- backend-api-design
Research direction
Start with LoggingHandler._get_attributes in opentelemetry/instrumentation/logging/handler.py and inspect the same expression in opentelemetry/instrumentation/structlog/__init__.py and the deprecated SDK handler at opentelemetry/sdk/_logs/_internal/__init__.py. Check the tests for exception attributes and compare log output with Span.record_exception for the examples in the issue. Done means all three handlers export str(exception) consistently, including exceptions with multiple or no arguments.
Written by the indexing model from the issue text.
Description
(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_attributesopentelemetry/instrumentation/structlog/__init__.py,StructlogProcessor._get_attributesopentelemetry/sdk/_logs/_internal/__init__.py, the SDK's deprecatedLoggingHandler(in opentelemetry-python)
Would you like to implement a fix?
No
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 51
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from open-telemetry/opentelemetry-python-contrib
-
jinja2: tracing ignores suppress_instrumentation()Possibly taken @RichardoMrMu claimed this 37 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
open-telemetry/opentelemetry-python-contrib#5167 · 2 comments ·
Maintainers usually reply within 2 days
-
opentelemetry-instrumentation-tornado: server metrics recorded twice when a handler raises, http.server.active_requests goes negativePossibly taken @sivakumar-mahalingam claimed this 51 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
open-telemetry/opentelemetry-python-contrib#5113 · 2 comments · 2 reactions ·
Maintainers usually reply within 2 days
-
httpx: `http.client.duration` has no `net.peer.name` in the default semconv modePossibly taken @jbyers44 claimed this 53 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
open-telemetry/opentelemetry-python-contrib#5100 ·
Maintainers usually reply within 2 days
-
`LoggingInstrumentor` `log_hook` only runs when there is an active spanPossibly taken @git-jxj claimed this 61 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
open-telemetry/opentelemetry-python-contrib#5069 ·
Maintainers usually reply within 2 days
-
[grpc] AIO server spans record uncaught exceptions twicePossibly taken @somuai claimed this 60 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
open-telemetry/opentelemetry-python-contrib#5068 · 1 comment ·
Maintainers usually reply within 2 days
All issues in open-telemetry/opentelemetry-python-contrib
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
docling-project/docling-pipelines#669 ·
Maintainers usually reply within 1 day
-
blocked kind/enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
opendatahub-io/agent-eval-harness#329 · 2 comments · 1 reaction ·
-
cc_wrapper crashes with ValueError on Windows when a path is on another drivePossibly taken @TrapsterDK claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
tweag/rules_haskell#2492 ·
Maintainers usually reply within 1 day