-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store current Span instead of local and remote SpanContext in context…
….Context (#1731) * Store Span instead of local/remote SpanContext in Context Now that the SpanContext has a remote identifier, storing a Span's SpanContext two separate ways in a Context (one for local another for remote) is unnecessary and adds complication throughout the project when determining heredity of a Span. This moves to storing the Span directly in the Context uniformly (for both local and remote) as current Span. In the process, it updates the getter/setter functionality the `trace` package provides and replaces the distributed heredity logic throughout the project with just using the current Span as the parent if it exists. * Update trace/context.go Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> * Assert propagators context remote state Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
- Loading branch information
Showing
16 changed files
with
191 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package trace // import "go.opentelemetry.io/otel/trace" | ||
|
||
import "context" | ||
|
||
type traceContextKeyType int | ||
|
||
const currentSpanKey traceContextKeyType = iota | ||
|
||
// ContextWithSpan returns a copy of parent with span set as the current Span. | ||
func ContextWithSpan(parent context.Context, span Span) context.Context { | ||
return context.WithValue(parent, currentSpanKey, span) | ||
} | ||
|
||
// ContextWithRemoteSpanContext returns a copy of parent with rsc set explicly | ||
// as a remote SpanContext and as the current Span. The Span implementation | ||
// that wraps rsc is non-recording and performs no operations other than to | ||
// return rsc as the SpanContext from the SpanContext method. | ||
func ContextWithRemoteSpanContext(parent context.Context, rsc SpanContext) context.Context { | ||
return ContextWithSpan(parent, nonRecordingSpan{sc: rsc.WithRemote(true)}) | ||
} | ||
|
||
// SpanFromContext returns the current Span from ctx. | ||
// | ||
// If no Span is currently set in ctx an implementation of a Span that | ||
// performs no operations is returned. | ||
func SpanFromContext(ctx context.Context) Span { | ||
if span, ok := ctx.Value(currentSpanKey).(Span); ok { | ||
return span | ||
} | ||
return noopSpan{} | ||
} | ||
|
||
// SpanContextFromContext returns the current Span's SpanContext. | ||
func SpanContextFromContext(ctx context.Context) SpanContext { | ||
return SpanFromContext(ctx).SpanContext() | ||
} |
Oops, something went wrong.