Skip to content

Span not finished when subscription is cancelled #133

@NHebrard

Description

@NHebrard

Hello!

In the TracingOperator component is there any good reason the not finish the span when the wrapped source has been canceled?

I would change

class TracingOperator extends MonoOperator<Void, Void> {
    
    @Override
    public void subscribe(final CoreSubscriber<? super Void> subscriber) {
        // ...
        try (final Scope scope = tracer.scopeManager().activate(span)) {
            exchange.getAttributes().put(TracingWebFilter.SERVER_SPAN_CONTEXT, span.context());
            source.subscribe(new TracingSubscriber(subscriber, exchange, context, span, spanDecorators));
        }
    }

To

class TracingOperator extends MonoOperator<Void, Void> {
    
    @Override
    public void subscribe(final CoreSubscriber<? super Void> subscriber) {
        // ...
        try (final Scope scope = tracer.scopeManager().activate(span)) {
            exchange.getAttributes().put(TracingWebFilter.SERVER_SPAN_CONTEXT, span.context());
            source.doOnCancel(() -> span.finish())
               .subscribe(new TracingSubscriber(subscriber, exchange, context, span, spanDecorators));
        }
    }

Happy to contribute if needed!

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions