-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runs the processors before finishing the span #1690
Runs the processors before finishing the span #1690
Conversation
Signed-off-by: Gustavo Pantuza <[email protected]>
Heavy 👎 (don't feel discouraged by it though, the need is indeed there) This change does not conform to the specification. Modifying the span in the onEnd/on_finish method is not permitted. There is a new |
Just quickly chiming in, tldr this is a limitation of the spec. You bring up valid practical considerations (which I agree with the spirit of!) but we are beholden to the specification that states spans have to be ended before being passed into onend https://opentelemetry.io/docs/specs/otel/trace/sdk/#onendspan Looks like there's the concept of "onending" that sortve is what you're looking for, but it's in "development" within the spec https://opentelemetry.io/docs/specs/otel/trace/sdk/#onending Some of the more knowledgable folks and maintainers here can provide better context with the precise language on why this is working as intended, and suggested workarounds (monkeypatch the sdk itself, some sort of cloning of spans, etc) or path forward. |
"in development" means the spec is brand new and may still change, in which case the SDKs would have to change too. |
Thank you @dmathieu for all the clarifications. I totally agree with everything you have mentioned. Do you folks mind if I try to implement the new Spec? Is there anyone working in such thing already? |
I am closing this PR since, based on the suggestion made here, I have opened another Pull Request (#1713) addressing the Open Telemetry Spec. |
Hi 👋🏼
This Pull Request simply moves the processors call to the beginning of the
finish()
method.Why?
Otherwise, you can't modify the span getting finished. Processors are run AFTER the span
@ended
variablegets updated to
true
. Thus, the span is locked for changes.Real use case
Suppose you want to add extra attributes to you spans on the way out the door.
Therefore, you can create a custom processor by implementing a child class of
OpenTelemetry::SDK::Trace::SpanProcessor
and overriding the methodon_finish()
.This method receives the span getting finished and you can then add new attributes, right?
Not exactly, cause by calling
add_attributes
you receive an error:Calling add_attributes on an ended Span
.Whit that, my personal assumption is that you can not do anything useful inside
on_finish()
methodof a custom Processor cause the span will always be
@ended
when this method is called.The changes
This PR makes the span
finish()
method to iterate calling every Processor BEFORE actually endingthe span. It will allow processors to modify spans before actually finishing it.
Other argument: on_start method
If you look at the way this Span class calls
on_start
method, you will see it being the last thing in theinitialize()
method. That makes sense, we first create the span, then we call each processor for that particular span.The
on_finish()
method should do the opposite: run processors FIRST, then finish the span. Does it make sense?Considerations
Please, let me know in case you folks think I should do something else for this PR.