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 static access of current span to Span. #1795

Closed
wants to merge 1 commit into from

Conversation

anuraaga
Copy link
Contributor

I was thinking of talking about this after changes like #1753 and #1737 (after which I'm thinking of moving context interaction to OpenTelemetry) but figured it doesn't hurt to split this out as an idea.

I think getting the current span is a very common operation, especially for javaagent users. They will rarely create spans, or deal with tracers. But adding attributes to a span is very common for anyone.

Response myRequestHandler(Request request) {
  Span.current().setAttribute("userid", request.getUserId());
}

We are also toying with the idea of having static methods on Tracer

Response myRequestHandler(Request request) {
  Tracer.currentSpan().setAttribute("userid", request.getUserId());
}

For simple usage, which is common for accessing the current span since when you have a tracer, you usually also will have created a span from it to track yourself, the former feels more intuitive and looks like better code from a user perspective to me. Tracer is a very important concept for instrumentation authors, but not so important for end users.

@codecov
Copy link

codecov bot commented Oct 14, 2020

Codecov Report

Merging #1795 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1795   +/-   ##
=========================================
  Coverage     85.53%   85.53%           
- Complexity     1374     1375    +1     
=========================================
  Files           166      166           
  Lines          5308     5309    +1     
  Branches        549      549           
=========================================
+ Hits           4540     4541    +1     
  Misses          569      569           
  Partials        199      199           
Impacted Files Coverage Δ Complexity Δ
...va/io/opentelemetry/trace/TracingContextUtils.java 100.00% <ø> (ø) 7.00 <0.00> (ø)
...ain/java/io/opentelemetry/trace/DefaultTracer.java 97.14% <100.00%> (ø) 5.00 <1.00> (ø)
api/src/main/java/io/opentelemetry/trace/Span.java 100.00% <100.00%> (ø) 2.00 <1.00> (+1.00)
...ain/java/io/opentelemetry/sdk/trace/TracerSdk.java 100.00% <100.00%> (ø) 6.00 <1.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e539890...c837e22. Read the comment docs.

@iNikem
Copy link
Contributor

iNikem commented Oct 14, 2020

It seems to contradict this spec issue

Remove all current public helpers from Tracer and Trace Context Utilities that interact with "current Context".
Things like Get the currently active span and Set the currently active span should be removed.

@Oberon00
Copy link
Member

I think that is a spec wording issue and should be fixed there. IMHO the spec just wants these methods to not require a Span/Tracer instance as parameters (e.g. implicit this parameter)

* @since 0.3.0
*/
public static Span getCurrentSpan() {
static Span getCurrentSpan() {
return getSpan(io.opentelemetry.context.Context.current());
Copy link
Contributor

Choose a reason for hiding this comment

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

odd fully-qualified class here. might cleaning it up while you're here?

@carlosalberto
Copy link
Contributor

I think that is a spec wording issue and should be fixed there

No, we also want to reduce the places where we expose this functionality.

That being said, whether we keep this functionality (Tracer or TracingContextUtils), I'd personally be fine with Span.current() as a single shortcut (that is, no more shortcuts, at least for now). Else, maybe a reason to have Tracer.getCurrentSpan() as a static member.

Copy link
Contributor

@jkwatson jkwatson left a comment

Choose a reason for hiding this comment

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

I'm definitely not a fan of TCU, so this seems like a good change to me. Would love @carlosalberto to comment, as well.

@Oberon00
Copy link
Member

Oberon00 commented Oct 14, 2020

@carlosalberto

No, we also want to reduce the places where we expose this functionality.

But this is not adding more places?

@carlosalberto
Copy link
Contributor

But this is not adding more places?

Yes! And that's why I'd be fine with a single shortcut (or, well, none). The idea is that Spec change is to not have all duplicated (at this moment we have many operations all over the place).

@jkwatson
Copy link
Contributor

We had some discussion about this during the SIG meeting this morning. The request from @bogdandrutu , which I think everyone agreed with, is possibly an end-state-describing issue that can track all the work on this cleanup, so we can have a good handle on where you/we are headed. For instance, we all like having Span.current(), but many of us also think that if we add it, we should remove at least one of the other public options for accessing the current span.

So, the ask is for a little bit of design work to describe where you see the end-state of the API (this might tie into the instance/global work, additionally, if you feel they are related).

@jkwatson jkwatson self-requested a review October 14, 2020 17:16
@anuraaga
Copy link
Contributor Author

Thanks, summarized in #1807

@@ -35,7 +35,7 @@ public static Tracer getInstance() {

@Override
public Span getCurrentSpan() {
return TracingContextUtils.getCurrentSpan();
return Span.current();
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that TracingContextUtils still is the root, I'd be happier with using that one instead (users and instrumentation are free to use whatever they want of course ;) )

Copy link
Contributor

Choose a reason for hiding this comment

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

this is gone from the Tracer now, so probably not relevant. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Disagree - we want to use whatever the root is. Otherwise, let's simply move the logic to Span ;) (although the Spec may not allow that).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just saying that this method is no longer on the Tracer on the main branch, so this comment can't apply without adding it back to the Tracer.

@@ -24,7 +24,7 @@

@Override
public Span getCurrentSpan() {
return TracingContextUtils.getCurrentSpan();
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise.

Copy link
Contributor

Choose a reason for hiding this comment

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

same

@bogdandrutu
Copy link
Member

Proposing for the moment to close this PR and update or create a new PR with the latest discussion from #1807

@carlosalberto
Copy link
Contributor

@bogdandrutu Fine by me to close this PR while we discuss our options.

@anuraaga anuraaga closed this Oct 19, 2020
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.

6 participants