Search in sources :

Example 56 with Segment

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

the class ExternalAsyncTest method testCat.

@Test
public void testCat() throws Exception {
    // override default agent config to disabled distributed tracing and use CAT instead
    EnvironmentHolder holder = setupEnvironmentHolder("cat_enabled_dt_disabled_test");
    try {
        final Outbound outbound = new Outbound();
        final Inbound inbound = new Inbound();
        doInTransaction((Callable<Void>) () -> {
            Segment externalEvent = startSegment(outbound);
            Transaction transaction = Transaction.getTransaction(false);
            String encodingKey = transaction.getCrossProcessConfig().getEncodingKey();
            String appData = Obfuscator.obfuscateNameUsingKey("[\"crossProcessId\",\"externalTransactionName\"]", encodingKey);
            inbound.headers.put(HeadersUtil.NEWRELIC_APP_DATA_HEADER, appData);
            finishExternalEvent(externalEvent, null, inbound, HOST, LIBRARY, URI, OPERATION_NAME);
            return null;
        });
        // assert outbound request headers were populated correctly
        Assert.assertTrue(outbound.headers.containsKey(HeadersUtil.NEWRELIC_ID_HEADER));
        Assert.assertTrue(outbound.headers.containsKey(HeadersUtil.NEWRELIC_TRANSACTION_HEADER));
        // assert inbound response headers were processed correctly by checking for CAT metric name
        verifyTimesSet(1);
        verifyScopedMetricsPresent("OtherTransaction/Custom/com.newrelic.agent.async.ExternalAsyncTest/doInTransaction", "ExternalTransaction/www.example.com/crossProcessId/externalTransactionName");
        verifyUnscopedMetricsPresent("External/www.example.com/all", "External/allOther", "External/all");
        verifyScopedMetricsNotPresent("OtherTransaction/Custom/com.newrelic.agent.async.ExternalAsyncTest/doInTransaction", "External/www.host2.com/library");
        verifyTransactionSegmentsBreadthFirst("OtherTransaction/Custom/com.newrelic.agent.async.ExternalAsyncTest/doInTransaction", "Java/com.newrelic.agent.async.ExternalAsyncTest/doInTransaction", Thread.currentThread().getName(), "ExternalTransaction/www.example.com/crossProcessId/externalTransactionName", NO_ASYNC_CONTEXT);
        verifyNoExceptions();
    } finally {
        holder.close();
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) Segment(com.newrelic.api.agent.Segment) NoOpSegment(com.newrelic.agent.bridge.NoOpSegment) Test(org.junit.Test)

Example 57 with Segment

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

the class SessionManager_Instrumentation method executeAsync.

public ResultSetFuture executeAsync(Statement statement) {
    final Segment segment;
    ResultSetFuture result = Weaver.callOriginal();
    if (result != null && null != AgentBridge.getAgent().getTransaction(false) && AgentBridge.getAgent().getTransaction().isStarted()) {
        segment = NewRelic.getAgent().getTransaction().startSegment("executeAsync");
    } else {
        segment = null;
    }
    if (segment != null) {
        NewRelicChainedResultSetFuture nrfuture = new NewRelicChainedResultSetFuture(getLoggedKeyspace(), segment, result, statement);
        nrfuture.setSource(result);
        return nrfuture;
    }
    return result;
}
Also used : Segment(com.newrelic.api.agent.Segment)

Example 58 with Segment

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

the class TraceAccessorApiTest method startSegmentAndAssertTraceId.

@Trace(dispatcher = true)
private void startSegmentAndAssertTraceId() {
    Segment testSegment = NewRelic.getAgent().getTransaction().startSegment("TestSegment");
    String traceId = AgentBridge.getAgent().getTraceMetadata().getTraceId();
    Transaction txn = ServiceFactory.getServiceManager().getTransactionService().getTransaction(false);
    // A segment should not affect the traceId
    assertEquals(txn.getSpanProxy().getTraceId(), traceId);
    testSegment.end();
}
Also used : Transaction(com.newrelic.agent.Transaction) Segment(com.newrelic.api.agent.Segment) Trace(com.newrelic.api.agent.Trace)

Example 59 with Segment

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

the class TraceAccessorApiTest method startSegmentAndReturnSpanId.

@Trace(dispatcher = true)
private String startSegmentAndReturnSpanId() {
    Segment testSegment = NewRelic.getAgent().getTransaction().startSegment("TestSegment");
    // A segment should not affect the spanId
    String spanId = AgentBridge.getAgent().getTraceMetadata().getSpanId();
    testSegment.end();
    return spanId;
}
Also used : Segment(com.newrelic.api.agent.Segment) Trace(com.newrelic.api.agent.Trace)

Example 60 with Segment

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

the class S3AsyncClient_Instrumentation method createBucket.

public CompletableFuture<CreateBucketResponse> createBucket(CreateBucketRequest createBucketRequest) {
    String uri = "s3://" + createBucketRequest.bucket();
    Segment segment = NewRelic.getAgent().getTransaction().startSegment("S3", "createBucket");
    AgentBridge.getAgent().getTracedMethod().setTrackChildThreads(false);
    CompletableFuture<CreateBucketResponse> result = Weaver.callOriginal();
    return result.whenComplete(new S3ResponseResultWrapper<>(segment, uri, "createBucket"));
}
Also used : CreateBucketResponse(software.amazon.awssdk.services.s3.model.CreateBucketResponse) Segment(com.newrelic.api.agent.Segment)

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