Skip to content
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

Move context utils outside of the Tracer #527

Closed
wants to merge 9 commits into from

Conversation

bogdandrutu
Copy link
Member

@bogdandrutu bogdandrutu commented Mar 24, 2020

Rational:

  • Context is now a standalone concept in OpenTelemetry and we don't need to provide abstractions on top of context interactions, so no need to have getCurrentSpan an interface.
  • Remove duplicate APIs in some languages like Java where there is an util class to allow context interactions and also the methods on the tracer.
  • Simplify context interaction by not requiring to pass a Tracer to classes/functions where no need to create a new Span.

Fixes: #455

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Comment on lines 229 to 230
The API MUST provide methods to (depending on the language, global functions
or util class e.g. `TracingContextUtils`):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The API MUST provide methods to (depending on the language, global functions
or util class e.g. `TracingContextUtils`):
The API MUST provide methods (or, depending on the language, global functions
or util class e.g. `TracingContextUtils`) to:

Copy link
Member

Choose a reason for hiding this comment

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

also s/TracingContextUtils/TracingContext/

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we need something as suffix or prefix if we want to be consistent for CorrelationContext which has Context at the end, because will be ugly to name that CorrelationContextContext :(. Any ideas?

Copy link
Member

Choose a reason for hiding this comment

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

If context interaction is done via static util class, then TracingContext.activeSpan() looks a lot better than TracingContextUtils.activeSpan().

Copy link
Member Author

Choose a reason for hiding this comment

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

I do agree with you but I am trying to think how would I name this class for "CorrelationContext" package. If I find a good name for that and ensure consistency I am all to remove Utils.

Copy link
Member

Choose a reason for hiding this comment

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

CorrelationContext can remain CorrelationContext. It can represent both the object that stores correlations and the namespace for static functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yurishkuro I'd be up for not using TraceContext and keeping the activation bits in CorrelationContext - we will end up with too many classes having the Context suffix (some of them doing different things, i.e. TraceContext doing activation handling only, CorrelationContext doing both activation handling PLUS as a container of key-values).

There was already some confusion in the past because of the fact we had both CorrelationContext and Context, so this could get worse ;)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-Authored-By: Yuri Shkuro <yurishkuro@users.noreply.github.com>
The OpenTelemetry library achieves in-process context propagation of `Span`s by
way of the [Context](./context.md).

An `active Span` referes to a Span that is set to an
Copy link
Member

Choose a reason for hiding this comment

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

That means, for other languages (e.g. Go) all Spans are inactive?

Copy link
Member Author

Choose a reason for hiding this comment

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

that means there is no concept of active span. The current span is defined as the Span in the context passed to the function so no need to getCurrentSpan just getSpanFromContext.

Copy link
Member

@yurishkuro yurishkuro Mar 24, 2020

Choose a reason for hiding this comment

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

I would suggest:

  • having a clear definition of "current" in the context.md, which can be defined both for implicit prop and for explicit prop (closest context in the lexical scope)
  • converge on a single term for spans, either "active" or "current", not both, and define it as "span stored in the current context"

Copy link
Contributor

Choose a reason for hiding this comment

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

@yurishkuro I agree on keeping either current or active, not both terms. However, I'm wondering if this should be done in a follow up PR.

Copy link
Member

Choose a reason for hiding this comment

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

@carlosalberto I agree but this PR adds wording using both terms, at least within the PR it should be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR does not add any new reference to either active or current, both were in the previous text.

@carlosalberto
Copy link
Contributor

@bogdandrutu Overall LGTM. @yurishkuro raises a few interesting points (on which all I agree), so I'd be up for merging this one after the issues have been resolved (a few of them can be done in a follow up too, as already mentioned).

* Get/Set a Span from/to a Context
* Make a given Span as active

The API MUST internally leverage the Context in order to get and set the current
Copy link
Member

Choose a reason for hiding this comment

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

This sounds like logic is going into the API? Before the API was almost entirely interfaces.

Unless I'm misunderstanding this it seems instead of the Tracer simply calling to the sdk with a context and some options to start a span there is log in the API for juggling the span in the context, resulting in multiple calls from the API to the SDK?

How does this work out for the streaming SDK for example?

Copy link
Member

Choose a reason for hiding this comment

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

It was my understanding that the API should never call the SDK and cannot depend on it. Otherwise it would be impossible to have third party SDKs

Copy link
Member

Choose a reason for hiding this comment

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

The API is functions/methods that are implemented by the SDK, calling API functions results in whatever SDK is being used (if any) being called. Users do not call the SDK directly.

Copy link
Member

Choose a reason for hiding this comment

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

@tsloughter As far as I'm aware, Context is not a part of the SDK but a third top-level item that the API and SDK depend on.

@jmacd
Copy link
Contributor

jmacd commented Mar 25, 2020

There used to be specification language about the Span having a method to get the Tracer that created it. I am opposed to this functionality, but I can no longer find any specification for it. In Go we have this:

https://github.com/open-telemetry/opentelemetry-go/blob/4c69dd3234c6b71d030ecd1b523644cd3ccde0a2/api/trace/api.go#L87

Can we remove that now

In my work on Resource Scope, open-telemetry/oteps#78, that method caused a headache. If something similar must be done, I would argue that Spans should be able to provide you with their parent's Context, not their Tracer.

@tsloughter
Copy link
Member

@jmacd if the span has no method to get the Tracer then how does it run processors when it ends?

The same problem I had that lead me to open #516

@jmacd
Copy link
Contributor

jmacd commented Mar 25, 2020

@tsloughter I am assuming that the Span has a reference to the Tracer that created it, but that it does not expose this to the user. I believe that if a user wants to get at the Tracer that created a Span, the user should retain a reference to the Context that was used to start the Span.

specification/api-tracing.md Outdated Show resolved Hide resolved
The OpenTelemetry library achieves in-process context propagation of `Span`s by
way of the [Context](./context.md).

An `active Span` referes to a Span that is set to an
Copy link
Member

Choose a reason for hiding this comment

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

"a span that is set to an attached context" sounds unclear to me

specification/api-tracing.md Outdated Show resolved Hide resolved
specification/api-tracing.md Outdated Show resolved Hide resolved
specification/api-tracing.md Outdated Show resolved Hide resolved
The OpenTelemetry library achieves in-process context propagation of `Span`s by
way of the [Context](./context.md).

An `active Span` referes to a Span that is set to an
Copy link
Member

Choose a reason for hiding this comment

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

@carlosalberto I agree but this PR adds wording using both terms, at least within the PR it should be consistent.

specification/api-tracing.md Outdated Show resolved Hide resolved
bogdandrutu and others added 3 commits March 27, 2020 08:15
Co-Authored-By: Armin Ruech <armin.ruech@gmail.com>
Co-Authored-By: Armin Ruech <armin.ruech@gmail.com>
Co-Authored-By: Armin Ruech <armin.ruech@gmail.com>
bogdandrutu and others added 2 commits March 27, 2020 08:55
Co-Authored-By: Armin Ruech <armin.ruech@gmail.com>
@bogdandrutu
Copy link
Member Author

@jmacd @tsloughter This PR does not changes anything related to Span having or not having a method to return the Tracer that created it.

@tsloughter
Copy link
Member

From the spec meeting I thought I'd show how we do propagation in the tracer in Erlang.

-spec w3c_propagators() -> {ot_propagation:http_extractor(), ot_propagation:http_injector()}.
w3c_propagators() ->
    ToText = fun ot_propagation_http_w3c:inject/2,
    FromText = fun ot_propagation_http_w3c:extract/2,
    Injector = ot_ctx:http_injector(?TRACER_KEY, ?TRACER_CTX, ToText),
    Extractor = ot_ctx:http_extractor(?TRACER_KEY, ?EXTERNAL_SPAN_CTX, FromText),
    {Extractor, Injector}.

Applications can then setup a propagation in the SDK for the tracer of the SDK:

{CorrelationExtractor, CorrelationInjector} = ot_correlations:get_http_propagators(),
{TracerExtractor, TracerInjector} = ot_tracer_default:w3c_propagators(),

opentelemetry:set_http_extractor([TracerExtractor, CorrelationExtractor]),
opentelemetry:set_http_injector([TracerInjector, CorrelationInjector])

But now I see maybe your issue is that I'm using the SDK tracer directly, ot_tracer_default? Which I think makes sense, it is what knows the keys for tracer context.

@carlosalberto carlosalberto added spec:context Related to the specification/context directory spec:trace Related to the specification/trace directory labels Jun 12, 2020
@carlosalberto carlosalberto added the release:required-for-ga Must be resolved before GA release, or nice to have before GA label Jul 2, 2020
@Oberon00
Copy link
Member

Oberon00 commented Jul 7, 2020

I think this is partially obsolete after #619.

@bogdandrutu bogdandrutu deleted the tracercontext branch July 20, 2020 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:required-for-ga Must be resolved before GA release, or nice to have before GA spec:context Related to the specification/context directory spec:trace Related to the specification/trace directory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Context interaction from Tracer/CorrelationContextManager
8 participants