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.

Remove finishSpanOnClose flag

See original GitHub issue

This is a follow up on https://github.com/opentracing/opentracing-java/issues/267. The underlying issue of that one is that you can’t remember the finishSpanOnClose flag when implementing a bridge for ScopeManager#active().

The point of this issue is to remove the finishSpanOnClose flag altogether, as it is only useful in try-with-resources constructs which are a bad practice because you can’t can’t log exceptions as the span is closed before the catch block. To cite the main README.md:

Note that startActive(true) finishes the span on Scope.close(). Use it carefully because the try-with-resources construct finishes the span before the catch or finally blocks are executed, which makes logging exceptions and setting tags impossible. It is recommended to start the span and activate it later in try-with-resources. This makes the span available in catch and finally blocks.

So we are basically officially admitting that finishSpanOnClose is a bad practice.

You could argue that try-with-resources is valid if you don’t want to log exceptions. But what if a user then later decides that they do want to log exceptions? Do they still remember that they can’t use try-with-resources + a catch block then? I would most likely forget about that.

The finishSpanOnClose just enables some syntactic sugar after all which turns out to be problematic. As flag essentially advocates a bad practice, I suggest removing it.

Transition: Of course, we can’t just remove the flag which would introduce a breaking change.

Instead, I propose adding the method io.opentracing.Tracer.SpanBuilder#startActive() without arguments, which has the same semantics like calling spanBuilder.startActive(false). Also, deprecate io.opentracing.Tracer.SpanBuilder#startActive(boolean finishSpanOnClose). This method can then be removed on a later release (for example 1.0.0-RC1)

The Scope interface can still extend from Closeable, because logging an exception is still valid to do after the scope is closed.

I think, even after doing this, https://github.com/opentracing/opentracing-java/issues/267 (Deprecate or remove ScopeManager.active()) is still relevant, but maybe less severe.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
felixbarnycommented, Jul 26, 2018

The problem is that it requires people to actually read (and remember) the documentation because it’s counter-intuitive and thus error-prone.

0reactions
carlosalbertocommented, Oct 18, 2018

Hey @felixbarny ! as we merged #301, shall we close this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I remove a flag in C? - Stack Overflow
Short Answer. You want to do an Bitwise AND operation on the current value with a Bitwise NOT operation of the flag you...
Read more >
Recently Active 'Opentracing' Questions - ADocLib
active active API is that it implies that the same instance is returned as when the Scope has been created and that the...
Read more >
Tracer (Apache Hadoop Common 3.3.4 API)
No-Op Tracer (for now) to remove HTrace without changing too many files. ... newScope(String description, SpanContext spanCtx, boolean finishSpanOnClose).
Read more >
dd-trace - UNPKG
n/* eslint-disable no-proto */\nmodule.exports = Object. ... property instead of delete + defineProperty\n options.sham - add a flag to not completely full ...
Read more >
opentracing - Bountysource
Being part of the official API would remove this annotation from specific ... "finishSpanOnClose" in "try-with-resources" is still the main documented way ...
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