use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.
the class TransactionPropagationTest method testEmptyFluxOnComplete.
@Test
public void testEmptyFluxOnComplete() {
AtomicBoolean hadTransaction = new AtomicBoolean();
inTransaction(() -> {
Token token = createToken();
Flux.empty().subscribeOn(Schedulers.elastic()).doOnComplete(() -> checkTransaction(hadTransaction)).subscriberContext(with(token)).blockFirst();
token.expire();
});
assertCapturedData(hadTransaction);
}
use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.
the class TransactionPropagationTest method testMonoRetryOnSuccess.
@Test
public void testMonoRetryOnSuccess() {
AtomicBoolean hadTransaction = new AtomicBoolean();
inTransaction(() -> {
Token token = createToken();
AtomicBoolean firstCall = new AtomicBoolean(true);
Mono.create(monoSink -> inAnotherThread(() -> {
if (firstCall.getAndSet(false))
monoSink.error(new RuntimeException("failing the first call"));
else
monoSink.success(A_VALUE);
})).doOnSuccess(v -> checkTransaction(hadTransaction)).retry(2).subscriberContext(with(token)).block();
token.expire();
});
assertCapturedData(hadTransaction);
}
use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.
the class AbstractServerResponse_Instrumentation method writeTo.
public Mono<Void> writeTo(ServerWebExchange exchange, ServerResponse.Context context) {
final Token token = (Token) exchange.getAttribute(Util.NR_TOKEN);
if (token != null) {
final Object pathPattern = exchange.getAttribute(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
String txnName = exchange.getAttribute(Util.NR_TXN_NAME);
if (pathPattern != null) {
// If the pattern string provided by Spring is available we should use it
if (pathPattern instanceof PathPattern) {
txnName = ((PathPattern) pathPattern).getPatternString();
} else if (pathPattern instanceof String) {
txnName = (String) pathPattern;
}
}
final String methodName = " (" + exchange.getRequest().getMethod() + ")";
if (txnName != null && statusCode != 404) {
final String txnNameWithMethod = removeTrailingSlash(txnName) + methodName;
token.getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, true, "Spring", txnNameWithMethod);
} else {
token.getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, true, "Spring", "Unknown Route" + methodName);
}
}
return Weaver.callOriginal();
}
use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.
the class HttpWebHandlerAdapter_Instrumentation method createExchange.
protected ServerWebExchange createExchange(ServerHttpRequest request, ServerHttpResponse response) {
final com.newrelic.agent.bridge.Transaction transaction = AgentBridge.getAgent().getTransaction(false);
final Token token = transaction == null ? null : transaction.getToken();
if (response instanceof ReactiveHttpOutputMessage_Instrumentation) {
ReactiveHttpOutputMessage_Instrumentation reactiveResponse = (ReactiveHttpOutputMessage_Instrumentation) response;
reactiveResponse.token = token;
}
ServerWebExchange exchange = Weaver.callOriginal();
if (token != null) {
exchange.getAttributes().put(Util.NR_TOKEN, token);
}
return exchange;
}
use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.
the class ServerResponse_Instrumentation method writeTo.
public Mono<Void> writeTo(ServerWebExchange exchange, ServerResponse.Context context) {
final Token token = (Token) exchange.getAttribute(Util.NR_TOKEN);
if (token != null) {
final PathPattern pathPattern = exchange.getAttribute("org.springframework.web.reactive.function.server.RouterFunctions.matchingPattern");
String txnName = exchange.getAttribute(Util.NR_TXN_NAME);
if (pathPattern != null) {
// If the pattern string provided by Spring is available we should use it
txnName = pathPattern.getPatternString();
}
final String methodName = " (" + exchange.getRequest().getMethod() + ")";
if (txnName != null && statusCode().value() != 404) {
final String txnNameWithMethod = removeTrailingSlash(txnName) + methodName;
token.getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, true, "Spring", txnNameWithMethod);
} else {
token.getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, true, "Spring", "Unknown Route" + methodName);
}
}
return Weaver.callOriginal();
}
Aggregations