Repository navigation
fix(opentelemetry): handle DroppedSpan when transaction_max_spans is exceeded - #2789
jonatasemidio wants to merge 1 commit into
Conversation
|
💚 CLA has been signed |
🤖 GitHub commentsJust comment with:
|
a02bdfe to
cacd6ae
Compare
cacd6ae to
0a064d4
Compare
|
run docs-build : Re-trigger the docs validation. |
|
@jonatasemidio Hey Jonatas, thanks for your PR. Did you hit this issue yourself or are you looking after some open source contribution experience? |
|
Hi @xrmx Thanks for checking! To be transparent, it’s a bit of both... We’re validating this tool in POCs for an internal agentic reconciliation pipeline, and we ran into this during testing. Since we’d like to rely on it in our flow without waiting on the normal backlog, I also saw this as a nice opportunity to contribute something useful back. |
As I wrote in the issue if you are starting something new I would go all-in on OpenTelemetry with something like our distribution of OpenTelemetry Python instead https://github.com/elastic/elastic-otel-python |
|
Hi @xrmx That makes total sense, and I'm not sure how this slipped past our radar, so thanks for the honest heads-up! I'll pivot our POC to OpenTelemetry with elastic-otel-python instead. Thank you very much! Also, I have an internal static verification tool that helped me spot this issue, and I suspect other Elastic Python projects might have similar ones. Since I'd love to contribute real fixes with tests, do you have any suggestions? |
What does this pull request do?
Hi team! 👋
When an active transaction exceeds
ELASTIC_APM_TRANSACTION_MAX_SPANS,current_transaction.begin_span(...)returns aDroppedSpan(wherecontextandidareNone,nameis a read-only property, and.transactionis not set).Previously, creating or ending spans through the OpenTelemetry bridge (
elasticapm.contrib.opentelemetry) crashed once the span limit was reached:Tracer.start_spanattemptedelastic_span.context["otel_spankind"] = spankind(TypeError: 'NoneType' object does not support item assignment).Span.set_attributeattempted"otel_attributes" not in self.elastic_span.contextwhenattributeswere passed (TypeError).Span.endcalled_set_types()on exit (AttributeErroronNonecontext), andSpan.get_span_context/Span.is_recording/Span.update_nameassumed a recordedSpanorTransaction.This PR updates
Tracer.start_spanandSpansoDroppedSpaninstances behave as safe non-recording spans—matching howelasticapm.capture_span()handles dropped spans:otel_spankindcontext assignment inTracer.start_spanand attribute writes inSpan.set_attributewhencontextisNone.DroppedSpandirectly inSpan.end()(preservingexecution_contextcleanup and repeat-end()idempotency) without calling_set_types().SpanContext(trace_id=0, span_id=0, is_remote=False) fromget_span_context(),Falsefromis_recording(), and guardupdate_name()onDroppedSpan.tests/contrib/opentelemetry/tests.pycovering nested spans, attributes, andSpanmethods pasttransaction_max_spans.Related issues
Closes #2245