Search in sources :

Example 1 with Transaction

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;
    }
}
Also used : Transaction(com.newrelic.api.agent.Transaction) ResponseWrapper(com.agent.instrumentation.akka.http.ResponseWrapper) Trace(com.newrelic.api.agent.Trace)

Example 2 with Transaction

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;
    }
}
Also used : Transaction(com.newrelic.api.agent.Transaction) GrpcResponse(com.nr.agent.instrumentation.grpc.GrpcResponse) Trace(com.newrelic.api.agent.Trace)

Example 3 with Transaction

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);
    }
}
Also used : ExitTracer(com.newrelic.agent.bridge.ExitTracer) NoOpTransaction(com.newrelic.agent.bridge.NoOpTransaction) Transaction(com.newrelic.api.agent.Transaction) InstrumentationImpl(com.newrelic.agent.instrumentation.InstrumentationImpl) TransactionApiImpl(com.newrelic.agent.TransactionApiImpl) NoOpTransaction(com.newrelic.agent.bridge.NoOpTransaction) Trace(com.newrelic.api.agent.Trace)

Example 4 with Transaction

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");
    }
}
Also used : Transaction(com.newrelic.api.agent.Transaction) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 5 with Transaction

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();
}
Also used : PublishResult(com.amazonaws.services.sns.model.PublishResult) Transaction(com.newrelic.api.agent.Transaction) PublishRequest(com.amazonaws.services.sns.model.PublishRequest) Segment(com.newrelic.api.agent.Segment) Trace(com.newrelic.api.agent.Trace)

Aggregations

Transaction (com.newrelic.api.agent.Transaction)8 Trace (com.newrelic.api.agent.Trace)5 Segment (com.newrelic.api.agent.Segment)2 GrpcResponse (com.nr.agent.instrumentation.grpc.GrpcResponse)2 URISyntaxException (java.net.URISyntaxException)2 ResponseWrapper (com.agent.instrumentation.akka.http.ResponseWrapper)1 PublishRequest (com.amazonaws.services.sns.model.PublishRequest)1 PublishResult (com.amazonaws.services.sns.model.PublishResult)1 TransactionApiImpl (com.newrelic.agent.TransactionApiImpl)1 ExitTracer (com.newrelic.agent.bridge.ExitTracer)1 NoOpTransaction (com.newrelic.agent.bridge.NoOpTransaction)1 InstrumentationImpl (com.newrelic.agent.instrumentation.InstrumentationImpl)1 MessageProduceParameters (com.newrelic.api.agent.MessageProduceParameters)1 Metadata (io.grpc.Metadata)1 IOException (java.io.IOException)1 URI (java.net.URI)1