Skip to content

Improve context propagation for rxjava1 observables #7686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package datadog.trace.instrumentation.rxjava;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.capture;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;

import datadog.trace.bootstrap.instrumentation.api.AgentScope;
Expand All @@ -15,7 +15,7 @@ public class TracedOnSubscribe<T> implements Observable.OnSubscribe<T> {

private final Observable.OnSubscribe<?> delegate;
private final CharSequence operationName;
private final AgentScope.Continuation continuation;
private final AgentSpan parent;
private final BaseDecorator decorator;

public TracedOnSubscribe(
Expand All @@ -25,25 +25,15 @@ public TracedOnSubscribe(
delegate = DDTracingUtil.extractOnSubscribe(originalObservable);
this.operationName = operationName;
this.decorator = decorator;

continuation = capture();
this.parent = activeSpan();
}

@Override
public void call(final Subscriber<? super T> subscriber) {
final AgentSpan span; // span finished by TracedSubscriber
if (continuation != null) {
try (final AgentScope scope = continuation.activate()) {
span = startSpan(operationName);
}
} else {
span = startSpan(operationName);
}

final AgentSpan span = startSpan(operationName, parent != null ? parent.context() : null);
afterStart(span);

try (final AgentScope scope = activateSpan(span)) {
scope.setAsyncPropagation(true);
try (final AgentScope scope = activateSpan(span, true)) {
delegate.call(new TracedSubscriber(span, subscriber, decorator));
}
}
Expand Down