Should there be such a thing as a `null` activeSpan()? Or SpanContext?
See original GitHub issueNow 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.
- Do nothing. Callers check for
null
and get on with their lives. - Specify that implementations use some sort of
NoopSpan
, but do not specify which - Specify that implementations use a particular instance of a particular object… maybe
NoSpan.INSTANCE
instead ofNoopSpan.INSTANCE
. I.e., the caller could do equality testing and be guaranteed to check for the “no-span Span” without adding a newisReal()
sort of method to theSpan
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:
- Created 6 years ago
- Reactions:1
- Comments:36 (32 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Begging you to just return a NoopSpan or something if there’s no active span.
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.