Skip to content

Commit

Permalink
Merge pull request #59 from appoptics/NH-21584-jdbc-instrumentation-fix
Browse files Browse the repository at this point in the history
NH-21584: Decrease stack depth in early return branch
  • Loading branch information
jiwen624 authored Sep 22, 2022
2 parents 6349f9d + e0475d6 commit 7b40e7c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -92,6 +93,9 @@ 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;
}
QueryArgsCollector.maybeAttach(currentContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ 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;
}
sql = TraceContextInjector.inject(currentContext(), sql);
Expand Down

0 comments on commit 7b40e7c

Please sign in to comment.