opentracing-java icon indicating copy to clipboard operation
opentracing-java copied to clipboard

Mechanism to understand when ActiveSpan has been finished

Open objectiser opened this issue 7 years ago • 15 comments

Currently, if writing a wrapper tracer, there is no way to know when the ActiveSpan has actually been finished, as the application (or framework integrations) simply call deactivate, but as this is ref counted, any call to this method could potentially finish the span.

Options are: a) The wrapper tracer would also need to reference count b) The deactivate method could return a boolean indicating whether the associated ActiveSpan has been finished c) The BaseSpan could support an isFinished method which could be checked after deactivate d) Implement some active span lifecycle support

objectiser avatar Jun 08 '17 07:06 objectiser

b) +1, IMO, the return value should be enough.

wu-sheng avatar Jun 08 '17 08:06 wu-sheng

Very important issue for me as it seems my current wrapper implementation would not work with OT 0.30.0.

felixbarny avatar Jun 08 '17 13:06 felixbarny

The wrapper implementations are becoming more and more difficult with the growing API. I think an Observer facility would make more sense (Cf. https://github.com/opentracing/opentracing-go/pull/135)

yurishkuro avatar Jun 08 '17 14:06 yurishkuro

(sorry for my delay getting to this)

IMO we should not change core APIs for the convenience of wrappers. If there's a non-theoretical performance problem or something important is impossible, those would be different stories altogether.

I think I'm basically agreeing with @yurishkuro on this: since we can factor this sort of thing into a dedicated TracerObserver, that seems like the safest (i.e., most minimal) place to start.

bhs avatar Jun 10 '17 23:06 bhs

I like an Observer as it is clearer on how to extend an existing tracer. However, we need to make very clear that observer implementations may degrade performance of the whole system if not carefully applied.

sjoerdtalsma avatar Jun 12 '17 05:06 sjoerdtalsma

+1 on observable for span events. Something like finish event should do the job here.

Currently, if writing a wrapper tracer, there is no way to know when the ActiveSpan has actually been finished, as the application (or framework integrations) simply call deactivate, but as this is ref counted, any call to this method could potentially finish the span.

ActiveSpan#deactivate https://github.com/opentracing/opentracing-java/blob/master/opentracing-api/src/main/java/io/opentracing/ActiveSpan.java#L48 should call finish. So wrapping span#finish should be enough to know when span has been finished. Or am I missing something?

pavolloffay avatar Jun 14 '17 11:06 pavolloffay

Currently, if writing a wrapper tracer, there is no way to know when the ActiveSpan has actually been finished, as the application (or framework integrations) simply call deactivate, but as this is ref counted, any call to this method could potentially finish the span.

I think this can be done at the moment by simply doing this:

      // span builder wrapper code..
        @Override
        public ActiveSpan startActive() {
            Span span = startManual();  
            return wrappedTracer.makeActive(span);
        }

and you don't have to wrap any continuation or active span. Then ActiveSpan#deactivate calls span#finish https://github.com/opentracing/opentracing-java/blob/master/opentracing-api/src/main/java/io/opentracing/ActiveSpan.java#L48

pavolloffay avatar Jun 14 '17 15:06 pavolloffay

Documentation note about I approach^^^ I proposed. The implementation shouldn't do something like this: https://github.com/openzipkin/brave-opentracing/pull/43/files#diff-ec734b127c956fb921d0d3c12254a659R56. Though, it's still only a PR.

pavolloffay avatar Jun 19 '17 08:06 pavolloffay

Maybe BaseSpan should have a unwrap method similar to java.sql.Wrapper#unwrap?

felixbarny avatar Jun 19 '17 08:06 felixbarny

@felixbarny it makes more sense on ActiveSpan no? to return Span

pavolloffay avatar Jun 20 '17 15:06 pavolloffay

I'm not too sure about that. When its on BaseSpan, its available on Span and ActiveSpan. Do you mean we don't need it on Span?

felixbarny avatar Jun 20 '17 21:06 felixbarny

I don't think it's needed on Span. Do you have a concrete example?

pavolloffay avatar Jun 21 '17 08:06 pavolloffay

No, I don't have a concrete use case. I'm not too familiar with the new api tbh. Why do you think Spans should not (need to) be unwrapped?

felixbarny avatar Jun 21 '17 10:06 felixbarny

Hey all,

Wondering if we should rename this issue to something such as "Observer API"? (which, I think, many people would like to have eventually).

(Also, the unwrap proposal has been mentioned in a few other issues already ;) )

carlosalberto avatar Jun 24 '18 16:06 carlosalberto

I would recommend a new issue with such title and refer to this one. In Go there is already an observer API (in contrib only), which only applies to the span life cycle, not the Scope life cycle, so it's a decision whether those should be merged or not. Also, it has been often mentioned that observers would work better if there was a stable span ID exposed from the SpanContext, so we can also link to that issue/PR as a dependency.

yurishkuro avatar Jun 24 '18 17:06 yurishkuro