Skip to content

Commit

Permalink
Log a warning when GlobalOpenTelemetry#resetForTest() is called (#6212)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Jun 24, 2022
1 parent dc6833a commit 8a83844
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public void transform(TypeTransformer transformer) {
.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")
Expand Down Expand Up @@ -77,4 +80,19 @@ public static void onEnter() {
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());
}
}
}

0 comments on commit 8a83844

Please sign in to comment.