-
Notifications
You must be signed in to change notification settings - Fork 851
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
Added SpanProcessor OnEnding callback #6367
Added SpanProcessor OnEnding callback #6367
Conversation
sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanProcessor.java
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6367 +/- ##
============================================
- Coverage 90.05% 90.01% -0.05%
- Complexity 6276 6330 +54
============================================
Files 697 703 +6
Lines 18949 19086 +137
Branches 1858 1881 +23
============================================
+ Hits 17065 17180 +115
- Misses 1312 1331 +19
- Partials 572 575 +3 ☔ View full report in Codecov by Sentry. |
this.endEpochNanos = endEpochNanos; | ||
hasEnded = true; | ||
if (spanProcessor.isOnEndingRequired()) { | ||
spanProcessor.onEnding(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's probably a mistake to be calling this under the lock. I believe we only want to do internal state management while the lock is being held, not call not-under-our-control methods provided by users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lock was actually intentionally hold to cover this part of the spec:
The SDK MUST guarantee that the span can no longer be modified by any other thread
before invokingOnEnding
of the firstSpanProcessor
. From that point on, modifications
are only allowed synchronously from within the invokedOnEnding
callbacks.
This part was added to the spec so that SpanProcessors can be sure that the state they see the span in is actually consistent and not prone to race conditions due to span modifications from the application code.
However, I now switched to a different way of implementing this, because as you said exposing the lock is probably not the best way of achieving the desired safety here.
# Conflicts: # docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple minor comments, but seems generally good. Thanks!
sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/ExtendedSpanProcessor.java
Outdated
Show resolved
Hide resolved
sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/ExtendedSpanProcessor.java
Outdated
Show resolved
Hide resolved
sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/ExtendedSpanProcessor.java
Outdated
Show resolved
Hide resolved
sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/ExtendedSpanProcessor.java
Outdated
Show resolved
Hide resolved
sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpan.java
Outdated
Show resolved
Hide resolved
Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com>
I approve of putting this in a separate interface. But, we should provide documentation on how someone could use this, as well. |
What do you think would be the best place for this? Just a javadoc in |
I think the ideal way to do this is a unit test. Let's add an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding the example. couple of nits but ready otherwise ready to merge IMO
sdk/trace/src/test/java/io/opentelemetry/sdk/trace/internal/ExtendedSpanProcessorUsageTest.java
Outdated
Show resolved
Hide resolved
sdk/trace/src/test/java/io/opentelemetry/sdk/trace/internal/ExtendedSpanProcessorUsageTest.java
Outdated
Show resolved
Hide resolved
sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpan.java
Outdated
Show resolved
Hide resolved
Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com>
Implementation for the spec change open-telemetry/opentelemetry-specification#4024.