Skip to content
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
dashpole:replace_sdk_v2
Nov 2, 2020
Merged

Provide accessor to the span implementation#1240
dashpole merged 1 commit intocensus-instrumentation:masterfrom
dashpole:replace_sdk_v2

Conversation

@dashpole
Copy link
Copy Markdown
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 a team and rghetia as code owners October 29, 2020 20:04
@google-cla google-cla bot added the cla: yes label Oct 29, 2020
}

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

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
Copy Markdown
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
Copy Markdown

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.

2 participants