use of com.newrelic.agent.tracers.OtherRootTracer in project newrelic-java-agent by newrelic.
the class TransactionTraceTest method testDistributedTracingAtts.
@Test
public void testDistributedTracingAtts() throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
Map<String, Object> config = new HashMap<>();
Map<String, Object> dtConfig = new HashMap<>();
dtConfig.put("enabled", true);
config.put("distributed_tracing", dtConfig);
Map<String, Object> spanConfig = new HashMap<>();
spanConfig.put("collect_span_events", true);
config.put("span_events", spanConfig);
config.put(AgentConfigImpl.APP_NAME, "TransactionTraceTest");
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), config);
serviceManager.setConfigService(configService);
serviceManager.setAttributesService(new AttributesService());
serviceManager.setTransactionTraceService(new TransactionTraceService());
serviceManager.setTransactionService(new TransactionService());
DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
serviceManager.setDistributedTraceService(distributedTraceService);
TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
serviceManager.setRPMServiceManager(new MockRPMServiceManager());
Transaction.clearTransaction();
Transaction transaction = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("class", "method", "desc");
OtherRootTracer tracer = new OtherRootTracer(transaction, sig, null, new SimpleMetricNameFormat("metric"));
transaction.getTransactionActivity().tracerStarted(tracer);
tracer.finish(Opcodes.ARETURN, null);
TransactionData td = new TransactionData(transaction, 0);
((DistributedTraceServiceImpl) ServiceFactory.getDistributedTraceService()).dispatcherTransactionFinished(td, new TransactionStats());
TransactionTrace trace = TransactionTrace.getTransactionTrace(td, SqlObfuscator.getDefaultSqlObfuscator());
Writer writer = new StringWriter();
trace.writeJSONString(writer);
JSONArray serializedTrace = (JSONArray) AgentHelper.serializeJSON(trace);
JSONArray traceDetails = (JSONArray) decodeTransactionTraceData(serializedTrace.get(4));
JSONObject atts = (JSONObject) traceDetails.get(4);
Map<String, Object> intrinsics = (Map<String, Object>) atts.get("intrinsics");
Assert.assertTrue(intrinsics.containsKey("traceId"));
Assert.assertTrue(intrinsics.containsKey("guid"));
Assert.assertTrue(intrinsics.containsKey("priority"));
Assert.assertTrue(intrinsics.containsKey("sampled"));
}
use of com.newrelic.agent.tracers.OtherRootTracer in project newrelic-java-agent by newrelic.
the class TransactionTraceTest method testExecContext.
@Test
public void testExecContext() throws Exception {
setUp(false, true, false);
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = new OtherRootTracer(tx, new ClassMethodSignature("Test", "root", "()V"), this, new OtherTransSimpleMetricNameFormat("myMetricName"));
DefaultTracer tracer1 = new DefaultTracer(tx, new ClassMethodSignature("Test", "dude", "()V"), this);
DefaultTracer tracer2 = new DefaultTracer(tx, new ClassMethodSignature("Test", "dude2", "()V"), this);
tx.getTransactionActivity().tracerStarted(rootTracer);
tx.getTransactionActivity().tracerStarted(tracer1);
tx.getTransactionActivity().tracerStarted(tracer2);
tracer2.finish(0, null);
tracer1.finish(0, null);
rootTracer.finish(0, null);
long startTime = System.currentTimeMillis();
String frontendMetricName = "Frontend/dude";
String requestUri = "/dude";
String appName = "dude";
TransactionData transactionData = new TransactionDataTestBuilder(appName, iAgentConfig, rootTracer).setStartTime(startTime).setRequestUri(requestUri).setFrontendMetricName(frontendMetricName).setTracers(Arrays.asList(rootTracer, tracer1, tracer2)).build();
TransactionTrace trace = TransactionTrace.getTransactionTrace(transactionData, SqlObfuscator.getDefaultSqlObfuscator());
JSONParser parser = new JSONParser();
// Get the raw data
JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(trace);
// Manually create an "inflated" version for comparison with simple compression
JSONArray inflatedJsonArray = new JSONArray();
inflatedJsonArray.addAll(jsonArray);
// Extract and inflate
Object decodedTTData = decodeTransactionTraceData(inflatedJsonArray.get(4));
// Store back in array to compare with simple compression below
inflatedJsonArray.set(4, decodedTTData);
Assert.assertNotNull(jsonArray);
// Second, serialize with simple compression off (data will be deflated)
byte[] jsonByteArray = AgentHelper.serializeJSONToByteArray(trace);
JSONArray parsedJsonByteArray = (JSONArray) parser.parse(new String(jsonByteArray, StandardCharsets.UTF_8));
Assert.assertEquals(jsonArray, parsedJsonByteArray);
// Third, turn on simple compression and compare with raw data above
setUp(false, true, true);
byte[] simpleCompressionJsonByteArray = AgentHelper.serializeJSONToByteArray(trace);
JSONArray parsedSimpleCompressionJsonByteArray = (JSONArray) parser.parse(new String(simpleCompressionJsonByteArray, StandardCharsets.UTF_8));
Assert.assertEquals(inflatedJsonArray, parsedSimpleCompressionJsonByteArray);
JSONArray jsonRootSegment = (JSONArray) decodedTTData;
Assert.assertEquals(8, jsonArray.size());
JSONArray rootSeg = (JSONArray) jsonRootSegment.get(3);
Assert.assertNotNull(rootSeg);
verifyAllTraceSegmentsHaveExecContext(rootSeg);
}
use of com.newrelic.agent.tracers.OtherRootTracer in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method createDispatcher.
private WebRequestDispatcher createDispatcher(Request httpRequest) throws Exception {
Transaction tx = Transaction.getTransaction();
Response httpResponse = new MockHttpResponse();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
DefaultTracer tracer = new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("test"));
tx.getTransactionActivity().tracerStarted(tracer);
WebRequestDispatcher dispatcher = new WebRequestDispatcher(httpRequest, httpResponse, tx);
tx.setDispatcher(dispatcher);
return dispatcher;
}
use of com.newrelic.agent.tracers.OtherRootTracer in project newrelic-java-agent by newrelic.
the class DistributedTraceServiceImplTest method configureAndCreatePayload.
private DistributedTracePayload configureAndCreatePayload(boolean excludeNewRelicHeader, boolean spanEventsEnabled) {
Map<String, Object> config = new HashMap<>();
config.put(AgentConfigImpl.APP_NAME, "Test");
Map<String, Object> dtConfig = new HashMap<>();
dtConfig.put(DistributedTracingConfig.ENABLED, true);
// This will need to change when we implement JAVA-5559
if (excludeNewRelicHeader) {
dtConfig.put(DistributedTracingConfig.EXCLUDE_NEWRELIC_HEADER, "true");
}
config.put(AgentConfigImpl.DISTRIBUTED_TRACING, dtConfig);
Map<String, Object> spansConfig = new HashMap<>();
spansConfig.put(SpanEventsConfig.ENABLED, spanEventsEnabled);
spansConfig.put(SpanEventsConfig.COLLECT_SPAN_EVENTS, true);
config.put(AgentConfigImpl.SPAN_EVENTS, spansConfig);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(config);
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
serviceManager.setConfigService(configService);
DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
Map<String, Object> connectInfo = new HashMap<>();
connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, "accountId");
connectInfo.put(DistributedTracingConfig.PRIMARY_APPLICATION_ID, "primaryApplicationId");
connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, "trustKey");
connectInfo.put(DistributedTracingConfig.EXCLUDE_NEWRELIC_HEADER, excludeNewRelicHeader);
AgentConfig connectData = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
DistributedTraceServiceImplTest.distributedTraceService.connected(serviceManager.getRPMServiceManager().getRPMService(), connectData);
Transaction.clearTransaction();
txn = Transaction.getTransaction(true);
final ClassMethodSignature cms = new ClassMethodSignature("class", "method", "methodDesc");
final OtherRootTracer tracer = new OtherRootTracer(txn, cms, null, new SimpleMetricNameFormat("metricName"));
txn.getTransactionActivity().tracerStarted(tracer);
return distributedTraceService.createDistributedTracePayload(tracer);
}
use of com.newrelic.agent.tracers.OtherRootTracer in project newrelic-java-agent by newrelic.
the class TransactionActivityTest method txaNoTxn.
@Test
public void txaNoTxn() {
TransactionActivity txa = TransactionActivity.create(null, Integer.MAX_VALUE);
ClassMethodSignature classMethodSignature = new ClassMethodSignature("class", "method", "methodDesc");
OtherRootTracer tracer = new OtherRootTracer(txa, classMethodSignature, null, null, TracerFlags.TRANSACTION_TRACER_SEGMENT | TracerFlags.ASYNC, 0);
tracer.isTransactionSegment();
// Make sure methods that touch this txa's txn don't throw NPEs.
txa.tracerStarted(tracer);
txa.addTracer(tracer);
txa.tracerFinished(tracer, 0);
}
Aggregations