Skip to content

Commit

Permalink
Instrumentation cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcculls committed Nov 12, 2020
1 parent 3909638 commit 099a571
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,38 @@ public Map<String, String> contextStore() {

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
transformers.put(
isConstructor(), packageName + ".CompletableInstrumentation$CompletableAdvice");
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
transformers.put(isConstructor(), getClass().getName() + "$CaptureParentSpanAdvice");
transformers.put(
isMethod()
.and(named("subscribe"))
.and(takesArguments(1))
.and(takesArgument(0, named("io.reactivex.CompletableObserver"))),
packageName + ".CompletableInstrumentation$SubscribeAdvice");
getClass().getName() + "$PropagateParentSpanAdvice");
return transformers;
}

public static class CompletableAdvice {
public static class CaptureParentSpanAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void onConstruct(@Advice.This final Completable thiz) {
AgentSpan span = activeSpan();
if (span != null) {
InstrumentationContext.get(Completable.class, AgentSpan.class).put(thiz, span);
public static void onConstruct(@Advice.This final Completable completable) {
AgentSpan parentSpan = activeSpan();
if (parentSpan != null) {
InstrumentationContext.get(Completable.class, AgentSpan.class).put(completable, parentSpan);
}
}
}

public static class SubscribeAdvice {
public static class PropagateParentSpanAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope openScope(
@Advice.This final Completable thiz,
public static AgentScope onSubscribe(
@Advice.This final Completable completable,
@Advice.Argument(value = 0, readOnly = false) CompletableObserver observer) {
if (observer != null) {
AgentSpan span = InstrumentationContext.get(Completable.class, AgentSpan.class).get(thiz);
if (span != null) {
observer = new TracingCompletableObserver(observer, span);
return activateSpan(span);
AgentSpan parentSpan =
InstrumentationContext.get(Completable.class, AgentSpan.class).get(completable);
if (parentSpan != null) {
observer = new TracingCompletableObserver(observer, parentSpan);
return activateSpan(parentSpan);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,38 @@ public Map<String, String> contextStore() {

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
transformers.put(isConstructor(), packageName + ".FlowableInstrumentation$FlowableAdvice");
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
transformers.put(isConstructor(), getClass().getName() + "$CaptureParentSpanAdvice");
transformers.put(
isMethod()
.and(named("subscribe"))
.and(takesArguments(1))
.and(takesArgument(0, named("org.reactivestreams.Subscriber"))),
packageName + ".FlowableInstrumentation$SubscribeAdvice");
getClass().getName() + "$PropagateParentSpanAdvice");
return transformers;
}

public static class FlowableAdvice {
public static class CaptureParentSpanAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void onConstruct(@Advice.This final Flowable<?> thiz) {
AgentSpan span = activeSpan();
if (span != null) {
InstrumentationContext.get(Flowable.class, AgentSpan.class).put(thiz, span);
public static void onConstruct(@Advice.This final Flowable<?> flowable) {
AgentSpan parentSpan = activeSpan();
if (parentSpan != null) {
InstrumentationContext.get(Flowable.class, AgentSpan.class).put(flowable, parentSpan);
}
}
}

public static class SubscribeAdvice {
public static class PropagateParentSpanAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope openScope(
@Advice.This final Flowable<?> thiz,
@Advice.Argument(value = 0, readOnly = false) Subscriber<?> observer) {
if (observer != null) {
AgentSpan span = InstrumentationContext.get(Flowable.class, AgentSpan.class).get(thiz);
if (span != null) {
observer = new TracingSubscriber<>(observer, span);
return activateSpan(span);
public static AgentScope onSubscribe(
@Advice.This final Flowable<?> flowable,
@Advice.Argument(value = 0, readOnly = false) Subscriber<?> subscriber) {
if (subscriber != null) {
AgentSpan parentSpan =
InstrumentationContext.get(Flowable.class, AgentSpan.class).get(flowable);
if (parentSpan != null) {
subscriber = new TracingSubscriber<>(subscriber, parentSpan);
return activateSpan(parentSpan);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,37 @@ public Map<String, String> contextStore() {

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
transformers.put(isConstructor(), packageName + ".MaybeInstrumentation$MaybeAdvice");
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
transformers.put(isConstructor(), getClass().getName() + "$CaptureParentSpanAdvice");
transformers.put(
isMethod()
.and(named("subscribe"))
.and(takesArguments(1))
.and(takesArgument(0, named("io.reactivex.MaybeObserver"))),
packageName + ".MaybeInstrumentation$SubscribeAdvice");
getClass().getName() + "$PropagateParentSpanAdvice");
return transformers;
}

public static class MaybeAdvice {
public static class CaptureParentSpanAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void onConstruct(@Advice.This final Maybe<?> thiz) {
AgentSpan span = activeSpan();
if (span != null) {
InstrumentationContext.get(Maybe.class, AgentSpan.class).put(thiz, span);
public static void onConstruct(@Advice.This final Maybe<?> maybe) {
AgentSpan parentSpan = activeSpan();
if (parentSpan != null) {
InstrumentationContext.get(Maybe.class, AgentSpan.class).put(maybe, parentSpan);
}
}
}

public static class SubscribeAdvice {
public static class PropagateParentSpanAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope openScope(
@Advice.This final Maybe<?> thiz,
public static AgentScope onSubscribe(
@Advice.This final Maybe<?> maybe,
@Advice.Argument(value = 0, readOnly = false) MaybeObserver<?> observer) {
if (observer != null) {
AgentSpan span = InstrumentationContext.get(Maybe.class, AgentSpan.class).get(thiz);
if (span != null) {
observer = new TracingMaybeObserver<>(observer, span);
return activateSpan(span);
AgentSpan parentSpan = InstrumentationContext.get(Maybe.class, AgentSpan.class).get(maybe);
if (parentSpan != null) {
observer = new TracingMaybeObserver<>(observer, parentSpan);
return activateSpan(parentSpan);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,38 @@ public Map<String, String> contextStore() {

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
transformers.put(isConstructor(), packageName + ".ObservableInstrumentation$ObservableAdvice");
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
transformers.put(isConstructor(), getClass().getName() + "$CaptureParentSpanAdvice");
transformers.put(
isMethod()
.and(named("subscribe"))
.and(takesArguments(1))
.and(takesArgument(0, named("io.reactivex.Observer"))),
packageName + ".ObservableInstrumentation$SubscribeAdvice");
getClass().getName() + "$PropagateParentSpanAdvice");
return transformers;
}

public static class ObservableAdvice {
public static class CaptureParentSpanAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void onConstruct(@Advice.This final Observable<?> thiz) {
AgentSpan span = activeSpan();
if (span != null) {
InstrumentationContext.get(Observable.class, AgentSpan.class).put(thiz, span);
public static void onConstruct(@Advice.This final Observable<?> observable) {
AgentSpan parentSpan = activeSpan();
if (parentSpan != null) {
InstrumentationContext.get(Observable.class, AgentSpan.class).put(observable, parentSpan);
}
}
}

public static class SubscribeAdvice {
public static class PropagateParentSpanAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope openScope(
@Advice.This final Observable<?> thiz,
public static AgentScope onSubscribe(
@Advice.This final Observable<?> observable,
@Advice.Argument(value = 0, readOnly = false) Observer<?> observer) {
if (observer != null) {
AgentSpan span = InstrumentationContext.get(Observable.class, AgentSpan.class).get(thiz);
if (span != null) {
observer = new TracingObserver<>(observer, span);
return activateSpan(span);
AgentSpan parentSpan =
InstrumentationContext.get(Observable.class, AgentSpan.class).get(observable);
if (parentSpan != null) {
observer = new TracingObserver<>(observer, parentSpan);
return activateSpan(parentSpan);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,38 @@ public Map<String, String> contextStore() {

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
transformers.put(isConstructor(), packageName + ".SingleInstrumentation$SingleAdvice");
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
transformers.put(isConstructor(), getClass().getName() + "$CaptureParentSpanAdvice");
transformers.put(
isMethod()
.and(named("subscribe"))
.and(takesArguments(1))
.and(takesArgument(0, named("io.reactivex.SingleObserver"))),
packageName + ".SingleInstrumentation$SubscribeAdvice");
getClass().getName() + "$PropagateParentSpanAdvice");
return transformers;
}

public static class SingleAdvice {
public static class CaptureParentSpanAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void onConstruct(@Advice.This final Single<?> thiz) {
AgentSpan span = activeSpan();
if (span != null) {
InstrumentationContext.get(Single.class, AgentSpan.class).put(thiz, span);
public static void onConstruct(@Advice.This final Single<?> single) {
AgentSpan parentSpan = activeSpan();
if (parentSpan != null) {
InstrumentationContext.get(Single.class, AgentSpan.class).put(single, parentSpan);
}
}
}

public static class SubscribeAdvice {
public static class PropagateParentSpanAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope openScope(
@Advice.This final Single<?> thiz,
public static AgentScope onSubscribe(
@Advice.This final Single<?> single,
@Advice.Argument(value = 0, readOnly = false) SingleObserver<?> observer) {
if (observer != null) {
AgentSpan span = InstrumentationContext.get(Single.class, AgentSpan.class).get(thiz);
if (span != null) {
observer = new TracingSingleObserver<>(observer, span);
return activateSpan(span);
AgentSpan parentSpan =
InstrumentationContext.get(Single.class, AgentSpan.class).get(single);
if (parentSpan != null) {
observer = new TracingSingleObserver<>(observer, parentSpan);
return activateSpan(parentSpan);
}
}
return null;
Expand Down

0 comments on commit 099a571

Please sign in to comment.