Log a warning when GlobalOpenTelemetry#resetForTest() is called (#6212)

This commit is contained in:
Mateusz Rzeszutek 2022-06-24 22:38:38 +02:00 committed by GitHub
parent dc6833afab
commit 8a83844245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -45,6 +45,9 @@ public class OpenTelemetryInstrumentation implements TypeInstrumentation {
.and(takesArguments(1))
.and(takesArgument(0, named("application.io.opentelemetry.api.OpenTelemetry"))),
OpenTelemetryInstrumentation.class.getName() + "$SetAdvice");
transformer.applyAdviceToMethod(
isMethod().and(isStatic()).and(named("resetForTest")).and(takesArguments(0)),
OpenTelemetryInstrumentation.class.getName() + "$ResetForTestAdvice");
}
@SuppressWarnings("unused")
@ -77,4 +80,19 @@ public class OpenTelemetryInstrumentation implements TypeInstrumentation {
new Throwable());
}
}
@SuppressWarnings("unused")
public static class ResetForTestAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter() {
Logger.getLogger(application.io.opentelemetry.api.GlobalOpenTelemetry.class.getName())
.log(
WARNING,
"You are currently using the OpenTelemetry Instrumentation Java Agent;"
+ " all GlobalOpenTelemetry.resetForTest calls are ignored - the agent provides"
+ " the global OpenTelemetry object used by your application.",
new Throwable());
}
}
}