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();
}
}
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;
}
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();
}
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;
}
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"));
}
Aggregations