Skip to content

Instantly share code, notes, and snippets.

@lmolkova
Created October 22, 2021 19:50
Show Gist options
  • Save lmolkova/70f4f6118d93100f54c739469d30e817 to your computer and use it in GitHub Desktop.
Save lmolkova/70f4f6118d93100f54c739469d30e817 to your computer and use it in GitHub Desktop.
private static final Method SET_REACTOR_CONTEXT_METHOD = getStoreContextMethod();
static Method getStoreContextMethod() {
try {
Class<?> contextPropagationOperatorClass = Class.forName("io.opentelemetry.javaagent.shaded.instrumentation.reactor.ContextPropagationOperator");
Class<?> oteContextShaded = Class.forName("io.opentelemetry.javaagent.shaded.io.opentelemetry.context.Context");
if (contextPropagationOperatorClass != null && oteContextShaded != null) {
Method storeMethod = contextPropagationOperatorClass.getDeclaredMethod("storeOpenTelemetryContext", reactor.util.context.Context.class, oteContextShaded);
if (storeMethod.getReturnType() == reactor.util.context.Context.class) {
return storeMethod;
}
} catch (Throwable t) {
//
}
return null;
}
if (SET_REACTOR_CONTEXT_METHOD != null) {
try {
this.context = (reactor.util.context.Context) SET_REACTOR_CONTEXT_METHOD.invoke(null, reactorContext, traceContext);
} catch (IllegalAccessException | InvocationTargetException e) {
// THROWS! because traceContext I use is io.otel.context.Context and this method wants shaded context
LOGGER.info("ContextPropagationOperator.storeOpenTelemetryContext threw");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment