Make it possible to use InstrumentationContext (now VirtualField) fro… (#4218)
* Make it possible to use InstrumentationContext (now VirtualField) from library instrumentation * fix tests * fix javadocs * fix some more tests * code review comments * setIfNull, computeIfNull
This commit is contained in:
parent
d55eee2ebf
commit
c11b96e4d0
|
@ -31,7 +31,8 @@ class MyLibraryInstrumentationModule extends InstrumentationModule {
|
|||
An `InstrumentationModule` needs to have at least one name. The user of the javaagent can
|
||||
[suppress a chosen instrumentation](../suppressing-instrumentation.md) by referring to it by one of
|
||||
its names. The instrumentation module names use kebab-case. The main instrumentation name (the first
|
||||
one) is supposed to be the same as the gradle module name (excluding the version suffix if it has one).
|
||||
one) is supposed to be the same as the gradle module name (excluding the version suffix if it has
|
||||
one).
|
||||
|
||||
```java
|
||||
public MyLibraryInstrumentationModule() {
|
||||
|
@ -104,8 +105,8 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
|
|||
}
|
||||
```
|
||||
|
||||
The above example will skip instrumenting the application code if it does not contain the class that was
|
||||
introduced in the version your instrumentation covers.
|
||||
The above example will skip instrumenting the application code if it does not contain the class that
|
||||
was introduced in the version your instrumentation covers.
|
||||
|
||||
### `typeInstrumentations()`
|
||||
|
||||
|
@ -174,8 +175,8 @@ of available transformations that you can apply:
|
|||
|
||||
* Calling `applyAdviceToMethod(ElementMatcher<? super MethodDescription>, String)` allows you to
|
||||
apply an advice class (the second parameter) to all matching methods (the first parameter). It is
|
||||
suggested to make the method matchers as strict as possible - the type instrumentation should
|
||||
only instrument the code that it's supposed to, not more.
|
||||
suggested to make the method matchers as strict as possible - the type instrumentation should only
|
||||
instrument the code that it's supposed to, not more.
|
||||
* `applyTransformer(AgentBuilder.Transformer)` allows you to inject an arbitrary ByteBuddy
|
||||
transformer. This is an advanced, low-level option that will not be subjected to muzzle safety
|
||||
checks and helper class detection - use it responsibly.
|
||||
|
@ -250,9 +251,9 @@ Exceptions thrown by the advice methods will get caught and handled by a special
|
|||
that OpenTelemetry javaagent defines. The handler makes sure to properly log all unexpected
|
||||
exceptions.
|
||||
|
||||
The `OnMethodEnter` and `OnMethodExit` advice methods often need to share several pieces
|
||||
of information. We use local variables prefixed with `otel` to pass context, scope (and sometimes
|
||||
more) between those methods.
|
||||
The `OnMethodEnter` and `OnMethodExit` advice methods often need to share several pieces of
|
||||
information. We use local variables prefixed with `otel` to pass context, scope (and sometimes more)
|
||||
between those methods.
|
||||
|
||||
```java
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
|
@ -305,18 +306,17 @@ for accessing these default methods from advice.
|
|||
In fact, we suggest avoiding Java 8 language features in advice classes at all - sometimes you don't
|
||||
know what bytecode version is used by the instrumented class.
|
||||
|
||||
Sometimes there is a need to associate some context class with an instrumented library class,
|
||||
and the library does not offer a way to do this. The OpenTelemetry javaagent provides the
|
||||
`ContextStore` for that purpose:
|
||||
Sometimes there is a need to associate some context class with an instrumented library class, and
|
||||
the library does not offer a way to do this. The OpenTelemetry javaagent provides the
|
||||
`VirtualField` for that purpose:
|
||||
|
||||
```java
|
||||
ContextStore<Runnable, Context> contextStore =
|
||||
InstrumentationContext.get(Runnable.class, Context.class);
|
||||
VirtualField<Runnable, Context> virtualField =
|
||||
VirtualField.get(Runnable.class, Context.class);
|
||||
```
|
||||
|
||||
A `ContextStore` is conceptually very similar to a map. It is not a simple map though:
|
||||
the javaagent uses a lot of bytecode modification magic to make this optimal.
|
||||
Because of this, retrieving a `ContextStore` instance is rather limited:
|
||||
the `InstrumentationContext#get()` method can only be called in advice classes, and it MUST receive
|
||||
class references as its parameters - it won't work with variables, method params etc.
|
||||
A `VirtualField` is conceptually very similar to a map. It is not a simple map though:
|
||||
the javaagent uses a lot of bytecode modification magic to make this optimal. Because of this,
|
||||
retrieving a `VirtualField` instance is rather limited: the `VirtualField#get()`
|
||||
MUST receive class references as its parameters - it won't work with variables, method params etc.
|
||||
Both the key class and the context class must be known at compile time for it to work.
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.field;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.internal.RuntimeVirtualFieldSupplier;
|
||||
import java.util.function.Supplier;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a "virtual" field of type {@code F} that is added to type {@code T} in the runtime.
|
||||
*
|
||||
* <p>A virtual field has similar semantics to a weak-keys strong-values map: the value will be
|
||||
* garbage collected when their owner instance is collected. It is discouraged to use a virtual
|
||||
* field for keeping values that might reference their key, as it may cause memory leaks.
|
||||
*
|
||||
* @param <T> The type that will contain the new virtual field.
|
||||
* @param <F> The field type that'll be added to {@code T}.
|
||||
*/
|
||||
// we're using an abstract class here so that we can call static find() in pre-jdk8 advice classes
|
||||
public abstract class VirtualField<T, F> {
|
||||
|
||||
/**
|
||||
* Finds a {@link VirtualField} instance for given {@code type} and {@code fieldType}.
|
||||
*
|
||||
* <p>Conceptually this can be thought of as a map lookup to fetch a second level map given {@code
|
||||
* type}.
|
||||
*
|
||||
* <p>In runtime, when using the javaagent, the <em>calls</em> to this method are rewritten to
|
||||
* something more performant while injecting advice into a method.
|
||||
*
|
||||
* <p>When using this method outside of Advice method, the {@link VirtualField} should be looked
|
||||
* up once and stored in a field to avoid repeatedly calling this method.
|
||||
*
|
||||
* @param type The type that will contain the new virtual field.
|
||||
* @param fieldType The field type that'll be added to {@code type}.
|
||||
*/
|
||||
public static <U extends T, T, F> VirtualField<U, F> find(Class<T> type, Class<F> fieldType) {
|
||||
return RuntimeVirtualFieldSupplier.get().find(type, fieldType);
|
||||
}
|
||||
|
||||
/** Gets the value of this virtual field. */
|
||||
@Nullable
|
||||
public abstract F get(T object);
|
||||
|
||||
/** Sets the new value of this virtual field. */
|
||||
public abstract void set(T object, @Nullable F fieldValue);
|
||||
|
||||
/** Sets the new value of this virtual field if the current value is {@code null}. */
|
||||
public abstract void setIfNull(T object, F fieldValue);
|
||||
|
||||
/**
|
||||
* Sets the new value of this virtual field if the current value is {@code null}.
|
||||
*
|
||||
* @return The old field value if it was present, or the result of evaluating passed {@code
|
||||
* fieldValueSupplier}.
|
||||
*/
|
||||
public abstract F computeIfNull(T object, Supplier<F> fieldValueSupplier);
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.internal;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.caching.Cache;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class RuntimeVirtualFieldSupplier {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RuntimeVirtualFieldSupplier.class);
|
||||
|
||||
public interface VirtualFieldSupplier {
|
||||
<U extends T, T, F> VirtualField<U, F> find(Class<T> type, Class<F> fieldType);
|
||||
}
|
||||
|
||||
private static final VirtualFieldSupplier DEFAULT = new CacheBasedVirtualFieldSupplier();
|
||||
|
||||
private static volatile VirtualFieldSupplier instance = DEFAULT;
|
||||
|
||||
public static void set(VirtualFieldSupplier virtualFieldSupplier) {
|
||||
// only overwrite the default, cache-based supplier
|
||||
if (instance != DEFAULT) {
|
||||
logger.warn(
|
||||
"Runtime VirtualField supplier has already been set up, further set() calls are ignored");
|
||||
return;
|
||||
}
|
||||
instance = virtualFieldSupplier;
|
||||
}
|
||||
|
||||
public static VirtualFieldSupplier get() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static final class CacheBasedVirtualFieldSupplier
|
||||
extends ClassValue<Map<Class<?>, VirtualField<?, ?>>> implements VirtualFieldSupplier {
|
||||
|
||||
@Override
|
||||
public <U extends T, T, F> VirtualField<U, F> find(Class<T> type, Class<F> fieldType) {
|
||||
return (VirtualField<U, F>)
|
||||
get(type).computeIfAbsent(fieldType, k -> new CacheBasedVirtualField<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<Class<?>, VirtualField<?, ?>> computeValue(Class<?> type) {
|
||||
return new ConcurrentHashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class CacheBasedVirtualField<T, F> extends VirtualField<T, F> {
|
||||
private final Cache<T, F> cache = Cache.newBuilder().setWeakKeys().build();
|
||||
|
||||
@Override
|
||||
public @Nullable F get(T object) {
|
||||
return cache.get(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(T object, @Nullable F fieldValue) {
|
||||
if (fieldValue == null) {
|
||||
cache.remove(object);
|
||||
} else {
|
||||
cache.put(object, fieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIfNull(T object, F fieldValue) {
|
||||
cache.computeIfAbsent(object, k -> fieldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public F computeIfNull(T object, Supplier<F> fieldValueSupplier) {
|
||||
return cache.computeIfAbsent(object, k -> fieldValueSupplier.get());
|
||||
}
|
||||
}
|
||||
|
||||
private RuntimeVirtualFieldSupplier() {}
|
||||
}
|
|
@ -142,9 +142,8 @@ public final class MappingResolver {
|
|||
|
||||
/**
|
||||
* Factory interface for creating {@link MappingResolver} instances. The main reason this class is
|
||||
* here is that we need to ensure that the class used for {@code InstrumentationContext} lookup is
|
||||
* always the same. If we would use an injected class it could be different in different class
|
||||
* loaders.
|
||||
* here is that we need to ensure that the class used for {@code VirtualField} lookup is always
|
||||
* the same. If we would use an injected class it could be different in different class loaders.
|
||||
*/
|
||||
public interface Factory {
|
||||
|
||||
|
|
|
@ -11,10 +11,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import akka.dispatch.Envelope;
|
||||
import akka.dispatch.sysmsg.SystemMessage;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.concurrent.PropagatedContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.TaskAdviceHelper;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -43,9 +42,9 @@ public class AkkaActorCellInstrumentation implements TypeInstrumentation {
|
|||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static Scope enter(@Advice.Argument(0) Envelope envelope) {
|
||||
ContextStore<Envelope, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Envelope.class, PropagatedContext.class);
|
||||
return TaskAdviceHelper.makePropagatedContextCurrent(contextStore, envelope);
|
||||
VirtualField<Envelope, PropagatedContext> virtualField =
|
||||
VirtualField.find(Envelope.class, PropagatedContext.class);
|
||||
return TaskAdviceHelper.makePropagatedContextCurrent(virtualField, envelope);
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
|
@ -61,9 +60,9 @@ public class AkkaActorCellInstrumentation implements TypeInstrumentation {
|
|||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static Scope enter(@Advice.Argument(0) SystemMessage systemMessage) {
|
||||
ContextStore<SystemMessage, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(SystemMessage.class, PropagatedContext.class);
|
||||
return TaskAdviceHelper.makePropagatedContextCurrent(contextStore, systemMessage);
|
||||
VirtualField<SystemMessage, PropagatedContext> virtualField =
|
||||
VirtualField.find(SystemMessage.class, PropagatedContext.class);
|
||||
return TaskAdviceHelper.makePropagatedContextCurrent(virtualField, systemMessage);
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
|
|
|
@ -12,10 +12,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import akka.dispatch.sysmsg.SystemMessage;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.ExecutorAdviceHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.PropagatedContext;
|
||||
|
@ -50,9 +49,9 @@ public class AkkaDefaultSystemMessageQueueInstrumentation implements TypeInstrum
|
|||
public static PropagatedContext enter(@Advice.Argument(1) SystemMessage systemMessage) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, systemMessage)) {
|
||||
ContextStore<SystemMessage, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(SystemMessage.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, systemMessage);
|
||||
VirtualField<SystemMessage, PropagatedContext> virtualField =
|
||||
VirtualField.find(SystemMessage.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, systemMessage);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -10,10 +10,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import akka.dispatch.Envelope;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.ExecutorAdviceHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.PropagatedContext;
|
||||
|
@ -44,9 +43,9 @@ public class AkkaDispatcherInstrumentation implements TypeInstrumentation {
|
|||
public static PropagatedContext enterDispatch(@Advice.Argument(1) Envelope envelope) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, envelope)) {
|
||||
ContextStore<Envelope, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Envelope.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, envelope);
|
||||
VirtualField<Envelope, PropagatedContext> virtualField =
|
||||
VirtualField.find(Envelope.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, envelope);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import akka.dispatch.forkjoin.ForkJoinTask;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.ExecutorAdviceHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.PropagatedContext;
|
||||
|
@ -54,9 +53,9 @@ public class AkkaForkJoinPoolInstrumentation implements TypeInstrumentation {
|
|||
@Advice.Argument(value = 0, readOnly = false) ForkJoinTask<?> task) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
|
||||
ContextStore<ForkJoinTask<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(ForkJoinTask.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, task);
|
||||
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -15,10 +15,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
import akka.dispatch.forkjoin.ForkJoinPool;
|
||||
import akka.dispatch.forkjoin.ForkJoinTask;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.concurrent.PropagatedContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.TaskAdviceHelper;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -63,14 +62,14 @@ public class AkkaForkJoinTaskInstrumentation implements TypeInstrumentation {
|
|||
*/
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static Scope enter(@Advice.This ForkJoinTask<?> thiz) {
|
||||
ContextStore<ForkJoinTask<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(ForkJoinTask.class, PropagatedContext.class);
|
||||
Scope scope = TaskAdviceHelper.makePropagatedContextCurrent(contextStore, thiz);
|
||||
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
|
||||
Scope scope = TaskAdviceHelper.makePropagatedContextCurrent(virtualField, thiz);
|
||||
if (thiz instanceof Runnable) {
|
||||
ContextStore<Runnable, PropagatedContext> runnableContextStore =
|
||||
InstrumentationContext.get(Runnable.class, PropagatedContext.class);
|
||||
VirtualField<Runnable, PropagatedContext> runnableVirtualField =
|
||||
VirtualField.find(Runnable.class, PropagatedContext.class);
|
||||
Scope newScope =
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(runnableContextStore, (Runnable) thiz);
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(runnableVirtualField, (Runnable) thiz);
|
||||
if (null != newScope) {
|
||||
if (null != scope) {
|
||||
newScope.close();
|
||||
|
@ -80,10 +79,10 @@ public class AkkaForkJoinTaskInstrumentation implements TypeInstrumentation {
|
|||
}
|
||||
}
|
||||
if (thiz instanceof Callable) {
|
||||
ContextStore<Callable<?>, PropagatedContext> callableContextStore =
|
||||
InstrumentationContext.get(Callable.class, PropagatedContext.class);
|
||||
VirtualField<Callable<?>, PropagatedContext> callableVirtualField =
|
||||
VirtualField.find(Callable.class, PropagatedContext.class);
|
||||
Scope newScope =
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(callableContextStore, (Callable<?>) thiz);
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(callableVirtualField, (Callable<?>) thiz);
|
||||
if (null != newScope) {
|
||||
if (null != scope) {
|
||||
newScope.close();
|
||||
|
|
|
@ -15,9 +15,9 @@ import com.ning.http.client.AsyncHandler;
|
|||
import com.ning.http.client.Request;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -53,8 +53,8 @@ public class RequestInstrumentation implements TypeInstrumentation {
|
|||
}
|
||||
|
||||
Context context = instrumenter().start(parentContext, request);
|
||||
InstrumentationContext.get(AsyncHandler.class, AsyncHandlerData.class)
|
||||
.put(handler, AsyncHandlerData.create(parentContext, context, request));
|
||||
VirtualField.find(AsyncHandler.class, AsyncHandlerData.class)
|
||||
.set(handler, AsyncHandlerData.create(parentContext, context, request));
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,10 +16,9 @@ import com.ning.http.client.AsyncCompletionHandler;
|
|||
import com.ning.http.client.AsyncHandler;
|
||||
import com.ning.http.client.Response;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -55,13 +54,13 @@ public class ResponseInstrumentation implements TypeInstrumentation {
|
|||
public static Scope onEnter(
|
||||
@Advice.This AsyncCompletionHandler<?> handler, @Advice.Argument(0) Response response) {
|
||||
|
||||
ContextStore<AsyncHandler<?>, AsyncHandlerData> contextStore =
|
||||
InstrumentationContext.get(AsyncHandler.class, AsyncHandlerData.class);
|
||||
AsyncHandlerData data = contextStore.get(handler);
|
||||
VirtualField<AsyncHandler<?>, AsyncHandlerData> virtualField =
|
||||
VirtualField.find(AsyncHandler.class, AsyncHandlerData.class);
|
||||
AsyncHandlerData data = virtualField.get(handler);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
contextStore.put(handler, null);
|
||||
virtualField.set(handler, null);
|
||||
instrumenter().end(data.getContext(), data.getRequest(), response, null);
|
||||
return data.getParentContext().makeCurrent();
|
||||
}
|
||||
|
@ -81,13 +80,13 @@ public class ResponseInstrumentation implements TypeInstrumentation {
|
|||
public static Scope onEnter(
|
||||
@Advice.This AsyncCompletionHandler<?> handler, @Advice.Argument(0) Throwable throwable) {
|
||||
|
||||
ContextStore<AsyncHandler<?>, AsyncHandlerData> contextStore =
|
||||
InstrumentationContext.get(AsyncHandler.class, AsyncHandlerData.class);
|
||||
AsyncHandlerData data = contextStore.get(handler);
|
||||
VirtualField<AsyncHandler<?>, AsyncHandlerData> virtualField =
|
||||
VirtualField.find(AsyncHandler.class, AsyncHandlerData.class);
|
||||
AsyncHandlerData data = virtualField.get(handler);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
contextStore.put(handler, null);
|
||||
virtualField.set(handler, null);
|
||||
instrumenter().end(data.getContext(), data.getRequest(), null, throwable);
|
||||
return data.getParentContext().makeCurrent();
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -55,13 +54,13 @@ public class AsyncCompletionHandlerInstrumentation implements TypeInstrumentatio
|
|||
public static Scope onEnter(
|
||||
@Advice.This AsyncCompletionHandler<?> handler, @Advice.Argument(0) Response response) {
|
||||
|
||||
ContextStore<AsyncHandler<?>, RequestContext> contextStore =
|
||||
InstrumentationContext.get(AsyncHandler.class, RequestContext.class);
|
||||
RequestContext requestContext = contextStore.get(handler);
|
||||
VirtualField<AsyncHandler<?>, RequestContext> virtualField =
|
||||
VirtualField.find(AsyncHandler.class, RequestContext.class);
|
||||
RequestContext requestContext = virtualField.get(handler);
|
||||
if (requestContext == null) {
|
||||
return null;
|
||||
}
|
||||
contextStore.put(handler, null);
|
||||
virtualField.set(handler, null);
|
||||
instrumenter().end(requestContext.getContext(), requestContext, response, null);
|
||||
return requestContext.getParentContext().makeCurrent();
|
||||
}
|
||||
|
@ -81,13 +80,13 @@ public class AsyncCompletionHandlerInstrumentation implements TypeInstrumentatio
|
|||
public static Scope onEnter(
|
||||
@Advice.This AsyncCompletionHandler<?> handler, @Advice.Argument(0) Throwable throwable) {
|
||||
|
||||
ContextStore<AsyncHandler<?>, RequestContext> contextStore =
|
||||
InstrumentationContext.get(AsyncHandler.class, RequestContext.class);
|
||||
RequestContext requestContext = contextStore.get(handler);
|
||||
VirtualField<AsyncHandler<?>, RequestContext> virtualField =
|
||||
VirtualField.find(AsyncHandler.class, RequestContext.class);
|
||||
RequestContext requestContext = virtualField.get(handler);
|
||||
if (requestContext == null) {
|
||||
return null;
|
||||
}
|
||||
contextStore.put(handler, null);
|
||||
virtualField.set(handler, null);
|
||||
instrumenter().end(requestContext.getContext(), requestContext, null, throwable);
|
||||
return requestContext.getParentContext().makeCurrent();
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -57,7 +57,7 @@ public class AsyncHttpClientInstrumentation implements TypeInstrumentation {
|
|||
Context context = instrumenter().start(parentContext, requestContext);
|
||||
requestContext.setContext(context);
|
||||
|
||||
// TODO (trask) instead of using InstrumentationContext, wrap the AsyncHandler in an
|
||||
// TODO (trask) instead of using VirtualField, wrap the AsyncHandler in an
|
||||
// instrumented AsyncHandler which delegates to the original AsyncHandler
|
||||
// (similar to other http client instrumentations, and needed for library instrumentation)
|
||||
//
|
||||
|
@ -70,8 +70,7 @@ public class AsyncHttpClientInstrumentation implements TypeInstrumentation {
|
|||
// 2.1, so the instrumentation module will need to be essentially duplicated (or a common
|
||||
// module introduced)
|
||||
|
||||
InstrumentationContext.get(AsyncHandler.class, RequestContext.class)
|
||||
.put(handler, requestContext);
|
||||
VirtualField.find(AsyncHandler.class, RequestContext.class).set(handler, requestContext);
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -59,8 +59,8 @@ public class NettyRequestSenderInstrumentation implements TypeInstrumentation {
|
|||
|
||||
@Advice.OnMethodEnter
|
||||
public static void attachContext(@Advice.Argument(0) Request request) {
|
||||
InstrumentationContext.get(Request.class, Context.class)
|
||||
.put(request, Java8BytecodeBridge.currentContext());
|
||||
VirtualField.find(Request.class, Context.class)
|
||||
.set(request, Java8BytecodeBridge.currentContext());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class NettyRequestSenderInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodEnter
|
||||
public static Scope mountContext(@Advice.Argument(0) NettyResponseFuture<?> responseFuture) {
|
||||
Request request = responseFuture.getCurrentRequest();
|
||||
Context context = InstrumentationContext.get(Request.class, Context.class).get(request);
|
||||
Context context = VirtualField.find(Request.class, Context.class).get(request);
|
||||
return context == null ? null : context.makeCurrent();
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ public class NettyRequestSenderInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodExit
|
||||
public static void rememberNettyRequest(@Advice.Return NettyResponseFuture responseFuture) {
|
||||
RequestContext requestContext =
|
||||
InstrumentationContext.get(AsyncHandler.class, RequestContext.class)
|
||||
VirtualField.find(AsyncHandler.class, RequestContext.class)
|
||||
.get(responseFuture.getAsyncHandler());
|
||||
if (requestContext != null) {
|
||||
requestContext.setNettyRequest(responseFuture.getNettyRequest());
|
||||
|
|
|
@ -12,10 +12,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import com.couchbase.client.core.message.CouchbaseRequest;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -49,14 +48,14 @@ public class CouchbaseCoreInstrumentation implements TypeInstrumentation {
|
|||
// The scope from the initial rxJava subscribe is not available to the networking layer
|
||||
// To transfer the span, the span is added to the context store
|
||||
|
||||
ContextStore<CouchbaseRequest, Span> contextStore =
|
||||
InstrumentationContext.get(CouchbaseRequest.class, Span.class);
|
||||
VirtualField<CouchbaseRequest, Span> virtualField =
|
||||
VirtualField.find(CouchbaseRequest.class, Span.class);
|
||||
|
||||
Span span = contextStore.get(request);
|
||||
Span span = virtualField.get(request);
|
||||
|
||||
if (span == null) {
|
||||
span = parentSpan;
|
||||
contextStore.put(request, span);
|
||||
virtualField.set(request, span);
|
||||
if (CouchbaseConfig.CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("couchbase.operation_id", request.operationId());
|
||||
}
|
||||
|
|
|
@ -15,11 +15,10 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import com.couchbase.client.core.message.CouchbaseRequest;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes;
|
||||
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.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -63,10 +62,10 @@ public class CouchbaseNetworkInstrumentation implements TypeInstrumentation {
|
|||
@Advice.FieldValue("remoteSocket") String remoteSocket,
|
||||
@Advice.FieldValue("localSocket") String localSocket,
|
||||
@Advice.Argument(1) CouchbaseRequest request) {
|
||||
ContextStore<CouchbaseRequest, Span> contextStore =
|
||||
InstrumentationContext.get(CouchbaseRequest.class, Span.class);
|
||||
VirtualField<CouchbaseRequest, Span> virtualField =
|
||||
VirtualField.find(CouchbaseRequest.class, Span.class);
|
||||
|
||||
Span span = contextStore.get(request);
|
||||
Span span = virtualField.get(request);
|
||||
if (span != null) {
|
||||
NetPeerAttributes.INSTANCE.setNetPeer(span, remoteHostname, null);
|
||||
|
||||
|
|
|
@ -11,10 +11,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.concurrent.PropagatedContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.TaskAdviceHelper;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -41,9 +40,9 @@ public class CallableInstrumentation implements TypeInstrumentation {
|
|||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static Scope enter(@Advice.This Callable<?> task) {
|
||||
ContextStore<Callable<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Callable.class, PropagatedContext.class);
|
||||
return TaskAdviceHelper.makePropagatedContextCurrent(contextStore, task);
|
||||
VirtualField<Callable<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(Callable.class, PropagatedContext.class);
|
||||
return TaskAdviceHelper.makePropagatedContextCurrent(virtualField, task);
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
|
|
|
@ -9,10 +9,9 @@ import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.concurrent.PropagatedContext;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -102,9 +101,9 @@ public class FutureInstrumentation implements TypeInstrumentation {
|
|||
// Try to clear parent span even if future was not cancelled:
|
||||
// the expectation is that parent span should be cleared after 'cancel'
|
||||
// is called, one way or another
|
||||
ContextStore<Future<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Future.class, PropagatedContext.class);
|
||||
PropagatedContext propagatedContext = contextStore.get(future);
|
||||
VirtualField<Future<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(Future.class, PropagatedContext.class);
|
||||
PropagatedContext propagatedContext = virtualField.get(future);
|
||||
if (propagatedContext != null) {
|
||||
propagatedContext.clear();
|
||||
}
|
||||
|
|
|
@ -11,9 +11,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.ExecutorAdviceHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.PropagatedContext;
|
||||
|
@ -71,9 +70,9 @@ public class JavaExecutorInstrumentation extends AbstractExecutorInstrumentation
|
|||
@Advice.Argument(value = 0, readOnly = false) Runnable task) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
|
||||
ContextStore<Runnable, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, task);
|
||||
VirtualField<Runnable, PropagatedContext> virtualField =
|
||||
VirtualField.find(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -93,9 +92,9 @@ public class JavaExecutorInstrumentation extends AbstractExecutorInstrumentation
|
|||
@Advice.Argument(value = 0, readOnly = false) ForkJoinTask<?> task) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
|
||||
ContextStore<ForkJoinTask<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(ForkJoinTask.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, task);
|
||||
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -115,9 +114,9 @@ public class JavaExecutorInstrumentation extends AbstractExecutorInstrumentation
|
|||
@Advice.Argument(value = 0, readOnly = false) Runnable task) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
|
||||
ContextStore<Runnable, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, task);
|
||||
VirtualField<Runnable, PropagatedContext> virtualField =
|
||||
VirtualField.find(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -128,9 +127,9 @@ public class JavaExecutorInstrumentation extends AbstractExecutorInstrumentation
|
|||
@Advice.Thrown Throwable throwable,
|
||||
@Advice.Return Future<?> future) {
|
||||
if (propagatedContext != null && future != null) {
|
||||
ContextStore<Future<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Future.class, PropagatedContext.class);
|
||||
contextStore.put(future, propagatedContext);
|
||||
VirtualField<Future<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(Future.class, PropagatedContext.class);
|
||||
virtualField.set(future, propagatedContext);
|
||||
}
|
||||
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
|
||||
}
|
||||
|
@ -144,9 +143,9 @@ public class JavaExecutorInstrumentation extends AbstractExecutorInstrumentation
|
|||
@Advice.Argument(value = 0, readOnly = false) Callable<?> task) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
|
||||
ContextStore<Callable<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Callable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, task);
|
||||
VirtualField<Callable<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(Callable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -157,9 +156,9 @@ public class JavaExecutorInstrumentation extends AbstractExecutorInstrumentation
|
|||
@Advice.Thrown Throwable throwable,
|
||||
@Advice.Return Future<?> future) {
|
||||
if (propagatedContext != null && future != null) {
|
||||
ContextStore<Future<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Future.class, PropagatedContext.class);
|
||||
contextStore.put(future, propagatedContext);
|
||||
VirtualField<Future<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(Future.class, PropagatedContext.class);
|
||||
virtualField.set(future, propagatedContext);
|
||||
}
|
||||
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
|
||||
}
|
||||
|
@ -178,9 +177,9 @@ public class JavaExecutorInstrumentation extends AbstractExecutorInstrumentation
|
|||
Context context = Java8BytecodeBridge.currentContext();
|
||||
for (Callable<?> task : tasks) {
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
|
||||
ContextStore<Callable<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Callable.class, PropagatedContext.class);
|
||||
ExecutorAdviceHelper.attachContextToTask(context, contextStore, task);
|
||||
VirtualField<Callable<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(Callable.class, PropagatedContext.class);
|
||||
ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,9 +203,9 @@ public class JavaExecutorInstrumentation extends AbstractExecutorInstrumentation
|
|||
if (throwable != null) {
|
||||
for (Callable<?> task : tasks) {
|
||||
if (task != null) {
|
||||
ContextStore<Callable<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Callable.class, PropagatedContext.class);
|
||||
PropagatedContext propagatedContext = contextStore.get(task);
|
||||
VirtualField<Callable<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(Callable.class, PropagatedContext.class);
|
||||
PropagatedContext propagatedContext = virtualField.get(task);
|
||||
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.ExecutorAdviceHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.PropagatedContext;
|
||||
|
@ -62,14 +61,14 @@ public class JavaForkJoinTaskInstrumentation implements TypeInstrumentation {
|
|||
*/
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static Scope enter(@Advice.This ForkJoinTask<?> task) {
|
||||
ContextStore<ForkJoinTask<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(ForkJoinTask.class, PropagatedContext.class);
|
||||
Scope scope = TaskAdviceHelper.makePropagatedContextCurrent(contextStore, task);
|
||||
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
|
||||
Scope scope = TaskAdviceHelper.makePropagatedContextCurrent(virtualField, task);
|
||||
if (task instanceof Runnable) {
|
||||
ContextStore<Runnable, PropagatedContext> runnableContextStore =
|
||||
InstrumentationContext.get(Runnable.class, PropagatedContext.class);
|
||||
VirtualField<Runnable, PropagatedContext> runnableVirtualField =
|
||||
VirtualField.find(Runnable.class, PropagatedContext.class);
|
||||
Scope newScope =
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(runnableContextStore, (Runnable) task);
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(runnableVirtualField, (Runnable) task);
|
||||
if (null != newScope) {
|
||||
if (null != scope) {
|
||||
newScope.close();
|
||||
|
@ -79,10 +78,10 @@ public class JavaForkJoinTaskInstrumentation implements TypeInstrumentation {
|
|||
}
|
||||
}
|
||||
if (task instanceof Callable) {
|
||||
ContextStore<Callable<?>, PropagatedContext> callableContextStore =
|
||||
InstrumentationContext.get(Callable.class, PropagatedContext.class);
|
||||
VirtualField<Callable<?>, PropagatedContext> callableVirtualField =
|
||||
VirtualField.find(Callable.class, PropagatedContext.class);
|
||||
Scope newScope =
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(callableContextStore, (Callable<?>) task);
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(callableVirtualField, (Callable<?>) task);
|
||||
if (null != newScope) {
|
||||
if (null != scope) {
|
||||
newScope.close();
|
||||
|
@ -109,9 +108,9 @@ public class JavaForkJoinTaskInstrumentation implements TypeInstrumentation {
|
|||
public static PropagatedContext enterFork(@Advice.This ForkJoinTask<?> task) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
|
||||
ContextStore<ForkJoinTask<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(ForkJoinTask.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, task);
|
||||
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.concurrent.PropagatedContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.TaskAdviceHelper;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -40,9 +39,9 @@ public class RunnableInstrumentation implements TypeInstrumentation {
|
|||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static Scope enter(@Advice.This Runnable thiz) {
|
||||
ContextStore<Runnable, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Runnable.class, PropagatedContext.class);
|
||||
return TaskAdviceHelper.makePropagatedContextCurrent(contextStore, thiz);
|
||||
VirtualField<Runnable, PropagatedContext> virtualField =
|
||||
VirtualField.find(Runnable.class, PropagatedContext.class);
|
||||
return TaskAdviceHelper.makePropagatedContextCurrent(virtualField, thiz);
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
|
|
|
@ -17,9 +17,9 @@ import com.google.api.client.http.HttpRequest;
|
|||
import com.google.api.client.http.HttpResponse;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import java.util.concurrent.Executor;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -58,7 +58,7 @@ public class GoogleHttpRequestInstrumentation implements TypeInstrumentation {
|
|||
@Advice.Local("otelContext") Context context,
|
||||
@Advice.Local("otelScope") Scope scope) {
|
||||
|
||||
context = InstrumentationContext.get(HttpRequest.class, Context.class).get(request);
|
||||
context = VirtualField.find(HttpRequest.class, Context.class).get(request);
|
||||
if (context != null) {
|
||||
// span was created by GoogleHttpClientAsyncAdvice instrumentation below
|
||||
// (executeAsync ends up calling execute from a separate thread)
|
||||
|
@ -105,7 +105,7 @@ public class GoogleHttpRequestInstrumentation implements TypeInstrumentation {
|
|||
context = instrumenter().start(parentContext, request);
|
||||
scope = context.makeCurrent();
|
||||
|
||||
InstrumentationContext.get(HttpRequest.class, Context.class).put(request, context);
|
||||
VirtualField.find(HttpRequest.class, Context.class).set(request, context);
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
|
|
|
@ -13,10 +13,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
|
||||
import io.grpc.ClientInterceptor;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 java.util.List;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -48,11 +47,11 @@ public class GrpcClientBuilderBuildInstrumentation implements TypeInstrumentatio
|
|||
public static void addInterceptor(
|
||||
@Advice.This ManagedChannelBuilder<?> builder,
|
||||
@Advice.FieldValue("interceptors") List<ClientInterceptor> interceptors) {
|
||||
ContextStore<ManagedChannelBuilder<?>, Boolean> instrumented =
|
||||
InstrumentationContext.get(ManagedChannelBuilder.class, Boolean.class);
|
||||
VirtualField<ManagedChannelBuilder<?>, Boolean> instrumented =
|
||||
VirtualField.find(ManagedChannelBuilder.class, Boolean.class);
|
||||
if (!Boolean.TRUE.equals(instrumented.get(builder))) {
|
||||
interceptors.add(0, GrpcSingletons.CLIENT_INTERCEPTOR);
|
||||
instrumented.put(builder, true);
|
||||
instrumented.set(builder, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,10 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.grpc.ServerBuilder;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -50,11 +49,11 @@ public class GrpcServerBuilderInstrumentation implements TypeInstrumentation {
|
|||
@Advice.Local("otelCallDepth") CallDepth callDepth) {
|
||||
callDepth = CallDepth.forClass(ServerBuilder.class);
|
||||
if (callDepth.getAndIncrement() == 0) {
|
||||
ContextStore<ServerBuilder<?>, Boolean> instrumented =
|
||||
InstrumentationContext.get(ServerBuilder.class, Boolean.class);
|
||||
VirtualField<ServerBuilder<?>, Boolean> instrumented =
|
||||
VirtualField.find(ServerBuilder.class, Boolean.class);
|
||||
if (!Boolean.TRUE.equals(instrumented.get(serverBuilder))) {
|
||||
serverBuilder.intercept(GrpcSingletons.SERVER_INTERCEPTOR);
|
||||
instrumented.put(serverBuilder, true);
|
||||
instrumented.set(serverBuilder, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,9 @@ import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.ExecutorAdviceHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.PropagatedContext;
|
||||
|
@ -54,9 +53,9 @@ public class GuavaListenableFutureInstrumentation implements TypeInstrumentation
|
|||
@Advice.Argument(value = 0, readOnly = false) Runnable task) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
|
||||
ContextStore<Runnable, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, task);
|
||||
VirtualField<Runnable, PropagatedContext> virtualField =
|
||||
VirtualField.find(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -13,11 +13,10 @@ import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -60,8 +59,8 @@ public class CriteriaInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<Criteria, Context> contextStore =
|
||||
InstrumentationContext.get(Criteria.class, Context.class);
|
||||
VirtualField<Criteria, Context> virtualField =
|
||||
VirtualField.find(Criteria.class, Context.class);
|
||||
|
||||
String entityName = null;
|
||||
if (criteria instanceof CriteriaImpl) {
|
||||
|
@ -69,7 +68,7 @@ public class CriteriaInstrumentation implements TypeInstrumentation {
|
|||
}
|
||||
|
||||
context =
|
||||
SessionMethodUtils.startSpanFrom(contextStore, criteria, "Criteria." + name, entityName);
|
||||
SessionMethodUtils.startSpanFrom(virtualField, criteria, "Criteria." + name, entityName);
|
||||
if (context != null) {
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
|
|
@ -13,11 +13,10 @@ import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -58,10 +57,9 @@ public class QueryInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<Query, Context> contextStore =
|
||||
InstrumentationContext.get(Query.class, Context.class);
|
||||
VirtualField<Query, Context> virtualField = VirtualField.find(Query.class, Context.class);
|
||||
|
||||
context = SessionMethodUtils.startSpanFromQuery(contextStore, query, query.getQueryString());
|
||||
context = SessionMethodUtils.startSpanFromQuery(virtualField, query, query.getQueryString());
|
||||
if (context != null) {
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
|
|
@ -15,10 +15,9 @@ import static net.bytebuddy.matcher.ElementMatchers.returns;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -61,13 +60,13 @@ public class SessionFactoryInstrumentation implements TypeInstrumentation {
|
|||
Context context = tracer().startSpan(parentContext, "Session");
|
||||
|
||||
if (session instanceof Session) {
|
||||
ContextStore<Session, Context> contextStore =
|
||||
InstrumentationContext.get(Session.class, Context.class);
|
||||
contextStore.putIfAbsent((Session) session, context);
|
||||
VirtualField<Session, Context> virtualField =
|
||||
VirtualField.find(Session.class, Context.class);
|
||||
virtualField.setIfNull((Session) session, context);
|
||||
} else if (session instanceof StatelessSession) {
|
||||
ContextStore<StatelessSession, Context> contextStore =
|
||||
InstrumentationContext.get(StatelessSession.class, Context.class);
|
||||
contextStore.putIfAbsent((StatelessSession) session, context);
|
||||
VirtualField<StatelessSession, Context> virtualField =
|
||||
VirtualField.find(StatelessSession.class, Context.class);
|
||||
virtualField.setIfNull((StatelessSession) session, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,10 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -79,7 +78,7 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
SessionInstrumentation.class.getName() + "$SessionMethodAdvice");
|
||||
|
||||
// These methods return some object that we want to instrument, and so the Advice will pin the
|
||||
// current Span to the returned object using a ContextStore.
|
||||
// current Span to the returned object using a VirtualField.
|
||||
transformer.applyAdviceToMethod(
|
||||
isMethod()
|
||||
.and(namedOneOf("beginTransaction", "getTransaction"))
|
||||
|
@ -104,13 +103,13 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
|
||||
Context sessionContext = null;
|
||||
if (session instanceof Session) {
|
||||
ContextStore<Session, Context> contextStore =
|
||||
InstrumentationContext.get(Session.class, Context.class);
|
||||
sessionContext = contextStore.get((Session) session);
|
||||
VirtualField<Session, Context> virtualField =
|
||||
VirtualField.find(Session.class, Context.class);
|
||||
sessionContext = virtualField.get((Session) session);
|
||||
} else if (session instanceof StatelessSession) {
|
||||
ContextStore<StatelessSession, Context> contextStore =
|
||||
InstrumentationContext.get(StatelessSession.class, Context.class);
|
||||
sessionContext = contextStore.get((StatelessSession) session);
|
||||
VirtualField<StatelessSession, Context> virtualField =
|
||||
VirtualField.find(StatelessSession.class, Context.class);
|
||||
sessionContext = virtualField.get((StatelessSession) session);
|
||||
}
|
||||
|
||||
if (sessionContext == null) {
|
||||
|
@ -145,13 +144,13 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
|
||||
Context sessionContext = null;
|
||||
if (session instanceof Session) {
|
||||
ContextStore<Session, Context> contextStore =
|
||||
InstrumentationContext.get(Session.class, Context.class);
|
||||
sessionContext = contextStore.get((Session) session);
|
||||
VirtualField<Session, Context> virtualField =
|
||||
VirtualField.find(Session.class, Context.class);
|
||||
sessionContext = virtualField.get((Session) session);
|
||||
} else if (session instanceof StatelessSession) {
|
||||
ContextStore<StatelessSession, Context> contextStore =
|
||||
InstrumentationContext.get(StatelessSession.class, Context.class);
|
||||
sessionContext = contextStore.get((StatelessSession) session);
|
||||
VirtualField<StatelessSession, Context> virtualField =
|
||||
VirtualField.find(StatelessSession.class, Context.class);
|
||||
sessionContext = virtualField.get((StatelessSession) session);
|
||||
}
|
||||
|
||||
if (sessionContext == null) {
|
||||
|
@ -192,18 +191,18 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void getQuery(@Advice.This Object session, @Advice.Return Query query) {
|
||||
|
||||
ContextStore<Query, Context> queryContextStore =
|
||||
InstrumentationContext.get(Query.class, Context.class);
|
||||
VirtualField<Query, Context> queryVirtualField =
|
||||
VirtualField.find(Query.class, Context.class);
|
||||
if (session instanceof Session) {
|
||||
ContextStore<Session, Context> sessionContextStore =
|
||||
InstrumentationContext.get(Session.class, Context.class);
|
||||
VirtualField<Session, Context> sessionVirtualField =
|
||||
VirtualField.find(Session.class, Context.class);
|
||||
SessionMethodUtils.attachSpanFromStore(
|
||||
sessionContextStore, (Session) session, queryContextStore, query);
|
||||
sessionVirtualField, (Session) session, queryVirtualField, query);
|
||||
} else if (session instanceof StatelessSession) {
|
||||
ContextStore<StatelessSession, Context> sessionContextStore =
|
||||
InstrumentationContext.get(StatelessSession.class, Context.class);
|
||||
VirtualField<StatelessSession, Context> sessionVirtualField =
|
||||
VirtualField.find(StatelessSession.class, Context.class);
|
||||
SessionMethodUtils.attachSpanFromStore(
|
||||
sessionContextStore, (StatelessSession) session, queryContextStore, query);
|
||||
sessionVirtualField, (StatelessSession) session, queryVirtualField, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,19 +214,19 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
public static void getTransaction(
|
||||
@Advice.This Object session, @Advice.Return Transaction transaction) {
|
||||
|
||||
ContextStore<Transaction, Context> transactionContextStore =
|
||||
InstrumentationContext.get(Transaction.class, Context.class);
|
||||
VirtualField<Transaction, Context> transactionVirtualField =
|
||||
VirtualField.find(Transaction.class, Context.class);
|
||||
|
||||
if (session instanceof Session) {
|
||||
ContextStore<Session, Context> sessionContextStore =
|
||||
InstrumentationContext.get(Session.class, Context.class);
|
||||
VirtualField<Session, Context> sessionVirtualField =
|
||||
VirtualField.find(Session.class, Context.class);
|
||||
SessionMethodUtils.attachSpanFromStore(
|
||||
sessionContextStore, (Session) session, transactionContextStore, transaction);
|
||||
sessionVirtualField, (Session) session, transactionVirtualField, transaction);
|
||||
} else if (session instanceof StatelessSession) {
|
||||
ContextStore<StatelessSession, Context> sessionContextStore =
|
||||
InstrumentationContext.get(StatelessSession.class, Context.class);
|
||||
VirtualField<StatelessSession, Context> sessionVirtualField =
|
||||
VirtualField.find(StatelessSession.class, Context.class);
|
||||
SessionMethodUtils.attachSpanFromStore(
|
||||
sessionContextStore, (StatelessSession) session, transactionContextStore, transaction);
|
||||
sessionVirtualField, (StatelessSession) session, transactionVirtualField, transaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -238,18 +237,18 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void getCriteria(@Advice.This Object session, @Advice.Return Criteria criteria) {
|
||||
|
||||
ContextStore<Criteria, Context> criteriaContextStore =
|
||||
InstrumentationContext.get(Criteria.class, Context.class);
|
||||
VirtualField<Criteria, Context> criteriaVirtualField =
|
||||
VirtualField.find(Criteria.class, Context.class);
|
||||
if (session instanceof Session) {
|
||||
ContextStore<Session, Context> sessionContextStore =
|
||||
InstrumentationContext.get(Session.class, Context.class);
|
||||
VirtualField<Session, Context> sessionVirtualField =
|
||||
VirtualField.find(Session.class, Context.class);
|
||||
SessionMethodUtils.attachSpanFromStore(
|
||||
sessionContextStore, (Session) session, criteriaContextStore, criteria);
|
||||
sessionVirtualField, (Session) session, criteriaVirtualField, criteria);
|
||||
} else if (session instanceof StatelessSession) {
|
||||
ContextStore<StatelessSession, Context> sessionContextStore =
|
||||
InstrumentationContext.get(StatelessSession.class, Context.class);
|
||||
VirtualField<StatelessSession, Context> sessionVirtualField =
|
||||
VirtualField.find(StatelessSession.class, Context.class);
|
||||
SessionMethodUtils.attachSpanFromStore(
|
||||
sessionContextStore, (StatelessSession) session, criteriaContextStore, criteria);
|
||||
sessionVirtualField, (StatelessSession) session, criteriaVirtualField, criteria);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,10 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -58,11 +57,11 @@ public class TransactionInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<Transaction, Context> contextStore =
|
||||
InstrumentationContext.get(Transaction.class, Context.class);
|
||||
VirtualField<Transaction, Context> virtualField =
|
||||
VirtualField.find(Transaction.class, Context.class);
|
||||
|
||||
context =
|
||||
SessionMethodUtils.startSpanFrom(contextStore, transaction, "Transaction.commit", null);
|
||||
SessionMethodUtils.startSpanFrom(virtualField, transaction, "Transaction.commit", null);
|
||||
if (context != null) {
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
|
|
@ -13,11 +13,10 @@ import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -60,8 +59,8 @@ public class CriteriaInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<Criteria, Context> contextStore =
|
||||
InstrumentationContext.get(Criteria.class, Context.class);
|
||||
VirtualField<Criteria, Context> virtualField =
|
||||
VirtualField.find(Criteria.class, Context.class);
|
||||
|
||||
String entityName = null;
|
||||
if (criteria instanceof CriteriaImpl) {
|
||||
|
@ -69,7 +68,7 @@ public class CriteriaInstrumentation implements TypeInstrumentation {
|
|||
}
|
||||
|
||||
context =
|
||||
SessionMethodUtils.startSpanFrom(contextStore, criteria, "Criteria." + name, entityName);
|
||||
SessionMethodUtils.startSpanFrom(virtualField, criteria, "Criteria." + name, entityName);
|
||||
if (context != null) {
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
|
|
@ -13,11 +13,10 @@ import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -58,10 +57,9 @@ public class QueryInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<Query, Context> contextStore =
|
||||
InstrumentationContext.get(Query.class, Context.class);
|
||||
VirtualField<Query, Context> virtualField = VirtualField.find(Query.class, Context.class);
|
||||
|
||||
context = SessionMethodUtils.startSpanFromQuery(contextStore, query, query.getQueryString());
|
||||
context = SessionMethodUtils.startSpanFromQuery(virtualField, query, query.getQueryString());
|
||||
if (context != null) {
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
|
|
@ -15,10 +15,9 @@ import static net.bytebuddy.matcher.ElementMatchers.returns;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -57,9 +56,9 @@ public class SessionFactoryInstrumentation implements TypeInstrumentation {
|
|||
Context parentContext = Java8BytecodeBridge.currentContext();
|
||||
Context context = tracer().startSpan(parentContext, "Session");
|
||||
|
||||
ContextStore<SharedSessionContract, Context> contextStore =
|
||||
InstrumentationContext.get(SharedSessionContract.class, Context.class);
|
||||
contextStore.putIfAbsent(session, context);
|
||||
VirtualField<SharedSessionContract, Context> virtualField =
|
||||
VirtualField.find(SharedSessionContract.class, Context.class);
|
||||
virtualField.setIfNull(session, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,11 +20,10 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -81,7 +80,7 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
SessionInstrumentation.class.getName() + "$SessionMethodAdvice");
|
||||
|
||||
// These methods return some object that we want to instrument, and so the Advice will pin the
|
||||
// current Span to the returned object using a ContextStore.
|
||||
// current Span to the returned object using a VirtualField.
|
||||
transformer.applyAdviceToMethod(
|
||||
isMethod()
|
||||
.and(namedOneOf("beginTransaction", "getTransaction"))
|
||||
|
@ -104,9 +103,9 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
public static void closeSession(
|
||||
@Advice.This SharedSessionContract session, @Advice.Thrown Throwable throwable) {
|
||||
|
||||
ContextStore<SharedSessionContract, Context> contextStore =
|
||||
InstrumentationContext.get(SharedSessionContract.class, Context.class);
|
||||
Context sessionContext = contextStore.get(session);
|
||||
VirtualField<SharedSessionContract, Context> virtualField =
|
||||
VirtualField.find(SharedSessionContract.class, Context.class);
|
||||
Context sessionContext = virtualField.get(session);
|
||||
if (sessionContext == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -137,9 +136,9 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<SharedSessionContract, Context> contextStore =
|
||||
InstrumentationContext.get(SharedSessionContract.class, Context.class);
|
||||
Context sessionContext = contextStore.get(session);
|
||||
VirtualField<SharedSessionContract, Context> virtualField =
|
||||
VirtualField.find(SharedSessionContract.class, Context.class);
|
||||
Context sessionContext = virtualField.get(session);
|
||||
|
||||
if (sessionContext == null) {
|
||||
return; // No state found. We aren't in a Session.
|
||||
|
@ -181,13 +180,13 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
public static void getQuery(
|
||||
@Advice.This SharedSessionContract session, @Advice.Return Query query) {
|
||||
|
||||
ContextStore<SharedSessionContract, Context> sessionContextStore =
|
||||
InstrumentationContext.get(SharedSessionContract.class, Context.class);
|
||||
ContextStore<Query, Context> queryContextStore =
|
||||
InstrumentationContext.get(Query.class, Context.class);
|
||||
VirtualField<SharedSessionContract, Context> sessionVirtualField =
|
||||
VirtualField.find(SharedSessionContract.class, Context.class);
|
||||
VirtualField<Query, Context> queryVirtualField =
|
||||
VirtualField.find(Query.class, Context.class);
|
||||
|
||||
SessionMethodUtils.attachSpanFromStore(
|
||||
sessionContextStore, session, queryContextStore, query);
|
||||
sessionVirtualField, session, queryVirtualField, query);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,13 +197,13 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
public static void getTransaction(
|
||||
@Advice.This SharedSessionContract session, @Advice.Return Transaction transaction) {
|
||||
|
||||
ContextStore<SharedSessionContract, Context> sessionContextStore =
|
||||
InstrumentationContext.get(SharedSessionContract.class, Context.class);
|
||||
ContextStore<Transaction, Context> transactionContextStore =
|
||||
InstrumentationContext.get(Transaction.class, Context.class);
|
||||
VirtualField<SharedSessionContract, Context> sessionVirtualField =
|
||||
VirtualField.find(SharedSessionContract.class, Context.class);
|
||||
VirtualField<Transaction, Context> transactionVirtualField =
|
||||
VirtualField.find(Transaction.class, Context.class);
|
||||
|
||||
SessionMethodUtils.attachSpanFromStore(
|
||||
sessionContextStore, session, transactionContextStore, transaction);
|
||||
sessionVirtualField, session, transactionVirtualField, transaction);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,13 +214,13 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
public static void getCriteria(
|
||||
@Advice.This SharedSessionContract session, @Advice.Return Criteria criteria) {
|
||||
|
||||
ContextStore<SharedSessionContract, Context> sessionContextStore =
|
||||
InstrumentationContext.get(SharedSessionContract.class, Context.class);
|
||||
ContextStore<Criteria, Context> criteriaContextStore =
|
||||
InstrumentationContext.get(Criteria.class, Context.class);
|
||||
VirtualField<SharedSessionContract, Context> sessionVirtualField =
|
||||
VirtualField.find(SharedSessionContract.class, Context.class);
|
||||
VirtualField<Criteria, Context> criteriaVirtualField =
|
||||
VirtualField.find(Criteria.class, Context.class);
|
||||
|
||||
SessionMethodUtils.attachSpanFromStore(
|
||||
sessionContextStore, session, criteriaContextStore, criteria);
|
||||
sessionVirtualField, session, criteriaVirtualField, criteria);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,10 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -58,11 +57,11 @@ public class TransactionInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<Transaction, Context> contextStore =
|
||||
InstrumentationContext.get(Transaction.class, Context.class);
|
||||
VirtualField<Transaction, Context> virtualField =
|
||||
VirtualField.find(Transaction.class, Context.class);
|
||||
|
||||
context =
|
||||
SessionMethodUtils.startSpanFrom(contextStore, transaction, "Transaction.commit", null);
|
||||
SessionMethodUtils.startSpanFrom(virtualField, transaction, "Transaction.commit", null);
|
||||
if (context != null) {
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import static io.opentelemetry.javaagent.instrumentation.hibernate.HibernateTrac
|
|||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.db.SqlStatementInfo;
|
||||
import io.opentelemetry.instrumentation.api.db.SqlStatementSanitizer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -24,20 +24,20 @@ public final class SessionMethodUtils {
|
|||
new HashSet<>(Arrays.asList("immediateLoad", "internalLoad"));
|
||||
|
||||
public static <TARGET, ENTITY> Context startSpanFrom(
|
||||
ContextStore<TARGET, Context> contextStore,
|
||||
VirtualField<TARGET, Context> virtualField,
|
||||
TARGET spanKey,
|
||||
String operationName,
|
||||
String entityName) {
|
||||
return startSpanFrom(contextStore, spanKey, () -> operationName, entityName);
|
||||
return startSpanFrom(virtualField, spanKey, () -> operationName, entityName);
|
||||
}
|
||||
|
||||
private static <TARGET, ENTITY> Context startSpanFrom(
|
||||
ContextStore<TARGET, Context> contextStore,
|
||||
VirtualField<TARGET, Context> virtualField,
|
||||
TARGET spanKey,
|
||||
Supplier<String> operationNameSupplier,
|
||||
String entityName) {
|
||||
|
||||
Context sessionContext = contextStore.get(spanKey);
|
||||
Context sessionContext = virtualField.get(spanKey);
|
||||
if (sessionContext == null) {
|
||||
return null; // No state found. We aren't in a Session.
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public final class SessionMethodUtils {
|
|||
}
|
||||
|
||||
public static <TARGET> Context startSpanFromQuery(
|
||||
ContextStore<TARGET, Context> contextStore, TARGET spanKey, String query) {
|
||||
VirtualField<TARGET, Context> virtualField, TARGET spanKey, String query) {
|
||||
Supplier<String> operationNameSupplier =
|
||||
() -> {
|
||||
// set operation to default value that is used when sql sanitizer fails to extract
|
||||
|
@ -61,7 +61,7 @@ public final class SessionMethodUtils {
|
|||
}
|
||||
return operation;
|
||||
};
|
||||
return startSpanFrom(contextStore, spanKey, operationNameSupplier, null);
|
||||
return startSpanFrom(virtualField, spanKey, operationNameSupplier, null);
|
||||
}
|
||||
|
||||
public static void end(@Nullable Context context, Throwable throwable) {
|
||||
|
@ -77,20 +77,20 @@ public final class SessionMethodUtils {
|
|||
}
|
||||
}
|
||||
|
||||
// Copies a span from the given Session ContextStore into the targetContextStore. Used to
|
||||
// Copies a span from the given Session VirtualField into the targetVirtualField. Used to
|
||||
// propagate a Span from a Session to transient Session objects such as Transaction and Query.
|
||||
public static <S, T> void attachSpanFromStore(
|
||||
ContextStore<S, Context> sourceContextStore,
|
||||
VirtualField<S, Context> sourceVirtualField,
|
||||
S source,
|
||||
ContextStore<T, Context> targetContextStore,
|
||||
VirtualField<T, Context> targetVirtualField,
|
||||
T target) {
|
||||
|
||||
Context sessionContext = sourceContextStore.get(source);
|
||||
Context sessionContext = sourceVirtualField.get(source);
|
||||
if (sessionContext == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
targetContextStore.putIfAbsent(target, sessionContext);
|
||||
targetVirtualField.setIfNull(target, sessionContext);
|
||||
}
|
||||
|
||||
public static String getSessionMethodSpanName(String methodName) {
|
||||
|
|
|
@ -12,11 +12,10 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -58,12 +57,12 @@ public class ProcedureCallInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<ProcedureCall, Context> contextStore =
|
||||
InstrumentationContext.get(ProcedureCall.class, Context.class);
|
||||
VirtualField<ProcedureCall, Context> virtualField =
|
||||
VirtualField.find(ProcedureCall.class, Context.class);
|
||||
|
||||
context =
|
||||
SessionMethodUtils.startSpanFrom(
|
||||
contextStore, call, "ProcedureCall." + name, call.getProcedureName());
|
||||
virtualField, call, "ProcedureCall." + name, call.getProcedureName());
|
||||
if (context != null) {
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
|
|
@ -12,10 +12,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.hibernate.SessionMethodUtils;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -50,13 +49,13 @@ public class SessionInstrumentation implements TypeInstrumentation {
|
|||
public static void getProcedureCall(
|
||||
@Advice.This SharedSessionContract session, @Advice.Return ProcedureCall returned) {
|
||||
|
||||
ContextStore<SharedSessionContract, Context> sessionContextStore =
|
||||
InstrumentationContext.get(SharedSessionContract.class, Context.class);
|
||||
ContextStore<ProcedureCall, Context> returnedContextStore =
|
||||
InstrumentationContext.get(ProcedureCall.class, Context.class);
|
||||
VirtualField<SharedSessionContract, Context> sessionVirtualField =
|
||||
VirtualField.find(SharedSessionContract.class, Context.class);
|
||||
VirtualField<ProcedureCall, Context> returnedVirtualField =
|
||||
VirtualField.find(ProcedureCall.class, Context.class);
|
||||
|
||||
SessionMethodUtils.attachSpanFromStore(
|
||||
sessionContextStore, session, returnedContextStore, returned);
|
||||
sessionVirtualField, session, returnedVirtualField, returned);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,11 @@ import io.opentelemetry.api.trace.Span;
|
|||
import io.opentelemetry.api.trace.StatusCode;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.api.tracer.HttpStatusConverter;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.HttpURLConnection;
|
||||
|
@ -83,8 +82,8 @@ public class HttpUrlConnectionInstrumentation implements TypeInstrumentation {
|
|||
// using storage for a couple of reasons:
|
||||
// - to start an operation in connect() and end it in getInputStream()
|
||||
// - to avoid creating a new operation on multiple subsequent calls to getInputStream()
|
||||
ContextStore<HttpURLConnection, HttpUrlState> storage =
|
||||
InstrumentationContext.get(HttpURLConnection.class, HttpUrlState.class);
|
||||
VirtualField<HttpURLConnection, HttpUrlState> storage =
|
||||
VirtualField.find(HttpURLConnection.class, HttpUrlState.class);
|
||||
httpUrlState = storage.get(connection);
|
||||
|
||||
if (httpUrlState != null) {
|
||||
|
@ -96,7 +95,7 @@ public class HttpUrlConnectionInstrumentation implements TypeInstrumentation {
|
|||
|
||||
Context context = instrumenter().start(parentContext, connection);
|
||||
httpUrlState = new HttpUrlState(context);
|
||||
storage.put(connection, httpUrlState);
|
||||
storage.set(connection, httpUrlState);
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
||||
|
@ -149,8 +148,8 @@ public class HttpUrlConnectionInstrumentation implements TypeInstrumentation {
|
|||
public static void methodExit(
|
||||
@Advice.This HttpURLConnection connection, @Advice.Return int returnValue) {
|
||||
|
||||
ContextStore<HttpURLConnection, HttpUrlState> storage =
|
||||
InstrumentationContext.get(HttpURLConnection.class, HttpUrlState.class);
|
||||
VirtualField<HttpURLConnection, HttpUrlState> storage =
|
||||
VirtualField.find(HttpURLConnection.class, HttpUrlState.class);
|
||||
HttpUrlState httpUrlState = storage.get(connection);
|
||||
if (httpUrlState != null) {
|
||||
Span span = Java8BytecodeBridge.spanFromContext(httpUrlState.context);
|
||||
|
|
|
@ -13,7 +13,7 @@ class ClassLoadingTest extends AgentInstrumentationSpecification {
|
|||
when:
|
||||
Class<?> clazz
|
||||
try {
|
||||
clazz = Class.forName("io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext", false, classLoader)
|
||||
clazz = Class.forName("io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge", false, classLoader)
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class JBossClassloadingTest extends AgentInstrumentationSpecification {
|
|||
when:
|
||||
Class<?> clazz
|
||||
try {
|
||||
clazz = Class.forName("io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext", false, classLoader)
|
||||
clazz = Class.forName("io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge", false, classLoader)
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,9 @@ class OSGIClassloadingTest extends AgentInstrumentationSpecification {
|
|||
when:
|
||||
def clazz
|
||||
if (args == 1) {
|
||||
clazz = loader.loadClass("io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext")
|
||||
clazz = loader.loadClass("io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge")
|
||||
} else {
|
||||
clazz = loader.loadClass("io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext", false)
|
||||
clazz = loader.loadClass("io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge", false)
|
||||
}
|
||||
|
||||
then:
|
||||
|
|
|
@ -26,6 +26,6 @@ class TomcatClassloadingTest extends AgentInstrumentationSpecification {
|
|||
|
||||
expect:
|
||||
// If instrumentation didn't work this would blow up with NPE due to incomplete resources mocking
|
||||
classloader.loadClass("io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext")
|
||||
classloader.loadClass("io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ package instrumentation;
|
|||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -35,7 +35,7 @@ public class TestTypeInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodExit
|
||||
public static void methodExit(
|
||||
@Advice.This Runnable test, @Advice.Return(readOnly = false) String result) {
|
||||
InstrumentationContext.get(Runnable.class, String.class).put(test, "instrumented");
|
||||
VirtualField.find(Runnable.class, String.class).set(test, "instrumented");
|
||||
result = "instrumented";
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class TestTypeInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodExit
|
||||
public static void methodExit(
|
||||
@Advice.This Runnable test, @Advice.Return(readOnly = false) String result) {
|
||||
result = InstrumentationContext.get(Runnable.class, String.class).get(test);
|
||||
result = VirtualField.find(Runnable.class, String.class).get(test);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,11 @@ import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
@ -83,12 +82,12 @@ public class JaxrsAnnotationsInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<AsyncResponse, AsyncResponseData> contextStore = null;
|
||||
VirtualField<AsyncResponse, AsyncResponseData> virtualField = null;
|
||||
for (Object arg : args) {
|
||||
if (arg instanceof AsyncResponse) {
|
||||
asyncResponse = (AsyncResponse) arg;
|
||||
contextStore = InstrumentationContext.get(AsyncResponse.class, AsyncResponseData.class);
|
||||
if (contextStore.get(asyncResponse) != null) {
|
||||
virtualField = VirtualField.find(AsyncResponse.class, AsyncResponseData.class);
|
||||
if (virtualField.get(asyncResponse) != null) {
|
||||
/*
|
||||
* We are probably in a recursive call and don't want to start a new span because it
|
||||
* would replace the existing span in the asyncResponse and cause it to never finish. We
|
||||
|
@ -117,8 +116,8 @@ public class JaxrsAnnotationsInstrumentation implements TypeInstrumentation {
|
|||
context = instrumenter().start(parentContext, handlerData);
|
||||
scope = context.makeCurrent();
|
||||
|
||||
if (contextStore != null && asyncResponse != null) {
|
||||
contextStore.put(asyncResponse, AsyncResponseData.create(context, handlerData));
|
||||
if (virtualField != null && asyncResponse != null) {
|
||||
virtualField.set(asyncResponse, AsyncResponseData.create(context, handlerData));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,8 +150,7 @@ public class JaxrsAnnotationsInstrumentation implements TypeInstrumentation {
|
|||
|
||||
if (asyncResponse != null && !asyncResponse.isSuspended()) {
|
||||
// Clear span from the asyncResponse. Logically this should never happen. Added to be safe.
|
||||
InstrumentationContext.get(AsyncResponse.class, AsyncResponseData.class)
|
||||
.put(asyncResponse, null);
|
||||
VirtualField.find(AsyncResponse.class, AsyncResponseData.class).set(asyncResponse, null);
|
||||
}
|
||||
if (asyncReturnValue != null) {
|
||||
// span finished by CompletionStageFinishCallback
|
||||
|
|
|
@ -13,10 +13,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 javax.ws.rs.container.AsyncResponse;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -54,12 +53,12 @@ public class JaxrsAsyncResponseInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void stopSpan(@Advice.This AsyncResponse asyncResponse) {
|
||||
|
||||
ContextStore<AsyncResponse, AsyncResponseData> contextStore =
|
||||
InstrumentationContext.get(AsyncResponse.class, AsyncResponseData.class);
|
||||
VirtualField<AsyncResponse, AsyncResponseData> virtualField =
|
||||
VirtualField.find(AsyncResponse.class, AsyncResponseData.class);
|
||||
|
||||
AsyncResponseData data = contextStore.get(asyncResponse);
|
||||
AsyncResponseData data = virtualField.get(asyncResponse);
|
||||
if (data != null) {
|
||||
contextStore.put(asyncResponse, null);
|
||||
virtualField.set(asyncResponse, null);
|
||||
instrumenter().end(data.getContext(), data.getHandlerData(), null, null);
|
||||
}
|
||||
}
|
||||
|
@ -72,12 +71,12 @@ public class JaxrsAsyncResponseInstrumentation implements TypeInstrumentation {
|
|||
public static void stopSpan(
|
||||
@Advice.This AsyncResponse asyncResponse, @Advice.Argument(0) Throwable throwable) {
|
||||
|
||||
ContextStore<AsyncResponse, AsyncResponseData> contextStore =
|
||||
InstrumentationContext.get(AsyncResponse.class, AsyncResponseData.class);
|
||||
VirtualField<AsyncResponse, AsyncResponseData> virtualField =
|
||||
VirtualField.find(AsyncResponse.class, AsyncResponseData.class);
|
||||
|
||||
AsyncResponseData data = contextStore.get(asyncResponse);
|
||||
AsyncResponseData data = virtualField.get(asyncResponse);
|
||||
if (data != null) {
|
||||
contextStore.put(asyncResponse, null);
|
||||
virtualField.set(asyncResponse, null);
|
||||
instrumenter().end(data.getContext(), data.getHandlerData(), null, throwable);
|
||||
}
|
||||
}
|
||||
|
@ -89,12 +88,12 @@ public class JaxrsAsyncResponseInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void stopSpan(@Advice.This AsyncResponse asyncResponse) {
|
||||
|
||||
ContextStore<AsyncResponse, AsyncResponseData> contextStore =
|
||||
InstrumentationContext.get(AsyncResponse.class, AsyncResponseData.class);
|
||||
VirtualField<AsyncResponse, AsyncResponseData> virtualField =
|
||||
VirtualField.find(AsyncResponse.class, AsyncResponseData.class);
|
||||
|
||||
AsyncResponseData data = contextStore.get(asyncResponse);
|
||||
AsyncResponseData data = virtualField.get(asyncResponse);
|
||||
if (data != null) {
|
||||
contextStore.put(asyncResponse, null);
|
||||
virtualField.set(asyncResponse, null);
|
||||
Context context = data.getContext();
|
||||
if (JaxrsConfig.CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
Java8BytecodeBridge.spanFromContext(context).setAttribute("jaxrs.canceled", true);
|
||||
|
|
|
@ -10,10 +10,10 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -48,8 +48,7 @@ public class ResteasyResourceLocatorInvokerInstrumentation implements TypeInstru
|
|||
Context currentContext = Java8BytecodeBridge.currentContext();
|
||||
|
||||
String name =
|
||||
InstrumentationContext.get(ResourceLocatorInvoker.class, String.class)
|
||||
.get(resourceInvoker);
|
||||
VirtualField.find(ResourceLocatorInvoker.class, String.class).get(resourceInvoker);
|
||||
ResteasyTracingUtil.updateServerSpanName(currentContext, name);
|
||||
|
||||
// subresource locator returns a resources class that may have @Path annotations
|
||||
|
|
|
@ -8,9 +8,9 @@ package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -40,8 +40,7 @@ public class ResteasyResourceMethodInvokerInstrumentation implements TypeInstrum
|
|||
public static void onEnter(@Advice.This ResourceMethodInvoker resourceInvoker) {
|
||||
|
||||
String name =
|
||||
InstrumentationContext.get(ResourceMethodInvoker.class, String.class)
|
||||
.get(resourceInvoker);
|
||||
VirtualField.find(ResourceMethodInvoker.class, String.class).get(resourceInvoker);
|
||||
ResteasyTracingUtil.updateServerSpanName(Java8BytecodeBridge.currentContext(), name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||
|
@ -50,12 +50,12 @@ public class ResteasyRootNodeTypeInstrumentation implements TypeInstrumentation
|
|||
String normalizedPath = JaxrsPathUtil.normalizePath(path);
|
||||
if (invoker instanceof ResourceLocatorInvoker) {
|
||||
ResourceLocatorInvoker resourceLocatorInvoker = (ResourceLocatorInvoker) invoker;
|
||||
InstrumentationContext.get(ResourceLocatorInvoker.class, String.class)
|
||||
.put(resourceLocatorInvoker, normalizedPath);
|
||||
VirtualField.find(ResourceLocatorInvoker.class, String.class)
|
||||
.set(resourceLocatorInvoker, normalizedPath);
|
||||
} else if (invoker instanceof ResourceMethodInvoker) {
|
||||
ResourceMethodInvoker resourceMethodInvoker = (ResourceMethodInvoker) invoker;
|
||||
InstrumentationContext.get(ResourceMethodInvoker.class, String.class)
|
||||
.put(resourceMethodInvoker, normalizedPath);
|
||||
VirtualField.find(ResourceMethodInvoker.class, String.class)
|
||||
.set(resourceMethodInvoker, normalizedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.jdbc;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.caching.Cache;
|
||||
import io.opentelemetry.instrumentation.jdbc.internal.DbInfo;
|
||||
import io.opentelemetry.instrumentation.jdbc.internal.JdbcData;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
/**
|
||||
* Provides means to associate extra info with JDBC {@link Connection} and {@link PreparedStatement}
|
||||
* using {@link ContextStore} which is more efficient than using a weak map.
|
||||
*/
|
||||
public class AgentCacheFactory implements JdbcData.CacheFactory {
|
||||
private final Cache<Connection, DbInfo> connectionCache;
|
||||
private final Cache<PreparedStatement, String> preparedStatementCache;
|
||||
|
||||
public AgentCacheFactory() {
|
||||
ContextStore<Connection, DbInfo> connectionContextStore =
|
||||
InstrumentationContext.get(Connection.class, DbInfo.class);
|
||||
connectionCache = connectionContextStore.asCache();
|
||||
ContextStore<PreparedStatement, String> preparedStatementContextStore =
|
||||
InstrumentationContext.get(PreparedStatement.class, String.class);
|
||||
preparedStatementCache = preparedStatementContextStore.asCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cache<Connection, DbInfo> connectionInfoCache() {
|
||||
return connectionCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cache<PreparedStatement, String> preparedStatementCache() {
|
||||
return preparedStatementCache;
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.jdbc;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.none;
|
||||
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
public class AgentCacheInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return none();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(TypeTransformer transformer) {
|
||||
transformer.applyAdviceToMethod(
|
||||
none(), AgentCacheInstrumentation.class.getName() + "$InitAdvice");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class InitAdvice {
|
||||
public void init() {
|
||||
// the sole purpose of this advice is to ensure that AgentDataStoreFactory is recognized
|
||||
// as helper class and injected into class loader
|
||||
AgentCacheFactory.class.getName();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ public class ConnectionInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void addDbInfo(
|
||||
@Advice.Argument(0) String sql, @Advice.Return PreparedStatement statement) {
|
||||
JdbcData.preparedStatement.put(statement, sql);
|
||||
JdbcData.preparedStatement.set(statement, sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class DriverInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
DbInfo dbInfo = JdbcConnectionUrlParser.parse(url, props);
|
||||
JdbcData.connectionInfo.put(connection, dbInfo);
|
||||
JdbcData.connectionInfo.set(connection, dbInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ public class JdbcInstrumentationModule extends InstrumentationModule {
|
|||
new ConnectionInstrumentation(),
|
||||
new DriverInstrumentation(),
|
||||
new PreparedStatementInstrumentation(),
|
||||
new StatementInstrumentation(),
|
||||
new AgentCacheInstrumentation());
|
||||
new StatementInstrumentation());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import io.opentelemetry.api.trace.SpanKind
|
|||
import io.opentelemetry.instrumentation.jdbc.TestConnection
|
||||
import io.opentelemetry.instrumentation.jdbc.TestDriver
|
||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||
import io.opentelemetry.javaagent.instrumentation.jdbc.AgentCacheFactory
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import org.apache.derby.jdbc.EmbeddedDataSource
|
||||
import org.apache.derby.jdbc.EmbeddedDriver
|
||||
|
@ -21,7 +20,6 @@ import spock.lang.Shared
|
|||
import spock.lang.Unroll
|
||||
|
||||
import javax.sql.DataSource
|
||||
import java.lang.reflect.Field
|
||||
import java.sql.CallableStatement
|
||||
import java.sql.Connection
|
||||
import java.sql.DatabaseMetaData
|
||||
|
@ -803,17 +801,6 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification {
|
|||
"getMetaData() uses PreparedStatement, test PreparedStatement" | true | { con, query -> con.prepareStatement(query).executeQuery() }
|
||||
}
|
||||
|
||||
def "should use agent data store"() {
|
||||
setup:
|
||||
Class<?> clazz = Class.forName("io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcData")
|
||||
Field field = clazz.getDeclaredField("cacheFactory")
|
||||
field.setAccessible(true)
|
||||
def dataStoreFactory = field.get(null)
|
||||
|
||||
expect:
|
||||
dataStoreFactory.getClass() == AgentCacheFactory
|
||||
}
|
||||
|
||||
class DbCallingConnection extends TestConnection {
|
||||
final boolean usePreparedStatement
|
||||
|
||||
|
|
|
@ -5,55 +5,17 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.jdbc.internal;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.caching.Cache;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** Holds info associated with JDBC connections and prepared statements. */
|
||||
public final class JdbcData {
|
||||
private static final Logger logger = LoggerFactory.getLogger(JdbcData.class);
|
||||
|
||||
private static final CacheFactory cacheFactory = getCacheFactory();
|
||||
|
||||
public static Cache<Connection, DbInfo> connectionInfo = cacheFactory.connectionInfoCache();
|
||||
public static Cache<PreparedStatement, String> preparedStatement =
|
||||
cacheFactory.preparedStatementCache();
|
||||
public static VirtualField<Connection, DbInfo> connectionInfo =
|
||||
VirtualField.find(Connection.class, DbInfo.class);
|
||||
public static VirtualField<PreparedStatement, String> preparedStatement =
|
||||
VirtualField.find(PreparedStatement.class, String.class);
|
||||
|
||||
private JdbcData() {}
|
||||
|
||||
private static CacheFactory getCacheFactory() {
|
||||
try {
|
||||
// this class is provided by jdbc javaagent instrumentation
|
||||
Class<?> clazz =
|
||||
Class.forName("io.opentelemetry.javaagent.instrumentation.jdbc.AgentCacheFactory");
|
||||
return (CacheFactory) clazz.getConstructor().newInstance();
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
// ignored, this is expected when running as library instrumentation
|
||||
} catch (Exception exception) {
|
||||
logger.error("Failed to instantiate AgentCacheFactory", exception);
|
||||
}
|
||||
|
||||
return new DefaultCacheFactory();
|
||||
}
|
||||
|
||||
public interface CacheFactory {
|
||||
Cache<Connection, DbInfo> connectionInfoCache();
|
||||
|
||||
Cache<PreparedStatement, String> preparedStatementCache();
|
||||
}
|
||||
|
||||
private static class DefaultCacheFactory implements CacheFactory {
|
||||
|
||||
@Override
|
||||
public Cache<Connection, DbInfo> connectionInfoCache() {
|
||||
return Cache.newBuilder().setWeakKeys().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cache<PreparedStatement, String> preparedStatementCache() {
|
||||
return Cache.newBuilder().setWeakKeys().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public final class JdbcUtils {
|
|||
DbInfo dbInfo = JdbcData.connectionInfo.get(connection);
|
||||
if (dbInfo == null) {
|
||||
dbInfo = computeDbInfo(connection);
|
||||
JdbcData.connectionInfo.put(connection, dbInfo);
|
||||
JdbcData.connectionInfo.set(connection, dbInfo);
|
||||
}
|
||||
return dbInfo;
|
||||
}
|
||||
|
|
|
@ -10,10 +10,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.ExecutorAdviceHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.PropagatedContext;
|
||||
|
@ -43,9 +42,9 @@ public class JettyQueuedThreadPoolInstrumentation implements TypeInstrumentation
|
|||
@Advice.Argument(value = 0, readOnly = false) Runnable task) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
|
||||
ContextStore<Runnable, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, task);
|
||||
VirtualField<Runnable, PropagatedContext> virtualField =
|
||||
VirtualField.find(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -65,7 +65,7 @@ public class ConsumerRecordsInstrumentation implements TypeInstrumentation {
|
|||
@Advice.Return(readOnly = false) Iterable<ConsumerRecord<?, ?>> iterable) {
|
||||
if (iterable != null) {
|
||||
SpanContext receiveSpanContext =
|
||||
InstrumentationContext.get(ConsumerRecords.class, SpanContext.class).get(records);
|
||||
VirtualField.find(ConsumerRecords.class, SpanContext.class).get(records);
|
||||
iterable = new TracingIterable(iterable, receiveSpanContext);
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class ConsumerRecordsInstrumentation implements TypeInstrumentation {
|
|||
@Advice.Return(readOnly = false) List<ConsumerRecord<?, ?>> list) {
|
||||
if (list != null) {
|
||||
SpanContext receiveSpanContext =
|
||||
InstrumentationContext.get(ConsumerRecords.class, SpanContext.class).get(records);
|
||||
VirtualField.find(ConsumerRecords.class, SpanContext.class).get(records);
|
||||
list = new TracingList(list, receiveSpanContext);
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public class ConsumerRecordsInstrumentation implements TypeInstrumentation {
|
|||
@Advice.Return(readOnly = false) Iterator<ConsumerRecord<?, ?>> iterator) {
|
||||
if (iterator != null) {
|
||||
SpanContext receiveSpanContext =
|
||||
InstrumentationContext.get(ConsumerRecords.class, SpanContext.class).get(records);
|
||||
VirtualField.find(ConsumerRecords.class, SpanContext.class).get(records);
|
||||
iterator = new TracingIterator(iterator, receiveSpanContext);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 java.time.Duration;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -72,9 +71,9 @@ public class KafkaConsumerInstrumentation implements TypeInstrumentation {
|
|||
// context even though the span has ended
|
||||
// this is the suggested behavior according to the spec batch receive scenario:
|
||||
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/messaging.md#batch-receiving
|
||||
ContextStore<ConsumerRecords, SpanContext> consumerRecordsSpan =
|
||||
InstrumentationContext.get(ConsumerRecords.class, SpanContext.class);
|
||||
consumerRecordsSpan.put(records, spanFromContext(context).getSpanContext());
|
||||
VirtualField<ConsumerRecords, SpanContext> consumerRecordsSpan =
|
||||
VirtualField.find(ConsumerRecords.class, SpanContext.class);
|
||||
consumerRecordsSpan.set(records, spanFromContext(context).getSpanContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ import static net.bytebuddy.matcher.ElementMatchers.returns;
|
|||
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -61,7 +61,7 @@ public class PartitionGroupInstrumentation implements TypeInstrumentation {
|
|||
// use the receive CONSUMER span as parent if it's available
|
||||
Context parentContext = currentContext();
|
||||
SpanContext receiveSpanContext =
|
||||
InstrumentationContext.get(ConsumerRecord.class, SpanContext.class).get(record.value);
|
||||
VirtualField.find(ConsumerRecord.class, SpanContext.class).get(record.value);
|
||||
if (receiveSpanContext != null) {
|
||||
parentContext = parentContext.with(wrapSpan(receiveSpanContext));
|
||||
}
|
||||
|
|
|
@ -15,10 +15,9 @@ import static net.bytebuddy.matcher.ElementMatchers.returns;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -58,9 +57,9 @@ public class RecordDeserializerInstrumentation implements TypeInstrumentation {
|
|||
@Advice.Return(readOnly = false) ConsumerRecord<?, ?> result) {
|
||||
|
||||
// copy the receive CONSUMER span association
|
||||
ContextStore<ConsumerRecord, SpanContext> singleRecordReceiveSpan =
|
||||
InstrumentationContext.get(ConsumerRecord.class, SpanContext.class);
|
||||
singleRecordReceiveSpan.put(result, singleRecordReceiveSpan.get(incoming));
|
||||
VirtualField<ConsumerRecord, SpanContext> singleRecordReceiveSpan =
|
||||
VirtualField.find(ConsumerRecord.class, SpanContext.class);
|
||||
singleRecordReceiveSpan.set(result, singleRecordReceiveSpan.get(incoming));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,9 @@ import static net.bytebuddy.matcher.ElementMatchers.returns;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -64,9 +63,9 @@ public class SourceNodeRecordDeserializerInstrumentation implements TypeInstrume
|
|||
incoming.headers());
|
||||
|
||||
// copy the receive CONSUMER span association
|
||||
ContextStore<ConsumerRecord, SpanContext> singleRecordReceiveSpan =
|
||||
InstrumentationContext.get(ConsumerRecord.class, SpanContext.class);
|
||||
singleRecordReceiveSpan.put(result, singleRecordReceiveSpan.get(incoming));
|
||||
VirtualField<ConsumerRecord, SpanContext> singleRecordReceiveSpan =
|
||||
VirtualField.find(ConsumerRecord.class, SpanContext.class);
|
||||
singleRecordReceiveSpan.set(result, singleRecordReceiveSpan.get(incoming));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.kafka.KafkaConsumerIteratorWrapper;
|
||||
import java.util.Iterator;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -49,13 +48,13 @@ public class StreamThreadInstrumentation implements TypeInstrumentation {
|
|||
}
|
||||
|
||||
SpanContext receiveSpanContext =
|
||||
InstrumentationContext.get(ConsumerRecords.class, SpanContext.class).get(records);
|
||||
VirtualField.find(ConsumerRecords.class, SpanContext.class).get(records);
|
||||
if (receiveSpanContext == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ContextStore<ConsumerRecord, SpanContext> singleRecordReceiveSpan =
|
||||
InstrumentationContext.get(ConsumerRecord.class, SpanContext.class);
|
||||
VirtualField<ConsumerRecord, SpanContext> singleRecordReceiveSpan =
|
||||
VirtualField.find(ConsumerRecord.class, SpanContext.class);
|
||||
|
||||
Iterator<? extends ConsumerRecord<?, ?>> it = records.iterator();
|
||||
// this will forcefully suppress the kafka-clients CONSUMER instrumentation even though
|
||||
|
@ -66,7 +65,7 @@ public class StreamThreadInstrumentation implements TypeInstrumentation {
|
|||
|
||||
while (it.hasNext()) {
|
||||
ConsumerRecord<?, ?> record = it.next();
|
||||
singleRecordReceiveSpan.put(record, receiveSpanContext);
|
||||
singleRecordReceiveSpan.set(record, receiveSpanContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import com.lambdaworks.redis.protocol.AsyncCommand;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -43,7 +43,7 @@ public class LettuceAsyncCommandInstrumentation implements TypeInstrumentation {
|
|||
Context context = Java8BytecodeBridge.currentContext();
|
||||
// get the context that submitted this command and attach it, it will be used to run callbacks
|
||||
context = context.get(LettuceSingletons.COMMAND_CONTEXT_KEY);
|
||||
InstrumentationContext.get(AsyncCommand.class, Context.class).put(asyncCommand, context);
|
||||
VirtualField.find(AsyncCommand.class, Context.class).set(asyncCommand, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,7 @@ public class LettuceAsyncCommandInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void onEnter(
|
||||
@Advice.This AsyncCommand<?, ?, ?> asyncCommand, @Advice.Local("otelScope") Scope scope) {
|
||||
Context context =
|
||||
InstrumentationContext.get(AsyncCommand.class, Context.class).get(asyncCommand);
|
||||
Context context = VirtualField.find(AsyncCommand.class, Context.class).get(asyncCommand);
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import io.lettuce.core.protocol.AsyncCommand;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -43,7 +43,7 @@ public class LettuceAsyncCommandInstrumentation implements TypeInstrumentation {
|
|||
Context context = Java8BytecodeBridge.currentContext();
|
||||
// get the context that submitted this command and attach it, it will be used to run callbacks
|
||||
context = context.get(LettuceSingletons.COMMAND_CONTEXT_KEY);
|
||||
InstrumentationContext.get(AsyncCommand.class, Context.class).put(asyncCommand, context);
|
||||
VirtualField.find(AsyncCommand.class, Context.class).set(asyncCommand, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,7 @@ public class LettuceAsyncCommandInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void onEnter(
|
||||
@Advice.This AsyncCommand<?, ?, ?> asyncCommand, @Advice.Local("otelScope") Scope scope) {
|
||||
Context context =
|
||||
InstrumentationContext.get(AsyncCommand.class, Context.class).get(asyncCommand);
|
||||
Context context = VirtualField.find(AsyncCommand.class, Context.class).get(asyncCommand);
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import io.lettuce.core.protocol.AsyncCommand;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -41,7 +41,7 @@ public class LettuceAsyncCommandInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void saveContext(@Advice.This AsyncCommand<?, ?, ?> asyncCommand) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
InstrumentationContext.get(AsyncCommand.class, Context.class).put(asyncCommand, context);
|
||||
VirtualField.find(AsyncCommand.class, Context.class).set(asyncCommand, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,8 +51,7 @@ public class LettuceAsyncCommandInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void onEnter(
|
||||
@Advice.This AsyncCommand<?, ?, ?> asyncCommand, @Advice.Local("otelScope") Scope scope) {
|
||||
Context context =
|
||||
InstrumentationContext.get(AsyncCommand.class, Context.class).get(asyncCommand);
|
||||
Context context = VirtualField.find(AsyncCommand.class, Context.class).get(asyncCommand);
|
||||
scope = context.makeCurrent();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -43,8 +43,8 @@ public class CategoryInstrumentation implements TypeInstrumentation {
|
|||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void onEnter(@Advice.Argument(0) LoggingEvent event) {
|
||||
InstrumentationContext.get(LoggingEvent.class, Span.class)
|
||||
.put(event, Java8BytecodeBridge.currentSpan());
|
||||
VirtualField.find(LoggingEvent.class, Span.class)
|
||||
.set(event, Java8BytecodeBridge.currentSpan());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import java.util.Hashtable;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -61,7 +61,7 @@ public class LoggingEventInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
Span span = InstrumentationContext.get(LoggingEvent.class, Span.class).get(event);
|
||||
Span span = VirtualField.find(LoggingEvent.class, Span.class).get(event);
|
||||
if (span == null || !span.getSpanContext().isValid()) {
|
||||
return;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class LoggingEventInstrumentation implements TypeInstrumentation {
|
|||
|
||||
// Assume already instrumented event if traceId is present.
|
||||
if (!mdc.containsKey(TRACE_ID)) {
|
||||
Span span = InstrumentationContext.get(LoggingEvent.class, Span.class).get(event);
|
||||
Span span = VirtualField.find(LoggingEvent.class, Span.class).get(event);
|
||||
if (span != null && span.getSpanContext().isValid()) {
|
||||
SpanContext spanContext = span.getSpanContext();
|
||||
mdc.put(TRACE_ID, spanContext.getTraceId());
|
||||
|
|
|
@ -13,9 +13,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -44,8 +44,8 @@ public class LoggerInstrumentation implements TypeInstrumentation {
|
|||
|
||||
@Advice.OnMethodEnter
|
||||
public static void onEnter(@Advice.Argument(value = 0, readOnly = false) ILoggingEvent event) {
|
||||
InstrumentationContext.get(ILoggingEvent.class, Span.class)
|
||||
.put(event, Java8BytecodeBridge.currentSpan());
|
||||
VirtualField.find(ILoggingEvent.class, Span.class)
|
||||
.set(event, Java8BytecodeBridge.currentSpan());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.logback.v1_0.internal.UnionMap;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -63,7 +63,7 @@ public class LoggingEventInstrumentation implements TypeInstrumentation {
|
|||
return;
|
||||
}
|
||||
|
||||
Span currentSpan = InstrumentationContext.get(ILoggingEvent.class, Span.class).get(event);
|
||||
Span currentSpan = VirtualField.find(ILoggingEvent.class, Span.class).get(event);
|
||||
if (currentSpan == null || !currentSpan.getSpanContext().isValid()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -14,10 +14,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -60,11 +59,11 @@ public class ChannelFutureListenerInstrumentation implements TypeInstrumentation
|
|||
return null;
|
||||
}
|
||||
|
||||
ContextStore<Channel, ChannelTraceContext> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
|
||||
VirtualField<Channel, ChannelTraceContext> virtualField =
|
||||
VirtualField.find(Channel.class, ChannelTraceContext.class);
|
||||
|
||||
ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(future.getChannel(), ChannelTraceContext.FACTORY);
|
||||
virtualField.computeIfNull(future.getChannel(), ChannelTraceContext.FACTORY);
|
||||
Context parentContext = channelTraceContext.getConnectionContext();
|
||||
if (parentContext == null) {
|
||||
return null;
|
||||
|
|
|
@ -13,10 +13,9 @@ import static net.bytebuddy.matcher.ElementMatchers.returns;
|
|||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -52,12 +51,12 @@ public class NettyChannelInstrumentation implements TypeInstrumentation {
|
|||
Context context = Java8BytecodeBridge.currentContext();
|
||||
Span span = Java8BytecodeBridge.spanFromContext(context);
|
||||
if (span.getSpanContext().isValid()) {
|
||||
ContextStore<Channel, ChannelTraceContext> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
|
||||
VirtualField<Channel, ChannelTraceContext> virtualField =
|
||||
VirtualField.find(Channel.class, ChannelTraceContext.class);
|
||||
|
||||
if (contextStore.putIfAbsent(channel, ChannelTraceContext.FACTORY).getConnectionContext()
|
||||
if (virtualField.computeIfNull(channel, ChannelTraceContext.FACTORY).getConnectionContext()
|
||||
== null) {
|
||||
contextStore.get(channel).setConnectionContext(context);
|
||||
virtualField.get(channel).setConnectionContext(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,10 @@ import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.client.HttpClientRequestTracingHandler;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.client.HttpClientResponseTracingHandler;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.client.HttpClientTracingHandler;
|
||||
|
@ -69,34 +68,34 @@ public class NettyChannelPipelineInstrumentation implements TypeInstrumentation
|
|||
*/
|
||||
public static class ChannelPipelineAdviceUtil {
|
||||
public static void wrapHandler(
|
||||
ContextStore<Channel, ChannelTraceContext> contextStore,
|
||||
VirtualField<Channel, ChannelTraceContext> virtualField,
|
||||
ChannelPipeline pipeline,
|
||||
ChannelHandler handler) {
|
||||
// Server pipeline handlers
|
||||
if (handler instanceof HttpServerCodec) {
|
||||
pipeline.addLast(
|
||||
HttpServerTracingHandler.class.getName(), new HttpServerTracingHandler(contextStore));
|
||||
HttpServerTracingHandler.class.getName(), new HttpServerTracingHandler(virtualField));
|
||||
} else if (handler instanceof HttpRequestDecoder) {
|
||||
pipeline.addLast(
|
||||
HttpServerRequestTracingHandler.class.getName(),
|
||||
new HttpServerRequestTracingHandler(contextStore));
|
||||
new HttpServerRequestTracingHandler(virtualField));
|
||||
} else if (handler instanceof HttpResponseEncoder) {
|
||||
pipeline.addLast(
|
||||
HttpServerResponseTracingHandler.class.getName(),
|
||||
new HttpServerResponseTracingHandler(contextStore));
|
||||
new HttpServerResponseTracingHandler(virtualField));
|
||||
} else
|
||||
// Client pipeline handlers
|
||||
if (handler instanceof HttpClientCodec) {
|
||||
pipeline.addLast(
|
||||
HttpClientTracingHandler.class.getName(), new HttpClientTracingHandler(contextStore));
|
||||
HttpClientTracingHandler.class.getName(), new HttpClientTracingHandler(virtualField));
|
||||
} else if (handler instanceof HttpRequestEncoder) {
|
||||
pipeline.addLast(
|
||||
HttpClientRequestTracingHandler.class.getName(),
|
||||
new HttpClientRequestTracingHandler(contextStore));
|
||||
new HttpClientRequestTracingHandler(virtualField));
|
||||
} else if (handler instanceof HttpResponseDecoder) {
|
||||
pipeline.addLast(
|
||||
HttpClientResponseTracingHandler.class.getName(),
|
||||
new HttpClientResponseTracingHandler(contextStore));
|
||||
new HttpClientResponseTracingHandler(virtualField));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,10 +127,10 @@ public class NettyChannelPipelineInstrumentation implements TypeInstrumentation
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<Channel, ChannelTraceContext> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
|
||||
VirtualField<Channel, ChannelTraceContext> virtualField =
|
||||
VirtualField.find(Channel.class, ChannelTraceContext.class);
|
||||
|
||||
ChannelPipelineAdviceUtil.wrapHandler(contextStore, pipeline, handler);
|
||||
ChannelPipelineAdviceUtil.wrapHandler(virtualField, pipeline, handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,10 +161,10 @@ public class NettyChannelPipelineInstrumentation implements TypeInstrumentation
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<Channel, ChannelTraceContext> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
|
||||
VirtualField<Channel, ChannelTraceContext> virtualField =
|
||||
VirtualField.find(Channel.class, ChannelTraceContext.class);
|
||||
|
||||
ChannelPipelineAdviceUtil.wrapHandler(contextStore, pipeline, handler);
|
||||
ChannelPipelineAdviceUtil.wrapHandler(virtualField, pipeline, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import static io.opentelemetry.javaagent.instrumentation.netty.v3_8.client.Netty
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.ChannelTraceContext;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
|
@ -19,10 +19,10 @@ import org.jboss.netty.handler.codec.http.HttpRequest;
|
|||
|
||||
public class HttpClientRequestTracingHandler extends SimpleChannelDownstreamHandler {
|
||||
|
||||
private final ContextStore<Channel, ChannelTraceContext> contextStore;
|
||||
private final VirtualField<Channel, ChannelTraceContext> virtualField;
|
||||
|
||||
public HttpClientRequestTracingHandler(ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
this.contextStore = contextStore;
|
||||
public HttpClientRequestTracingHandler(VirtualField<Channel, ChannelTraceContext> virtualField) {
|
||||
this.virtualField = virtualField;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,7 +34,7 @@ public class HttpClientRequestTracingHandler extends SimpleChannelDownstreamHand
|
|||
}
|
||||
|
||||
ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
virtualField.computeIfNull(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
|
||||
Context parentContext = channelTraceContext.getConnectionContext();
|
||||
if (parentContext != null) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import static io.opentelemetry.javaagent.instrumentation.netty.v3_8.client.Netty
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.ChannelTraceContext;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
|
@ -19,16 +19,16 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
|
|||
|
||||
public class HttpClientResponseTracingHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
private final ContextStore<Channel, ChannelTraceContext> contextStore;
|
||||
private final VirtualField<Channel, ChannelTraceContext> virtualField;
|
||||
|
||||
public HttpClientResponseTracingHandler(ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
this.contextStore = contextStore;
|
||||
public HttpClientResponseTracingHandler(VirtualField<Channel, ChannelTraceContext> virtualField) {
|
||||
this.virtualField = virtualField;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent msg) {
|
||||
ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
virtualField.computeIfNull(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
|
||||
Context context = channelTraceContext.getContext();
|
||||
if (context == null) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.netty.v3_8.client;
|
||||
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.ChannelTraceContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.CombinedSimpleChannelHandler;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
|
@ -14,9 +14,9 @@ public class HttpClientTracingHandler
|
|||
extends CombinedSimpleChannelHandler<
|
||||
HttpClientResponseTracingHandler, HttpClientRequestTracingHandler> {
|
||||
|
||||
public HttpClientTracingHandler(ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
public HttpClientTracingHandler(VirtualField<Channel, ChannelTraceContext> virtualField) {
|
||||
super(
|
||||
new HttpClientResponseTracingHandler(contextStore),
|
||||
new HttpClientRequestTracingHandler(contextStore));
|
||||
new HttpClientResponseTracingHandler(virtualField),
|
||||
new HttpClientRequestTracingHandler(virtualField));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import static io.opentelemetry.javaagent.instrumentation.netty.v3_8.server.Netty
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.ChannelTraceContext;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
|
@ -19,16 +19,16 @@ import org.jboss.netty.handler.codec.http.HttpRequest;
|
|||
|
||||
public class HttpServerRequestTracingHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
private final ContextStore<Channel, ChannelTraceContext> contextStore;
|
||||
private final VirtualField<Channel, ChannelTraceContext> virtualField;
|
||||
|
||||
public HttpServerRequestTracingHandler(ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
this.contextStore = contextStore;
|
||||
public HttpServerRequestTracingHandler(VirtualField<Channel, ChannelTraceContext> virtualField) {
|
||||
this.virtualField = virtualField;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) {
|
||||
ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
virtualField.computeIfNull(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
|
||||
Object message = event.getMessage();
|
||||
if (!(message instanceof HttpRequest)) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import static io.opentelemetry.javaagent.instrumentation.netty.v3_8.server.Netty
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.ChannelTraceContext;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
|
@ -19,16 +19,16 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
|
|||
|
||||
public class HttpServerResponseTracingHandler extends SimpleChannelDownstreamHandler {
|
||||
|
||||
private final ContextStore<Channel, ChannelTraceContext> contextStore;
|
||||
private final VirtualField<Channel, ChannelTraceContext> virtualField;
|
||||
|
||||
public HttpServerResponseTracingHandler(ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
this.contextStore = contextStore;
|
||||
public HttpServerResponseTracingHandler(VirtualField<Channel, ChannelTraceContext> virtualField) {
|
||||
this.virtualField = virtualField;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeRequested(ChannelHandlerContext ctx, MessageEvent msg) {
|
||||
ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
virtualField.computeIfNull(ctx.getChannel(), ChannelTraceContext.FACTORY);
|
||||
|
||||
Context context = tracer().getServerContext(channelTraceContext);
|
||||
if (context == null || !(msg.getMessage() instanceof HttpResponse)) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.netty.v3_8.server;
|
||||
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.ChannelTraceContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.CombinedSimpleChannelHandler;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
|
@ -14,9 +14,9 @@ public class HttpServerTracingHandler
|
|||
extends CombinedSimpleChannelHandler<
|
||||
HttpServerRequestTracingHandler, HttpServerResponseTracingHandler> {
|
||||
|
||||
public HttpServerTracingHandler(ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
public HttpServerTracingHandler(VirtualField<Channel, ChannelTraceContext> virtualField) {
|
||||
super(
|
||||
new HttpServerRequestTracingHandler(contextStore),
|
||||
new HttpServerResponseTracingHandler(contextStore));
|
||||
new HttpServerRequestTracingHandler(virtualField),
|
||||
new HttpServerResponseTracingHandler(virtualField));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,10 +15,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
@ -68,12 +67,12 @@ public abstract class AbstractNettyChannelPipelineInstrumentation implements Typ
|
|||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void removeHandler(
|
||||
@Advice.This ChannelPipeline pipeline, @Advice.Argument(0) ChannelHandler handler) {
|
||||
ContextStore<ChannelHandler, ChannelHandler> contextStore =
|
||||
InstrumentationContext.get(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = contextStore.get(handler);
|
||||
VirtualField<ChannelHandler, ChannelHandler> virtualField =
|
||||
VirtualField.find(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = virtualField.get(handler);
|
||||
if (ourHandler != null) {
|
||||
pipeline.remove(ourHandler);
|
||||
contextStore.put(handler, null);
|
||||
virtualField.set(handler, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,12 +88,12 @@ public abstract class AbstractNettyChannelPipelineInstrumentation implements Typ
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<ChannelHandler, ChannelHandler> contextStore =
|
||||
InstrumentationContext.get(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = contextStore.get(handler);
|
||||
VirtualField<ChannelHandler, ChannelHandler> virtualField =
|
||||
VirtualField.find(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = virtualField.get(handler);
|
||||
if (ourHandler != null) {
|
||||
pipeline.remove(ourHandler);
|
||||
contextStore.put(handler, null);
|
||||
virtualField.set(handler, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,12 +110,12 @@ public abstract class AbstractNettyChannelPipelineInstrumentation implements Typ
|
|||
return;
|
||||
}
|
||||
|
||||
ContextStore<ChannelHandler, ChannelHandler> contextStore =
|
||||
InstrumentationContext.get(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = contextStore.get(handler);
|
||||
VirtualField<ChannelHandler, ChannelHandler> virtualField =
|
||||
VirtualField.find(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = virtualField.get(handler);
|
||||
if (ourHandler != null) {
|
||||
pipeline.remove(ourHandler);
|
||||
contextStore.put(handler, null);
|
||||
virtualField.set(handler, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,12 +126,12 @@ public abstract class AbstractNettyChannelPipelineInstrumentation implements Typ
|
|||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void removeHandler(
|
||||
@Advice.This ChannelPipeline pipeline, @Advice.Return ChannelHandler handler) {
|
||||
ContextStore<ChannelHandler, ChannelHandler> contextStore =
|
||||
InstrumentationContext.get(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = contextStore.get(handler);
|
||||
VirtualField<ChannelHandler, ChannelHandler> virtualField =
|
||||
VirtualField.find(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = virtualField.get(handler);
|
||||
if (ourHandler != null) {
|
||||
pipeline.remove(ourHandler);
|
||||
contextStore.put(handler, null);
|
||||
virtualField.set(handler, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,12 +142,12 @@ public abstract class AbstractNettyChannelPipelineInstrumentation implements Typ
|
|||
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||
public static void removeHandler(
|
||||
@Advice.This ChannelPipeline pipeline, @Advice.Return ChannelHandler handler) {
|
||||
ContextStore<ChannelHandler, ChannelHandler> contextStore =
|
||||
InstrumentationContext.get(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = contextStore.get(handler);
|
||||
VirtualField<ChannelHandler, ChannelHandler> virtualField =
|
||||
VirtualField.find(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = virtualField.get(handler);
|
||||
if (ourHandler != null) {
|
||||
pipeline.remove(ourHandler);
|
||||
contextStore.put(handler, null);
|
||||
virtualField.set(handler, null);
|
||||
} else if (handler
|
||||
.getClass()
|
||||
.getName()
|
||||
|
@ -167,9 +166,9 @@ public abstract class AbstractNettyChannelPipelineInstrumentation implements Typ
|
|||
@Advice.Argument(value = 1, readOnly = false) String name) {
|
||||
ChannelHandler handler = pipeline.get(name);
|
||||
if (handler != null) {
|
||||
ContextStore<ChannelHandler, ChannelHandler> contextStore =
|
||||
InstrumentationContext.get(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = contextStore.get(handler);
|
||||
VirtualField<ChannelHandler, ChannelHandler> virtualField =
|
||||
VirtualField.find(ChannelHandler.class, ChannelHandler.class);
|
||||
ChannelHandler ourHandler = virtualField.get(handler);
|
||||
if (ourHandler != null) {
|
||||
name = ourHandler.getClass().getName();
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ import io.opentelemetry.context.Scope;
|
|||
import io.opentelemetry.instrumentation.api.caching.Cache;
|
||||
|
||||
public final class FutureListenerWrappers {
|
||||
// Instead of ContextStore use Cache with weak keys and weak values to store link between original
|
||||
// listener and wrapper. ContextStore works fine when wrapper is stored in a field on original
|
||||
// Instead of VirtualField use Cache with weak keys and weak values to store link between original
|
||||
// listener and wrapper. VirtualField works fine when wrapper is stored in a field on original
|
||||
// listener, but when listener class is a lambda instead of field it gets stored in a map with
|
||||
// weak keys where original listener is key and wrapper is value. As wrapper has a strong
|
||||
// reference to original listener this causes a memory leak.
|
||||
|
|
|
@ -18,9 +18,9 @@ import io.netty.handler.codec.http.HttpRequestEncoder;
|
|||
import io.netty.handler.codec.http.HttpResponseDecoder;
|
||||
import io.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import io.netty.handler.codec.http.HttpServerCodec;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.common.AbstractNettyChannelPipelineInstrumentation;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v4_0.client.HttpClientRequestTracingHandler;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v4_0.client.HttpClientResponseTracingHandler;
|
||||
|
@ -88,8 +88,8 @@ public class NettyChannelPipelineInstrumentation
|
|||
try {
|
||||
pipeline.addLast(ourHandler.getClass().getName(), ourHandler);
|
||||
// associate our handle with original handler so they could be removed together
|
||||
InstrumentationContext.get(ChannelHandler.class, ChannelHandler.class)
|
||||
.putIfAbsent(handler, ourHandler);
|
||||
VirtualField.find(ChannelHandler.class, ChannelHandler.class)
|
||||
.setIfNull(handler, ourHandler);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Prevented adding duplicate handlers.
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ import io.netty.handler.codec.http.HttpRequestEncoder;
|
|||
import io.netty.handler.codec.http.HttpResponseDecoder;
|
||||
import io.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import io.netty.handler.codec.http.HttpServerCodec;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.common.AbstractNettyChannelPipelineInstrumentation;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.HttpClientRequestTracingHandler;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.HttpClientResponseTracingHandler;
|
||||
|
@ -113,8 +113,8 @@ public class NettyChannelPipelineInstrumentation
|
|||
try {
|
||||
pipeline.addAfter(name, ourHandler.getClass().getName(), ourHandler);
|
||||
// associate our handle with original handler so they could be removed together
|
||||
InstrumentationContext.get(ChannelHandler.class, ChannelHandler.class)
|
||||
.putIfAbsent(handler, ourHandler);
|
||||
VirtualField.find(ChannelHandler.class, ChannelHandler.class)
|
||||
.setIfNull(handler, ourHandler);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Prevented adding duplicate handlers.
|
||||
}
|
||||
|
|
|
@ -9,10 +9,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.ExecutorAdviceHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.PropagatedContext;
|
||||
|
@ -40,9 +39,9 @@ public class DispatcherInstrumentation implements TypeInstrumentation {
|
|||
public static PropagatedContext onEnter(@Advice.Argument(0) Runnable call) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, call)) {
|
||||
ContextStore<Runnable, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, call);
|
||||
VirtualField<Runnable, PropagatedContext> virtualField =
|
||||
VirtualField.find(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, call);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -10,10 +10,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.ExecutorAdviceHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.PropagatedContext;
|
||||
|
@ -43,9 +42,9 @@ public class OkHttp3DispatcherInstrumentation implements TypeInstrumentation {
|
|||
public static PropagatedContext onEnter(@Advice.Argument(0) Runnable call) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, call)) {
|
||||
ContextStore<Runnable, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, call);
|
||||
VirtualField<Runnable, PropagatedContext> virtualField =
|
||||
VirtualField.find(Runnable.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, call);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ package io.opentelemetry.instrumentation.okhttp.v3_0;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.caching.Cache;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -20,8 +20,10 @@ import okio.Timeout;
|
|||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
class TracingCallFactory implements Call.Factory {
|
||||
private static final Cache<Request, Context> contextsByRequest =
|
||||
Cache.newBuilder().setWeakKeys().build();
|
||||
|
||||
private static final VirtualField<Request, Context> contextsByRequest =
|
||||
VirtualField.find(Request.class, Context.class);
|
||||
|
||||
// We use old-school reflection here, rather than MethodHandles because Android doesn't support
|
||||
// MethodHandles until API 26.
|
||||
@Nullable private static Method timeoutMethod;
|
||||
|
@ -55,7 +57,7 @@ class TracingCallFactory implements Call.Factory {
|
|||
public Call newCall(Request request) {
|
||||
Context callingContext = Context.current();
|
||||
Request requestCopy = request.newBuilder().build();
|
||||
contextsByRequest.put(requestCopy, callingContext);
|
||||
contextsByRequest.set(requestCopy, callingContext);
|
||||
return new TracingCall(okHttpClient.newCall(requestCopy), callingContext);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.rmi.context;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutput;
|
||||
import java.rmi.NoSuchObjectException;
|
||||
|
@ -48,7 +48,7 @@ public class ContextPropagator {
|
|||
}
|
||||
|
||||
public void attemptToPropagateContext(
|
||||
ContextStore<Connection, Boolean> knownConnections, Connection c, Context context) {
|
||||
VirtualField<Connection, Boolean> knownConnections, Connection c, Context context) {
|
||||
if (checkIfContextCanBePassed(knownConnections, c)) {
|
||||
if (!syntheticCall(c, ContextPayload.from(context), CONTEXT_PAYLOAD_OPERATION_ID)) {
|
||||
logger.debug("Couldn't send context payload");
|
||||
|
@ -57,14 +57,14 @@ public class ContextPropagator {
|
|||
}
|
||||
|
||||
private static boolean checkIfContextCanBePassed(
|
||||
ContextStore<Connection, Boolean> knownConnections, Connection c) {
|
||||
VirtualField<Connection, Boolean> knownConnections, Connection c) {
|
||||
Boolean storedResult = knownConnections.get(c);
|
||||
if (storedResult != null) {
|
||||
return storedResult;
|
||||
}
|
||||
|
||||
boolean result = syntheticCall(c, null, CONTEXT_CHECK_CALL_OPERATION_ID);
|
||||
knownConnections.put(c, result);
|
||||
knownConnections.set(c, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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 java.rmi.server.ObjID;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -79,8 +78,8 @@ public class RmiClientContextInstrumentation implements TypeInstrumentation {
|
|||
}
|
||||
|
||||
// caching if a connection can support enhanced format
|
||||
ContextStore<Connection, Boolean> knownConnections =
|
||||
InstrumentationContext.get(Connection.class, Boolean.class);
|
||||
VirtualField<Connection, Boolean> knownConnections =
|
||||
VirtualField.find(Connection.class, Boolean.class);
|
||||
|
||||
PROPAGATOR.attemptToPropagateContext(knownConnections, c, currentContext);
|
||||
}
|
||||
|
|
|
@ -10,10 +10,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.ExecutorAdviceHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.PropagatedContext;
|
||||
|
@ -54,9 +53,9 @@ public class ScalaForkJoinPoolInstrumentation implements TypeInstrumentation {
|
|||
@Advice.Argument(value = 0, readOnly = false) ForkJoinTask<?> task) {
|
||||
Context context = Java8BytecodeBridge.currentContext();
|
||||
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
|
||||
ContextStore<ForkJoinTask<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(ForkJoinTask.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, contextStore, task);
|
||||
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
|
||||
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ import static net.bytebuddy.matcher.ElementMatchers.not;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.concurrent.PropagatedContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.concurrent.TaskAdviceHelper;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -64,14 +63,14 @@ public class ScalaForkJoinTaskInstrumentation implements TypeInstrumentation {
|
|||
*/
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static Scope enter(@Advice.This ForkJoinTask<?> thiz) {
|
||||
ContextStore<ForkJoinTask<?>, PropagatedContext> contextStore =
|
||||
InstrumentationContext.get(ForkJoinTask.class, PropagatedContext.class);
|
||||
Scope scope = TaskAdviceHelper.makePropagatedContextCurrent(contextStore, thiz);
|
||||
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
|
||||
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
|
||||
Scope scope = TaskAdviceHelper.makePropagatedContextCurrent(virtualField, thiz);
|
||||
if (thiz instanceof Runnable) {
|
||||
ContextStore<Runnable, PropagatedContext> runnableContextStore =
|
||||
InstrumentationContext.get(Runnable.class, PropagatedContext.class);
|
||||
VirtualField<Runnable, PropagatedContext> runnableVirtualField =
|
||||
VirtualField.find(Runnable.class, PropagatedContext.class);
|
||||
Scope newScope =
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(runnableContextStore, (Runnable) thiz);
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(runnableVirtualField, (Runnable) thiz);
|
||||
if (null != newScope) {
|
||||
if (null != scope) {
|
||||
newScope.close();
|
||||
|
@ -81,10 +80,10 @@ public class ScalaForkJoinTaskInstrumentation implements TypeInstrumentation {
|
|||
}
|
||||
}
|
||||
if (thiz instanceof Callable) {
|
||||
ContextStore<Callable<?>, PropagatedContext> callableContextStore =
|
||||
InstrumentationContext.get(Callable.class, PropagatedContext.class);
|
||||
VirtualField<Callable<?>, PropagatedContext> callableVirtualField =
|
||||
VirtualField.find(Callable.class, PropagatedContext.class);
|
||||
Scope newScope =
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(callableContextStore, (Callable<?>) thiz);
|
||||
TaskAdviceHelper.makePropagatedContextCurrent(callableVirtualField, (Callable<?>) thiz);
|
||||
if (null != newScope) {
|
||||
if (null != scope) {
|
||||
newScope.close();
|
||||
|
|
|
@ -12,10 +12,10 @@ import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.servlet.ServletRequestContext;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -60,7 +60,7 @@ public class HttpServletResponseInstrumentation implements TypeInstrumentation {
|
|||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void onEnter(@Advice.This HttpServletResponse response) {
|
||||
InstrumentationContext.get(ServletResponse.class, Integer.class).put(response, 302);
|
||||
VirtualField.find(ServletResponse.class, Integer.class).set(response, 302);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class HttpServletResponseInstrumentation implements TypeInstrumentation {
|
|||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void onEnter(
|
||||
@Advice.This HttpServletResponse response, @Advice.Argument(0) Integer status) {
|
||||
InstrumentationContext.get(ServletResponse.class, Integer.class).put(response, status);
|
||||
VirtualField.find(ServletResponse.class, Integer.class).set(response, status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import static io.opentelemetry.javaagent.instrumentation.servlet.v2_2.Servlet2Si
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.api.servlet.AppServerBridge;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import io.opentelemetry.javaagent.instrumentation.servlet.ServletRequestContext;
|
||||
import javax.servlet.ServletRequest;
|
||||
|
@ -62,7 +62,7 @@ public class Servlet2Advice {
|
|||
scope = context.makeCurrent();
|
||||
// reset response status from previous request
|
||||
// (some servlet containers reuse response objects to reduce memory allocations)
|
||||
InstrumentationContext.get(ServletResponse.class, Integer.class).put(response, null);
|
||||
VirtualField.find(ServletResponse.class, Integer.class).set(response, null);
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
|
@ -94,8 +94,7 @@ public class Servlet2Advice {
|
|||
}
|
||||
|
||||
int responseStatusCode = HttpServletResponse.SC_OK;
|
||||
Integer responseStatus =
|
||||
InstrumentationContext.get(ServletResponse.class, Integer.class).get(response);
|
||||
Integer responseStatus = VirtualField.find(ServletResponse.class, Integer.class).get(response);
|
||||
if (responseStatus != null) {
|
||||
responseStatusCode = responseStatus;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterConfig;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -20,7 +20,7 @@ public class Servlet3FilterInitAdvice {
|
|||
if (filterConfig == null) {
|
||||
return;
|
||||
}
|
||||
InstrumentationContext.get(Filter.class, MappingResolver.Factory.class)
|
||||
.putIfAbsent(filter, new Servlet3FilterMappingResolverFactory(filterConfig));
|
||||
VirtualField.find(Filter.class, MappingResolver.Factory.class)
|
||||
.setIfNull(filter, new Servlet3FilterMappingResolverFactory(filterConfig));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletConfig;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -20,7 +20,7 @@ public class Servlet3InitAdvice {
|
|||
if (servletConfig == null) {
|
||||
return;
|
||||
}
|
||||
InstrumentationContext.get(Servlet.class, MappingResolver.Factory.class)
|
||||
.putIfAbsent(servlet, new Servlet3MappingResolverFactory(servletConfig));
|
||||
VirtualField.find(Servlet.class, MappingResolver.Factory.class)
|
||||
.setIfNull(servlet, new Servlet3MappingResolverFactory(servletConfig));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,10 @@ package io.opentelemetry.javaagent.instrumentation.servlet.v3_0;
|
|||
import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.FILTER;
|
||||
import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.SERVLET;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.servlet.ServletInstrumenterBuilder;
|
||||
import io.opentelemetry.javaagent.instrumentation.servlet.ServletRequestContext;
|
||||
|
@ -39,10 +38,10 @@ public final class Servlet3Singletons {
|
|||
private static final ServletHelper<HttpServletRequest, HttpServletResponse> HELPER =
|
||||
new ServletHelper<>(INSTRUMENTER, Servlet3Accessor.INSTANCE);
|
||||
|
||||
private static final ContextStore<Servlet, MappingResolver.Factory> SERVLET_CONTEXT_STORE =
|
||||
InstrumentationContext.get(Servlet.class, MappingResolver.Factory.class);
|
||||
private static final ContextStore<Filter, MappingResolver.Factory> FILTER_CONTEXT_STORE =
|
||||
InstrumentationContext.get(Filter.class, MappingResolver.Factory.class);
|
||||
private static final VirtualField<Servlet, MappingResolver.Factory> SERVLET_MAPPING_RESOLVER =
|
||||
VirtualField.find(Servlet.class, MappingResolver.Factory.class);
|
||||
private static final VirtualField<Filter, MappingResolver.Factory> FILTER_MAPPING_RESOLVER =
|
||||
VirtualField.find(Filter.class, MappingResolver.Factory.class);
|
||||
|
||||
public static ServletHelper<HttpServletRequest, HttpServletResponse> helper() {
|
||||
return HELPER;
|
||||
|
@ -64,9 +63,9 @@ public final class Servlet3Singletons {
|
|||
private static MappingResolver.Factory getMappingResolverFactory(Object servletOrFilter) {
|
||||
boolean servlet = servletOrFilter instanceof Servlet;
|
||||
if (servlet) {
|
||||
return SERVLET_CONTEXT_STORE.get((Servlet) servletOrFilter);
|
||||
return SERVLET_MAPPING_RESOLVER.get((Servlet) servletOrFilter);
|
||||
} else {
|
||||
return FILTER_CONTEXT_STORE.get((Filter) servletOrFilter);
|
||||
return FILTER_MAPPING_RESOLVER.get((Filter) servletOrFilter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,10 @@ package io.opentelemetry.javaagent.instrumentation.servlet.v5_0;
|
|||
import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.FILTER;
|
||||
import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.SERVLET;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper;
|
||||
import io.opentelemetry.javaagent.instrumentation.servlet.ServletInstrumenterBuilder;
|
||||
import io.opentelemetry.javaagent.instrumentation.servlet.ServletRequestContext;
|
||||
|
@ -23,6 +22,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
public final class Servlet5Singletons {
|
||||
|
||||
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.servlet-5.0";
|
||||
|
||||
private static final Instrumenter<
|
||||
|
@ -39,10 +39,10 @@ public final class Servlet5Singletons {
|
|||
private static final ServletHelper<HttpServletRequest, HttpServletResponse> HELPER =
|
||||
new ServletHelper<>(INSTRUMENTER, Servlet5Accessor.INSTANCE);
|
||||
|
||||
private static final ContextStore<Servlet, MappingResolver.Factory> SERVLET_CONTEXT_STORE =
|
||||
InstrumentationContext.get(Servlet.class, MappingResolver.Factory.class);
|
||||
private static final ContextStore<Filter, MappingResolver.Factory> FILTER_CONTEXT_STORE =
|
||||
InstrumentationContext.get(Filter.class, MappingResolver.Factory.class);
|
||||
private static final VirtualField<Servlet, MappingResolver.Factory> SERVLET_MAPPING_RESOLVER =
|
||||
VirtualField.find(Servlet.class, MappingResolver.Factory.class);
|
||||
private static final VirtualField<Filter, MappingResolver.Factory> FILTER_MAPPING_RESOLVER =
|
||||
VirtualField.find(Filter.class, MappingResolver.Factory.class);
|
||||
|
||||
public static ServletHelper<HttpServletRequest, HttpServletResponse> helper() {
|
||||
return HELPER;
|
||||
|
@ -64,9 +64,9 @@ public final class Servlet5Singletons {
|
|||
private static MappingResolver.Factory getMappingResolverFactory(Object servletOrFilter) {
|
||||
boolean servlet = servletOrFilter instanceof Servlet;
|
||||
if (servlet) {
|
||||
return SERVLET_CONTEXT_STORE.get((Servlet) servletOrFilter);
|
||||
return SERVLET_MAPPING_RESOLVER.get((Servlet) servletOrFilter);
|
||||
} else {
|
||||
return FILTER_CONTEXT_STORE.get((Filter) servletOrFilter);
|
||||
return FILTER_MAPPING_RESOLVER.get((Filter) servletOrFilter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.servlet.v5_0.service;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import jakarta.servlet.Filter;
|
||||
import jakarta.servlet.FilterConfig;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -20,7 +20,7 @@ public class JakartaServletFilterInitAdvice {
|
|||
if (filterConfig == null) {
|
||||
return;
|
||||
}
|
||||
InstrumentationContext.get(Filter.class, MappingResolver.Factory.class)
|
||||
.putIfAbsent(filter, new JakartaServletFilterMappingResolverFactory(filterConfig));
|
||||
VirtualField.find(Filter.class, MappingResolver.Factory.class)
|
||||
.setIfNull(filter, new JakartaServletFilterMappingResolverFactory(filterConfig));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.servlet.v5_0.service;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import jakarta.servlet.Servlet;
|
||||
import jakarta.servlet.ServletConfig;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -20,7 +20,7 @@ public class JakartaServletInitAdvice {
|
|||
if (servletConfig == null) {
|
||||
return;
|
||||
}
|
||||
InstrumentationContext.get(Servlet.class, MappingResolver.Factory.class)
|
||||
.putIfAbsent(servlet, new JakartaServletMappingResolverFactory(servletConfig));
|
||||
VirtualField.find(Servlet.class, MappingResolver.Factory.class)
|
||||
.setIfNull(servlet, new JakartaServletMappingResolverFactory(servletConfig));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.field.VirtualField;
|
||||
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.spring.batch.ContextAndScope;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -44,10 +43,10 @@ public class StepBuilderInstrumentation implements TypeInstrumentation {
|
|||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void onEnter(@Advice.This AbstractTaskletStepBuilder<?> stepBuilder) {
|
||||
ContextStore<ChunkContext, ContextAndScope> chunkExecutionContextStore =
|
||||
InstrumentationContext.get(ChunkContext.class, ContextAndScope.class);
|
||||
VirtualField<ChunkContext, ContextAndScope> chunkExecutionVirtualField =
|
||||
VirtualField.find(ChunkContext.class, ContextAndScope.class);
|
||||
stepBuilder.listener(
|
||||
new TracingChunkExecutionListener(chunkExecutionContextStore, stepBuilder.getClass()));
|
||||
new TracingChunkExecutionListener(chunkExecutionVirtualField, stepBuilder.getClass()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue