This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Provide accessor to the span implementation#1240
Merged
dashpole merged 1 commit intocensus-instrumentation:masterfrom Nov 2, 2020
Merged
Provide accessor to the span implementation#1240dashpole merged 1 commit intocensus-instrumentation:masterfrom
dashpole merged 1 commit intocensus-instrumentation:masterfrom
Conversation
nilebox
reviewed
Oct 29, 2020
| } | ||
|
|
||
| // Internal returns the underlying implementation of the Span | ||
| func (s *Span) Internal() SpanInterface { |
There was a problem hiding this comment.
Can you please explain why is this necessary?
Collaborator
Author
There was a problem hiding this comment.
This is needed when attempting to add an OpenCensus span to the OpenTelemetry context using otel.ContextWithSpan(context.Context, otel.Span) In order to do that, we need to be able to get the underlying Span implementation. The full implemnetation would look something like:
// This is the OpenCensus FromContext function, implemented using opentelemetry's SpanFromContext
func (o *otelTracer) FromContext(ctx context.Context) *octrace.Span {
otSpan := otel.SpanFromContext(ctx)
return // convert the opentelemetry span into the OC span implementation
}
// This is the OpenCensus NewContext function, implemented using opentelemetry's ContextWithSpan
func (o *otelTracer) NewContext(parent context.Context, s *octrace.Span) context.Context {
// Below, I need to call s.Internal() in order to have an interface I can cast to my internal type.
// For example, my internal type could wrap an opentelemetry Span, which I could use in ContextWithSpan
if myspan, ok := s.Internal().(*myspanimplementation); ok {
return otel.ContextWithSpan(parent, // get an opentelemetry Span from myspan)
}
// The user must have created the octrace Span using a different tracer, and we don't know how to store it.
return parent
}
nilebox
approved these changes
Oct 29, 2020
This was referenced Mar 15, 2021
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is needed if the SDK needs to cast to its underlying type.
Part of open-telemetry/opentelemetry-go#93
@nilebox