-
Notifications
You must be signed in to change notification settings - Fork 886
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Okhttp3: fix concurrency test with callback (#3669)
- Loading branch information
Showing
5 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...opentelemetry/javaagent/instrumentation/okhttp/v3_0/OkHttp3DispatcherInstrumentation.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,54 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.okhttp.v3_0; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore; | ||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext; | ||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; | ||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.ExecutorInstrumentationUtils; | ||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.State; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class OkHttp3DispatcherInstrumentation implements TypeInstrumentation { | ||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("okhttp3.Dispatcher"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
named("enqueue").and(takesArgument(0, named("okhttp3.RealCall$AsyncCall"))), | ||
OkHttp3DispatcherInstrumentation.class.getName() + "$AttachStateAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class AttachStateAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static State onEnter(@Advice.Argument(0) Runnable call) { | ||
if (ExecutorInstrumentationUtils.shouldAttachStateToTask(call)) { | ||
ContextStore<Runnable, State> contextStore = | ||
InstrumentationContext.get(Runnable.class, State.class); | ||
return ExecutorInstrumentationUtils.setupState( | ||
contextStore, call, Java8BytecodeBridge.currentContext()); | ||
} | ||
return null; | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void onExit(@Advice.Enter State state, @Advice.Thrown Throwable throwable) { | ||
ExecutorInstrumentationUtils.cleanUpOnMethodExit(state, throwable); | ||
} | ||
} | ||
} |
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
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