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

fix: set context in in_span #551

Closed
wants to merge 1 commit into from
Closed

fix: set context in in_span #551

wants to merge 1 commit into from

Conversation

fbogsany
Copy link
Contributor

@fbogsany fbogsany commented Jan 12, 2021

THIS IS NOT INTENDED TO BE MERGED AS IS - IT IS INTENDED FOR DISCUSSION OF SEMANTICS ONLY

#549 shows two code examples that behave differently. At first glance, it seems like they should behave the same way, and this PR attempts to "fix" the Tracer.in_span helper to make them behave the same way.

I want to make it clear that, after close reading of the spec, I do NOT think we should merge this. I think the current behaviour is correct, even if it isn't immediately intuitive.

in_span is a helper that we've added. The spec states:

Span creation MUST NOT set the newly created Span as the currently active Span by default, but this functionality MAY be offered additionally as a separate operation.

This is what in_span implements. The spec says nothing about this optional operation setting an outer Context, and I don't think it should. It should simply behave as described: create a span as if start_span were called with the same parameters and then make it active for the duration of the provided block, using Trace.with_span.

As discussed in today's call, the behaviour we're trying to achieve in #549 doesn't seem like a common case, and largely falls under the heading of "Kafka is hard".

cc @Asafb26

span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, with_parent: with_parent)
Trace.with_span(span) { |s, c| yield s, c }
if with_parent.nil?
span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, with_parent: with_parent)
Copy link
Contributor

Choose a reason for hiding this comment

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

If with_parent is nil, why pass it here?

span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, with_parent: with_parent)
Trace.with_span(span) { |s, c| yield s, c }
else
OpenTelemetry::Context.with_current(with_parent) do
Copy link
Contributor

@johnnyshields johnnyshields Jan 17, 2021

Choose a reason for hiding this comment

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

Another way to code this would be to make OpenTelemetry::Context.with_current yield and return if with_parent is nil. That would eliminate the awkward if statement in this method.

Base automatically changed from master to main January 28, 2021 22:57
@mwear
Copy link
Member

mwear commented Mar 11, 2021

I think that we probably want this behavior. I mentioned this on #630, but without this change our Rack instrumentation does not automatically pick up baggage. We could treat this as a bug in the Rack instrumentation, and not use in_span, but this is now a second instance where we've run into this issue.

@fbogsany
Copy link
Contributor Author

I think we should fix the Rack instrumentation, and probably other instrumentation that propagates trace context (Sidekiq?). My concern with changing behaviour of in_span now is that there is an active project in the Specification SIG aiming to define a convenience API for OpenTelemetry, and this falls squarely in that domain. Changing instrumentation and recommendations now will not break later if something like in_span is specified as in this PR. Conversely, changing in_span now will cause breakage in instrumentation and (more importantly) client code if the spec ends up reflecting our current implementation.

@fbogsany
Copy link
Contributor Author

Replaced by #729

@fbogsany fbogsany closed this Apr 30, 2021
@fbogsany fbogsany deleted the in_span-sets-context branch January 21, 2022 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants