Skip to content

Commit

Permalink
Hikaricp: Avoid registering duplicate metrics (#6325)
Browse files Browse the repository at this point in the history
* Hikaricp: Avoid registering duplicate metrics

* Update instrumentation/hikaricp-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/hikaricp/HikariPoolInstrumentation.java

Co-authored-by: Trask Stalnaker <[email protected]>

* spotless

* Trigger build

Co-authored-by: Trask Stalnaker <[email protected]>
  • Loading branch information
laurit and trask authored Jul 15, 2022
1 parent 07f7876 commit b3e543d
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ public static class SetMetricsTrackerFactoryAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(
@Advice.Argument(value = 0, readOnly = false) MetricsTrackerFactory userMetricsTracker) {

@Advice.Argument(value = 0, readOnly = false) MetricsTrackerFactory userMetricsTracker,
@Advice.FieldValue(value = "metricsTracker") AutoCloseable existingMetricsTracker)
throws Exception {

if (existingMetricsTracker != null) {
// we call close on the existing metrics tracker in case it's our wrapper, so that our
// wrapper will unregister itself and won't keep recording metrics which leads to warnings
// about duplicate metrics
existingMetricsTracker.close();
}
userMetricsTracker = HikariSingletons.createMetricsTrackerFactory(userMetricsTracker);
}
}
Expand Down

0 comments on commit b3e543d

Please sign in to comment.