Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Provide accessor to the span implementation #1240

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

dashpole
Copy link
Collaborator

@dashpole dashpole commented Oct 29, 2020

This is needed if the SDK needs to cast to its underlying type.

Part of open-telemetry/opentelemetry-go#93

@nilebox

@dashpole dashpole requested review from rghetia and a team as code owners October 29, 2020 20:04
@google-cla google-cla bot added the cla: yes label Oct 29, 2020
@@ -148,6 +148,11 @@ type Span struct {
internal SpanInterface
}

// Internal returns the underlying implementation of the Span
func (s *Span) Internal() SpanInterface {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain why is this necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see that makes sense.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants