-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement span processor's OnEnding #5756
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
Changes from 3 commits
440d0b1
999175e
fb6bba5
5b53cc5
34a68be
793d5fd
3613902
6c04318
675b6f4
67a67f0
c7fe407
27565c9
2537c50
80c873a
43e3438
f4ae0f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package x // import "go.opentelemetry.io/otel/sdk/internal/x" | ||
|
|
||
| import "go.opentelemetry.io/otel/trace" | ||
|
|
||
| // OnEndingSpanProcessor represents span processors that allow mutating spans | ||
| // just before they are ended and made immutable. | ||
| type OnEndingSpanProcessor interface { | ||
| // OnEnding is called while the span is finished, and while spans are still | ||
| // mutable. It is called synchronously and cannot block. | ||
| OnEnding(trace.Span) | ||
dmathieu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import ( | |
| "go.opentelemetry.io/otel/codes" | ||
| "go.opentelemetry.io/otel/internal/global" | ||
| "go.opentelemetry.io/otel/sdk/instrumentation" | ||
| "go.opentelemetry.io/otel/sdk/internal/x" | ||
| "go.opentelemetry.io/otel/sdk/resource" | ||
| semconv "go.opentelemetry.io/otel/semconv/v1.26.0" | ||
| "go.opentelemetry.io/otel/trace" | ||
|
|
@@ -120,6 +121,9 @@ type recordingSpan struct { | |
| // value of time.Time until the span is ended. | ||
| endTime time.Time | ||
|
|
||
| // hasEnded records whether the span is fully ended. | ||
| hasEnded bool | ||
|
|
||
| // status is the status of this span. | ||
| status Status | ||
|
|
||
|
|
@@ -171,10 +175,8 @@ func (s *recordingSpan) IsRecording() bool { | |
| if s == nil { | ||
| return false | ||
| } | ||
| s.mu.Lock() | ||
| defer s.mu.Unlock() | ||
|
|
||
| return s.endTime.IsZero() | ||
| return !s.hasEnded | ||
dmathieu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // SetStatus sets the status of the Span in the form of a code and a | ||
|
|
@@ -417,7 +419,6 @@ func (s *recordingSpan) End(options ...trace.SpanEndOption) { | |
| } | ||
|
|
||
| s.mu.Lock() | ||
| // Setting endTime to non-zero marks the span as ended and not recording. | ||
| if config.Timestamp().IsZero() { | ||
| s.endTime = et | ||
| } else { | ||
|
|
@@ -426,6 +427,15 @@ func (s *recordingSpan) End(options ...trace.SpanEndOption) { | |
| s.mu.Unlock() | ||
|
|
||
| sps := s.tracer.provider.getSpanProcessors() | ||
| for _, sp := range sps { | ||
| if oesp, ok := sp.sp.(x.OnEndingSpanProcessor); ok { | ||
| oesp.OnEnding(s) | ||
| } | ||
| } | ||
dmathieu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| s.mu.Lock() | ||
|
||
| s.hasEnded = true | ||
| s.mu.Unlock() | ||
|
|
||
| if len(sps) == 0 { | ||
| return | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.