Skip to content
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

Add ObservationAwareSpanThreadLocalAccessor constructor taking ObservationRegistry #240

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ObservationAwareSpanThreadLocalAccessorTests {
void setup() {
observationRegistry.observationConfig().observationHandler(new DefaultTracingObservationHandler(tracer));
contextRegistry.loadThreadLocalAccessors()
.registerThreadLocalAccessor(new ObservationAwareSpanThreadLocalAccessor(tracer));
.registerThreadLocalAccessor(new ObservationAwareSpanThreadLocalAccessor(observationRegistry, tracer));
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import io.micrometer.tracing.Tracer;
import io.micrometer.tracing.handler.TracingObservationHandler;

import java.util.Objects;

/**
* A {@link ThreadLocalAccessor} to put and restore current {@link Span} depending on
* whether {@link ObservationThreadLocalAccessor} did some work or not (if
Expand All @@ -44,6 +46,7 @@
* call {@link ContextRegistry#registerThreadLocalAccessor(ThreadLocalAccessor)} manually.
*
* @author Marcin Grzejszczak
* @author Taeik Lim
* @since 1.0.4
*/
public class ObservationAwareSpanThreadLocalAccessor implements ThreadLocalAccessor<Span> {
Expand All @@ -53,16 +56,26 @@ public class ObservationAwareSpanThreadLocalAccessor implements ThreadLocalAcces
*/
public static final String KEY = "micrometer.tracing";

private final Tracer tracer;
private final ObservationRegistry registry;

private static final ObservationRegistry registry = ObservationRegistry.create();
private final Tracer tracer;

/**
* Creates a new instance of {@link ObservationThreadLocalAccessor}.
* @param tracer tracer
*/
public ObservationAwareSpanThreadLocalAccessor(Tracer tracer) {
this.tracer = tracer;
this(ObservationRegistry.create(), tracer);
}

/**
* Creates a new instance of {@link ObservationThreadLocalAccessor}.
* @param observationRegistry observationRegistry
* @param tracer tracer
*/
public ObservationAwareSpanThreadLocalAccessor(ObservationRegistry observationRegistry, Tracer tracer) {
this.registry = Objects.requireNonNull(observationRegistry, "observationRegistry must not be null");
this.tracer = Objects.requireNonNull(tracer, "tracer must not be null");
}

@Override
Expand Down