`SpanProcessor.on_end` exceptions escape cleanup and replace application exceptions
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- observability
Research direction
Start in opentelemetry-sdk/src/opentelemetry/sdk/trace/init.py at SynchronousMultiSpanProcessor.on_end and trace the call through Span.end. Verify that exceptions from SpanProcessor.on_end are handled and logged without replacing an application exception or escaping when no application exception exists.
Written by the indexing model from the issue text.
Description
Steps to Reproduce
from opentelemetry.sdk.trace import SpanProcessor, TracerProvider
class RaisingProcessor(SpanProcessor):
def on_end(self, span):
raise RuntimeError("processor failed")
provider = TracerProvider()
provider.add_span_processor(RaisingProcessor())
tracer = provider.get_tracer("reproduction")
with tracer.start_as_current_span("operation"):
raise ValueError("application failed")
Expected Result
This method MUST be called synchronously within the
Span.End()API, therefore it should not block or throw an exception.
OpenTelemetry implementations MUST NOT throw unhandled exceptions at runtime.
API methods that accept external callbacks MUST handle all errors.
SynchronousMultiSpanProcessor.on_end invokes processors without an exception guard. The exception escapes through Span.end during context-manager cleanup.
Actual Result
The caller receives RuntimeError("processor failed"), with the application’s ValueError in __context__. Replacing the application’s raise with pass also propagates RuntimeError.
Would you like to implement a fix?
--- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
+++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
@@ -187,3 +187,6 @@
def on_end(self, span: "ReadableSpan") -> None:
for sp in self._span_processors:
- sp.on_end(span)
+ try:
+ sp.on_end(span)
+ except Exception:
+ logger.exception("Exception while calling SpanProcessor.on_end.")
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.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 5d 29m
- Merged PRs (30d)
- 17
Contributor 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
-
Baggage is ignored by W3CBaggagePropagator and erronously causes warning 'Invalid baggage entry' Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
open-telemetry/opentelemetry-python#5678 · 1 reaction ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
open-telemetry/opentelemetry-python#5664 · 4 comments ·
-
bug tests
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
All issues in open-telemetry/opentelemetry-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100