Class FieldBackedProvider
- java.lang.Object
-
- io.opentelemetry.javaagent.tooling.context.FieldBackedProvider
-
- All Implemented Interfaces:
InstrumentationContextProvider
public class FieldBackedProvider extends Object implements InstrumentationContextProvider
InstrumentationContextProvider which stores context in a field that is injected into a class and falls back to global map if field was not injected.This is accomplished by
- Injecting a Dynamic Interface that provides getter and setter for context field
- Applying Dynamic Interface to a type needing context, implementing interface methods and adding context storage field
- Injecting a Dynamic Class created from
FieldBackedProvider.ContextStoreImplementationTemplateto use injected field or fall back to a static map - Rewriting calls to the context-store to access the specific dynamic
FieldBackedProvider.ContextStoreImplementationTemplate
Example:
InstrumentationContext.get(Runnable.class, RunnableState.class)")
is rewritten to:
FieldBackedProvider$ContextStore$Runnable$RunnableState12345.getContextStore(runnableRunnable.class, RunnableState.class)
-
-
Constructor Summary
Constructors Constructor Description FieldBackedProvider(Class<?> instrumenterClass, Map<String,String> contextStore)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description net.bytebuddy.agent.builder.AgentBuilder.Identified.ExtendableadditionalInstrumentation(net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable builder)Hook to define additional instrumentation.net.bytebuddy.agent.builder.AgentBuilder.Identified.ExtendableinstrumentationTransformer(net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable builder)Hook to provide an agent builder after advice is applied to target class.static voidresetContextMatchers()Clear set that prevents multiple matchers for same context class.
-
-
-
Method Detail
-
instrumentationTransformer
public net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable instrumentationTransformer(net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable builder)
Description copied from interface:InstrumentationContextProviderHook to provide an agent builder after advice is applied to target class. Used to implement context-store lookup.- Specified by:
instrumentationTransformerin interfaceInstrumentationContextProvider
-
resetContextMatchers
public static void resetContextMatchers()
Clear set that prevents multiple matchers for same context class.
-
additionalInstrumentation
public net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable additionalInstrumentation(net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable builder)
Description copied from interface:InstrumentationContextProviderHook to define additional instrumentation. Run at instrumentation advice is hooked up.- Specified by:
additionalInstrumentationin interfaceInstrumentationContextProvider
-
-