Skip to content

Commit

Permalink
Hikaricp: Avoid registering duplicate metrics (open-telemetry#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
2 people authored and LironKS committed Dec 4, 2022
1 parent 0510c92 commit 8f7c78e
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 8f7c78e

Please sign in to comment.