use of com.newrelic.agent.config.ConfigService 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.config.ConfigService in project newrelic-java-agent by newrelic.
the class TransactionTraceTest method testTraceWithTimeout.
@Test
public void testTraceWithTimeout() throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(null), new HashMap<String, Object>());
serviceManager.setConfigService(configService);
AttributesService attService = new AttributesService();
serviceManager.setAttributesService(attService);
TransactionTraceService transactionTraceService = new TransactionTraceService();
serviceManager.setTransactionTraceService(transactionTraceService);
TransactionData td = createTransactionData(TimeoutCause.TOKEN);
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.assertEquals("token", intrinsics.get(AttributeNames.TIMEOUT_CAUSE));
}
use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.
the class BaseDistributedTraceTest method beforeClass.
@BeforeClass
public static void beforeClass() {
final Map<String, Object> settings = new HashMap<>();
settings.put(AgentConfigImpl.APP_NAME, "Unit Test");
settings.put(AgentConfigImpl.HOST, "no-collector.example.com");
Map<String, Object> dtConfig = new HashMap<>();
dtConfig.put("enabled", true);
settings.put("distributed_tracing", dtConfig);
ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(settings);
serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
noOpLogger = Mockito.mock(IAgentLogger.class);
}
use of com.newrelic.agent.config.ConfigService 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.config.ConfigService in project newrelic-java-agent by newrelic.
the class DistributedTraceServiceImplTest method before.
@Before
public void before() throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(AgentConfigImpl.APP_NAME, "Test");
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);
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), Collections.<String, Object>emptyMap());
serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
serviceManager.setConfigService(configService);
serviceManager.setTransactionTraceService(new TransactionTraceService());
serviceManager.setTransactionService(new TransactionService());
distributedTraceService = new DistributedTraceServiceImpl();
serviceManager.setDistributedTraceService(distributedTraceService);
TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
serviceManager.setHarvestService(new HarvestServiceImpl());
serviceManager.setStatsService(new StatsServiceImpl());
rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
ServiceFactory.getServiceManager().start();
}
Aggregations