Search in sources :

Example 1 with Segment

use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.

the class NewRelicCommandListener method tryFinishEvent.

private void tryFinishEvent() {
    try {
        Segment tracerEvent = holder.get();
        if (tracerEvent != null) {
            tracerEvent.end();
            holder.remove();
        }
    } catch (Throwable t) {
        AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
    }
}
Also used : Segment(com.newrelic.api.agent.Segment)

Example 2 with Segment

use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.

the class NewRelicCommandListener method commandStarted.

@Override
public void commandStarted(CommandStartedEvent event) {
    try {
        Segment tracer = NewRelic.getAgent().getTransaction().startSegment(null);
        if (tracer != null) {
            holder.set(tracer);
            String collectionName = getCollectionName(event);
            String operationName = event.getCommandName().intern();
            ServerAddress address = event.getConnectionDescription().getServerAddress();
            DatastoreParameters params = DatastoreParameters.product(DatastoreVendor.MongoDB.name()).collection(collectionName).operation(operationName).instance(address.getHost(), address.getPort()).databaseName(event.getDatabaseName()).build();
            tracer.reportAsExternal(params);
        }
    } catch (Throwable t) {
        AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
    }
}
Also used : DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) ServerAddress(com.mongodb.ServerAddress) BsonString(org.bson.BsonString) Segment(com.newrelic.api.agent.Segment)

Example 3 with Segment

use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.

the class AsyncHttpProvider method execute.

public <T> ListenableFuture<T> execute(Request request, NRAsyncHandler<T> handler) {
    URI uri = null;
    try {
        uri = new URI(request.getUrl());
        String scheme = uri.getScheme();
        // only instrument HTTP or HTTPS calls
        if ((scheme == null || scheme.equals("http") || scheme.equals("https")) && null != AgentBridge.getAgent().getTransaction(false) && AgentBridge.getAgent().getTransaction().isStarted()) {
            Segment segment = NewRelic.getAgent().getTransaction().startSegment("execute");
            segment.addOutboundRequestHeaders(new OutboundWrapper(request));
            handler.uri = uri;
            handler.segment = segment;
        }
    } catch (URISyntaxException uriSyntaxException) {
    // if Java can't parse the URI, ning won't be able to either
    // let's just proceed without instrumentation
    }
    // proceed
    return Weaver.callOriginal();
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Segment(com.newrelic.api.agent.Segment) OutboundWrapper(com.nr.agent.instrumentation.asynchttpclient.OutboundWrapper)

Example 4 with Segment

use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.

the class JavaPlayWSUtils method finish.

public static CompletionStage<? extends StandaloneWSResponse> finish(Segment segment, String procedure, StandaloneWSRequest request, CompletionStage<? extends StandaloneWSResponse> response) {
    if (segment == null) {
        return response;
    }
    final Segment localSegment = segment;
    localSegment.setMetricName("External", "PlayWS", procedure);
    try {
        response = response.whenComplete(new BiConsumer<StandaloneWSResponse, Throwable>() {

            @Override
            public void accept(StandaloneWSResponse standaloneWSResponse, Throwable throwable) {
                if (throwable != null) {
                    try {
                        localSegment.reportAsExternal(HttpParameters.library("PlayWS").uri(new URL(request.getUrl()).toURI()).procedure(procedure).noInboundHeaders().build());
                        localSegment.end();
                    } catch (Exception e) {
                    }
                } else {
                    try {
                        localSegment.reportAsExternal(HttpParameters.library("PlayWS").uri(new URL(request.getUrl()).toURI()).procedure(procedure).inboundHeaders(new JavaInboundWrapper(standaloneWSResponse)).build());
                        localSegment.end();
                    } catch (Exception e) {
                    }
                }
            }
        });
    } catch (Throwable t) {
        AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
        try {
            localSegment.end();
        } catch (Throwable t1) {
            AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
        }
    }
    return response;
}
Also used : StandaloneWSResponse(play.libs.ws.StandaloneWSResponse) Segment(com.newrelic.api.agent.Segment) BiConsumer(java.util.function.BiConsumer) URL(java.net.URL)

Example 5 with Segment

use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.

the class StandaloneWSClient_Instrumentation method url.

public StandaloneWSRequest_Instrumentation url(String url) {
    Segment segment = PlayWSUtils.start();
    StandaloneWSRequest_Instrumentation request = Weaver.callOriginal();
    Buffer<Tuple2<String, String>> headers = PlayWSUtils.createSeq();
    segment.addOutboundRequestHeaders(new OutboundWrapper(headers));
    request.segment = segment;
    // This is here to ensure that we always add our outbound CAT headers
    return request.addHttpHeaders(headers);
}
Also used : Tuple2(scala.Tuple2) Segment(com.newrelic.api.agent.Segment) OutboundWrapper(com.nr.agent.instrumentation.playws.OutboundWrapper)

Aggregations

Segment (com.newrelic.api.agent.Segment)138 Trace (com.newrelic.api.agent.Trace)13 URI (java.net.URI)6 NoOpSegment (com.newrelic.agent.bridge.NoOpSegment)5 URISyntaxException (java.net.URISyntaxException)4 HttpResponse (akka.http.scaladsl.model.HttpResponse)3 Transaction (com.newrelic.agent.bridge.Transaction)3 DatastoreParameters (com.newrelic.api.agent.DatastoreParameters)3 ExternalParameters (com.newrelic.api.agent.ExternalParameters)3 InetSocketAddress (java.net.InetSocketAddress)3 Test (org.junit.Test)3 Transaction (com.newrelic.agent.Transaction)2 MessageProduceParameters (com.newrelic.api.agent.MessageProduceParameters)2 Transaction (com.newrelic.api.agent.Transaction)2 OutboundWrapper (com.nr.agent.instrumentation.asynchttpclient.OutboundWrapper)2 HelloReply (io.grpc.examples.helloworld.HelloReply)2 HelloRequest (io.grpc.examples.helloworld.HelloRequest)2 IOException (java.io.IOException)2 SocketAddress (java.net.SocketAddress)2 MemcachedNode (net.spy.memcached.MemcachedNode)2