-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...entelemetry/javaagent/instrumentation/ratpack/ExecutionBoundPublisherInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.ratpack; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.reactivestreams.Subscriber; | ||
|
||
public class ExecutionBoundPublisherInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return namedOneOf( | ||
"ratpack.exec.internal.ExecutionBoundPublisher", | ||
"ratpack.exec.internal.DefaultExecution$ExecutionBoundPublisher"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
named("subscribe").and(takesArgument(0, named("org.reactivestreams.Subscriber"))), | ||
this.getClass().getName() + "$SubscribeAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class SubscribeAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static <T> void wrap( | ||
@Advice.Argument(value = 0, readOnly = false) Subscriber<T> subscriber) { | ||
subscriber = new TracingSubscriber<>(subscriber, Java8BytecodeBridge.currentContext()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...t/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/TracingSubscriber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.ratpack; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.Subscription; | ||
|
||
public final class TracingSubscriber<T> implements Subscriber<T> { | ||
private final Subscriber<T> delegate; | ||
private final Context context; | ||
|
||
public TracingSubscriber(Subscriber<T> delegate, Context context) { | ||
this.delegate = delegate; | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public void onSubscribe(Subscription subscription) { | ||
try (Scope ignore = context.makeCurrent()) { | ||
delegate.onSubscribe(subscription); | ||
} | ||
} | ||
|
||
@Override | ||
public void onNext(T t) { | ||
try (Scope ignore = context.makeCurrent()) { | ||
delegate.onNext(t); | ||
} | ||
} | ||
|
||
@Override | ||
public void onError(Throwable throwable) { | ||
try (Scope ignore = context.makeCurrent()) { | ||
delegate.onError(throwable); | ||
} | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
try (Scope ignore = context.makeCurrent()) { | ||
delegate.onComplete(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters