From 5478373745dffe8c4ec066c2bca1f20d80f3f57f Mon Sep 17 00:00:00 2001 From: jiwen624 Date: Thu, 15 Sep 2022 18:32:11 -0700 Subject: [PATCH 1/3] decrease stack depth in early return branch --- .../instrumentation/AoPreparedStatementInstrumentation.java | 2 ++ .../instrumentation/AoStatementInstrumentation.java | 1 + 2 files changed, 3 insertions(+) diff --git a/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoPreparedStatementInstrumentation.java b/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoPreparedStatementInstrumentation.java index d0621fca..c0f7a1ab 100644 --- a/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoPreparedStatementInstrumentation.java +++ b/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoPreparedStatementInstrumentation.java @@ -58,6 +58,7 @@ public static void onEnter( // is called - the first recursive Statement call is just skipped and we do not create a span // for it if (CallDepth.forClass(Statement.class).getAndIncrement() != 0) { //only report back when depth is one to avoid duplications + CallDepth.forClass(Statement.class).decrementAndGet(); return; } QueryArgsCollector.collect(currentContext(), index, value); @@ -92,6 +93,7 @@ public static void onEnter( public static void onExit( @Advice.Thrown Throwable throwable) { if (CallDepth.forClass(Statement.class).getAndIncrement() != 1) { //only report back when depth is one to avoid duplications + CallDepth.forClass(Statement.class).decrementAndGet(); return; } QueryArgsCollector.maybeAttach(currentContext()); diff --git a/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoStatementInstrumentation.java b/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoStatementInstrumentation.java index 3764365c..e1f09eec 100644 --- a/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoStatementInstrumentation.java +++ b/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoStatementInstrumentation.java @@ -48,6 +48,7 @@ public static class StatementAdvice { @Advice.OnMethodEnter public static void onEnter(@Advice.Argument(value = 0, readOnly = false) String sql) { if (CallDepth.forClass(Statement.class).getAndIncrement() != 1) { //only report back when depth is one to avoid duplications + CallDepth.forClass(Statement.class).decrementAndGet(); return; } sql = TraceContextInjector.inject(currentContext(), sql); From be48ce6694dc149e0e5dccd506f7d78d2029a485 Mon Sep 17 00:00:00 2001 From: jiwen624 Date: Mon, 19 Sep 2022 10:24:03 -0700 Subject: [PATCH 2/3] add comments and bump up version --- build.gradle | 2 +- .../instrumentation/AoPreparedStatementInstrumentation.java | 2 ++ .../instrumentation/AoStatementInstrumentation.java | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3461c643..936b28e5 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ subprojects { bytebuddy : "1.12.6", guava : "30.1-jre", appopticsCore : "7.7.1", - agent : "0.12.1" // the custom distro agent version + agent : "0.12.2" // the custom distro agent version ] versions.appopticsMetrics = "${versions.appopticsCore}" // they share the same version now versions.opentelemetryAlpha = "${versions.opentelemetry}-alpha" diff --git a/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoPreparedStatementInstrumentation.java b/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoPreparedStatementInstrumentation.java index c0f7a1ab..fa377dba 100644 --- a/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoPreparedStatementInstrumentation.java +++ b/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoPreparedStatementInstrumentation.java @@ -93,6 +93,8 @@ public static void onEnter( public static void onExit( @Advice.Thrown Throwable throwable) { if (CallDepth.forClass(Statement.class).getAndIncrement() != 1) { //only report back when depth is one to avoid duplications + // Note that we need to decrement the call depth counter at every branch, otherwise the JDBC instrumentation of the + // Otel agent will break. CallDepth.forClass(Statement.class).decrementAndGet(); return; } diff --git a/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoStatementInstrumentation.java b/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoStatementInstrumentation.java index e1f09eec..e285d0fb 100644 --- a/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoStatementInstrumentation.java +++ b/instrumentation/jdbc/src/main/java/com/appoptics/opentelemetry/instrumentation/AoStatementInstrumentation.java @@ -48,6 +48,8 @@ public static class StatementAdvice { @Advice.OnMethodEnter public static void onEnter(@Advice.Argument(value = 0, readOnly = false) String sql) { if (CallDepth.forClass(Statement.class).getAndIncrement() != 1) { //only report back when depth is one to avoid duplications + // Note that we need to decrement the call depth counter at every branch, otherwise the JDBC instrumentation of the + // Otel agent will break. CallDepth.forClass(Statement.class).decrementAndGet(); return; } From e0475d6ec07afa3273879c77a0704b8ee649e062 Mon Sep 17 00:00:00 2001 From: jiwen624 Date: Mon, 19 Sep 2022 11:54:11 -0700 Subject: [PATCH 3/3] follow a newer version to avoid conflicts --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 936b28e5..3461c643 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ subprojects { bytebuddy : "1.12.6", guava : "30.1-jre", appopticsCore : "7.7.1", - agent : "0.12.2" // the custom distro agent version + agent : "0.12.1" // the custom distro agent version ] versions.appopticsMetrics = "${versions.appopticsCore}" // they share the same version now versions.opentelemetryAlpha = "${versions.opentelemetry}-alpha"