question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should there be such a thing as a `null` activeSpan()? Or SpanContext?

See original GitHub issue

Now that #115 is in, we need to contend with the scenario where ActiveSpanSource.activeSpan() / Tracer.activeSpan() returns null.

As I see it, there are three options.

  1. Do nothing. Callers check for null and get on with their lives.
  2. Specify that implementations use some sort of NoopSpan, but do not specify which
  3. Specify that implementations use a particular instance of a particular object… maybe NoSpan.INSTANCE instead of NoopSpan.INSTANCE. I.e., the caller could do equality testing and be guaranteed to check for the “no-span Span” without adding a new isReal() sort of method to the Span interface. Of course the various tagging methods would do nothing here.

There is the related case of Tracer.extract() when there’s, well, nothing to extract. Should it return null, an unspecified non-null SpanContext, or a particular SpanContext instance to represent the case of being absent?

See also https://github.com/opentracing/opentracing-java/pull/115/files/bf4606c596955c7e353cfa92bba372d5ecd2e206#r114108185 and https://github.com/opentracing/opentracing-java/pull/115/files/bf4606c596955c7e353cfa92bba372d5ecd2e206#r109821172 where this came up. And also https://github.com/opentracing/opentracing-java/pull/111#discussion_r111682133 .

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:36 (32 by maintainers)

github_iconTop GitHub Comments

3reactions
ryondaycommented, Mar 30, 2018

Begging you to just return a NoopSpan or something if there’s no active span.

1reaction
ivantopocommented, Jun 22, 2017

Hey @bhs, this is definitely not a “every day” coding situation, most people will be just fine with the instrumentation provided by the libraries. This is just to have a safe experience when it happens that you are required to tweak the instrumentation to cover some corner cases on how you application is implemented or doing “manual instrumentation”. I ended up creating a few utility functions that help our code hide the null checks and provide a safer API to the users, but that doesn’t prevent anyone from doing something like Kamon.activeSpan().setBaggageItem("my-thing", "my-value") and ending up throwing a NPE.

I understand that Java developers might be used to do null checks because, well, it’s Java, that’s how things have been done historically… but things are moving towards safer ways of writing code (think about Optional making it into Java!) and I would say it’s in the best interest of the OT spec to provide safety in all cases, even the less common ones.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Opentrace Activespan Is Null - ADocLib
The public API of the Elastic APM Java agent lets you customize and will return a noop transaction, which means that you never...
Read more >
Tracer (OpenTracing API 0.32.0 API) - javadoc.io
Returns: the current ScopeManager , which may be a noop but may not be null. activeSpan. Span activeSpan().
Read more >
Advanced Usage — ddtrace documentation - Read the Docs
Context management enables parenting to be done implicitly when creating new spans by using the active span as the parent of a new...
Read more >
Manual Instrumentation | OpenTelemetry
You can build the providers by using the SdkTracerProvider.builder() and ... makeCurrent()) { // In this scope, the span is the current/active span...
Read more >
opentracing - Bountysource
Should there be such a thing as a `null ` activeSpan()? Or SpanContext? ... implement the ScopeManager#activeSpan() method assuming there's only one tracer ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found