Skip to content

Commit

Permalink
[NR-249812] Support For Netty Reactor Server (#220)
Browse files Browse the repository at this point in the history
[FIX] Events generation for Netty Reactor Server

Co-authored-by: Lovesh Baya <[email protected]>
  • Loading branch information
IshikaDawda and lovesh-ap authored May 10, 2024
1 parent 2b3088a commit ad8439a
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
import java.net.HttpURLConnection;
import java.net.Socket;
import java.net.URL;
import java.time.Instant;
import java.util.ArrayList;
Expand Down Expand Up @@ -350,15 +349,30 @@ private void logIfIastScanForFirstTime(K2RequestIdentifier fuzzRequestIdentifier
}

private static boolean checkIfNRGeneratedEvent(AbstractOperation operation) {
boolean isNettyReactor = false, isNRGeneratedEvent = false;
for (int i = 1, j = 0; i < operation.getStackTrace().length; i++) {
if(StringUtils.equalsAny(operation.getStackTrace()[i].getClassName(), "com.nr.instrumentation.TokenLinkingSubscriber", "com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber")){
isNettyReactor = true;
continue;
}

// Only remove consecutive top com.newrelic and com.nr. elements from stack.
if (i - 1 == j && StringUtils.startsWithAny(operation.getStackTrace()[i].getClassName(), "com.newrelic.", "com.nr.")) {
j++;
} else if (StringUtils.startsWithAny(operation.getStackTrace()[i].getClassName(), "com.newrelic.", "com.nr.")) {
return true;
isNRGeneratedEvent = true;
}
}
return false;
if (isNettyReactor) {
operation.setStackTrace(removeNettyReactorLinkingTraces(operation.getStackTrace()));
}
return isNRGeneratedEvent;
}

private static StackTraceElement[] removeNettyReactorLinkingTraces(StackTraceElement[] stackTrace) {
return Arrays.stream(stackTrace).filter(stackTraceElement ->
!StringUtils.equalsAny(stackTraceElement.getClassName(), "com.nr.instrumentation.TokenLinkingSubscriber", "com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber")
).toArray(StackTraceElement[]::new);
}

private static boolean needToGenerateEvent(String apiID) {
Expand Down

0 comments on commit ad8439a

Please sign in to comment.