Search in sources :

Example 81 with ConfigService

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"));
}
Also used : HashMap(java.util.HashMap) TransactionDataToDistributedTraceIntrinsics(com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) StringWriter(java.io.StringWriter) TransactionData(com.newrelic.agent.TransactionData) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherTransSimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat) TransactionService(com.newrelic.agent.TransactionService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) JSONArray(org.json.simple.JSONArray) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockConfigService(com.newrelic.agent.MockConfigService) ConfigService(com.newrelic.agent.config.ConfigService) TransactionStats(com.newrelic.agent.stats.TransactionStats) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) JSONObject(org.json.simple.JSONObject) MockServiceManager(com.newrelic.agent.MockServiceManager) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) JSONObject(org.json.simple.JSONObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Writer(java.io.Writer) StringWriter(java.io.StringWriter) Test(org.junit.Test)

Example 82 with ConfigService

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));
}
Also used : AttributesService(com.newrelic.agent.attributes.AttributesService) JSONArray(org.json.simple.JSONArray) MockConfigService(com.newrelic.agent.MockConfigService) ConfigService(com.newrelic.agent.config.ConfigService) StringWriter(java.io.StringWriter) JSONObject(org.json.simple.JSONObject) MockServiceManager(com.newrelic.agent.MockServiceManager) JSONObject(org.json.simple.JSONObject) TransactionData(com.newrelic.agent.TransactionData) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Writer(java.io.Writer) StringWriter(java.io.StringWriter) Test(org.junit.Test)

Example 83 with ConfigService

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);
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) IAgentLogger(com.newrelic.agent.logging.IAgentLogger) BeforeClass(org.junit.BeforeClass)

Example 84 with ConfigService

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);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) HashMap(java.util.HashMap) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 85 with ConfigService

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();
}
Also used : TransactionService(com.newrelic.agent.TransactionService) HashMap(java.util.HashMap) HarvestServiceImpl(com.newrelic.agent.HarvestServiceImpl) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) TransactionDataToDistributedTraceIntrinsics(com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics) ConfigService(com.newrelic.agent.config.ConfigService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) Before(org.junit.Before)

Aggregations

ConfigService (com.newrelic.agent.config.ConfigService)95 MockServiceManager (com.newrelic.agent.MockServiceManager)57 TransactionService (com.newrelic.agent.TransactionService)36 AgentConfig (com.newrelic.agent.config.AgentConfig)36 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)32 ThreadService (com.newrelic.agent.ThreadService)31 AttributesService (com.newrelic.agent.attributes.AttributesService)30 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)29 HarvestService (com.newrelic.agent.HarvestService)24 MockHarvestService (com.newrelic.agent.MockHarvestService)23 HashMap (java.util.HashMap)23 StatsService (com.newrelic.agent.stats.StatsService)21 MockCoreService (com.newrelic.agent.MockCoreService)20 MockRPMService (com.newrelic.agent.MockRPMService)20 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)20 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)20 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)19 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)17 Test (org.junit.Test)15 EnvironmentService (com.newrelic.agent.environment.EnvironmentService)14