use of com.newrelic.api.agent.Transaction in project newrelic-java-agent by newrelic.
the class AkkaHttpMarshallerMapper method apply.
@Override
@Trace(async = true)
public HttpResponse apply(HttpResponse httpResponse) {
try {
if (token != null) {
token.linkAndExpire();
}
ResponseWrapper responseWrapper = new ResponseWrapper(httpResponse);
Transaction transaction = NewRelic.getAgent().getTransaction();
transaction.setWebResponse(responseWrapper);
transaction.addOutboundResponseHeaders();
transaction.markResponseSent();
return responseWrapper.response();
} catch (Throwable t) {
AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
return httpResponse;
}
}
use of com.newrelic.api.agent.Transaction in project newrelic-java-agent by newrelic.
the class ServerStream_Instrumentation method close.
@Trace(async = true)
public void close(Status status, Metadata trailers) {
if (token != null) {
token.link();
Transaction transaction = NewRelic.getAgent().getTransaction();
transaction.setWebResponse(new GrpcResponse(status, trailers));
transaction.addOutboundResponseHeaders();
transaction.markResponseSent();
}
if (status != null) {
NewRelic.addCustomParameter("response.status", status.getCode().value());
if (GrpcConfig.errorsEnabled && status.getCause() != null) {
// If an error occurred during the close of this server call we should record it
NewRelic.noticeError(status.getCause());
}
}
Weaver.callOriginal();
if (token != null) {
token.expire();
token = null;
}
}
use of com.newrelic.api.agent.Transaction in project newrelic-java-agent by newrelic.
the class CircuitBreakerServiceFunctionalTest method aTransaction.
@Trace(dispatcher = true)
private void aTransaction(boolean breakerTripped) {
Transaction transaction = NewRelic.getAgent().getTransaction();
InstrumentationImpl impl = new InstrumentationImpl(Agent.LOG);
if (breakerTripped) {
ExitTracer createdTracer = impl.createTracer(null, 0, "metricName", TracerFlags.DISPATCHER);
Assert.assertNull(createdTracer);
Assert.assertTrue(transaction instanceof NoOpTransaction);
} else {
Assert.assertTrue(transaction instanceof TransactionApiImpl);
}
}
use of com.newrelic.api.agent.Transaction in project newrelic-java-agent by newrelic.
the class HttpTestServerImpl method serveInternal.
private Response serveInternal(IHTTPSession session) {
NewRelic.addCustomParameter("server.port", this.port);
final Map<String, String> incomingHeaders = session.getHeaders();
if (incomingHeaders.containsKey(SLEEP_MS_HEADER_KEY)) {
try {
long input = Long.parseLong(incomingHeaders.remove(SLEEP_MS_HEADER_KEY));
Thread.sleep(input);
} catch (Exception e) {
e.printStackTrace();
}
}
boolean doCat = true;
if (incomingHeaders.containsKey(DO_CAT)) {
try {
doCat = Boolean.parseBoolean(incomingHeaders.remove(DO_CAT));
} catch (Exception e) {
e.printStackTrace();
}
}
if (Boolean.parseBoolean(incomingHeaders.get(DO_BETTER_CAT)) && AgentBridge.getAgent().getTransaction(false) != null) {
String tracePayload = incomingHeaders.get(HeadersUtil.NEWRELIC_TRACE_HEADER);
if (tracePayload != null) {
NewRelic.getAgent().getTransaction().acceptDistributedTracePayload(tracePayload);
}
}
if (doCat && AgentBridge.getAgent().getTransaction(false) != null) {
Transaction tx = NewRelic.getAgent().getTransaction();
tx.setTransactionName(TransactionNamePriority.CUSTOM_HIGH, true, "Custom", "ExternalHTTPServer");
tx.setWebRequest(new RequestWrapper(session));
Response res = newFixedLengthResponse("<html><body><h1>SuccessfulResponse</h1>\n</body></html>\n");
// outbound cat
com.newrelic.agent.Transaction.getTransaction().getCrossProcessTransactionState().processOutboundResponseHeaders(new OutboundWrapper(res), -1L);
return res;
} else {
return newFixedLengthResponse("<html><body><h1>SuccessfulResponse</h1>\n</body></html>\n");
}
}
use of com.newrelic.api.agent.Transaction in project newrelic-java-agent by newrelic.
the class AmazonSNSAsync_Instrumentation method publishAsync.
@Trace
public Future<PublishResult> publishAsync(final PublishRequest request, AsyncHandler<PublishRequest, PublishResult> asyncHandler) {
final AsyncHandler<PublishRequest, PublishResult> originalHandler = asyncHandler;
final Transaction transaction = NewRelic.getAgent().getTransaction();
final Segment segment = startSegment(request, transaction);
// replace the handler with ours that wraps the original (which might be null)
asyncHandler = new AsyncHandler<PublishRequest, PublishResult>() {
@Override
public void onError(Exception exception) {
try {
if (originalHandler != null) {
originalHandler.onError(exception);
}
} finally {
segment.end();
}
}
@Override
public void onSuccess(PublishRequest request, PublishResult publishResult) {
try {
if (originalHandler != null) {
originalHandler.onSuccess(request, publishResult);
}
} finally {
segment.end();
}
}
};
return Weaver.callOriginal();
}
Aggregations