use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.
the class CollectorSpanEventReservoirManagerTest method httpErrorTriggerDiscard.
@Test
public void httpErrorTriggerDiscard() {
ConfigService mockConfigService = mock21Samples();
CollectorSpanEventReservoirManager target = initWith25Tries(mockConfigService);
ReservoirManager.HarvestResult harvestResult = target.attemptToSendReservoir(APP_NAME, (appName, reservoirSize, eventsSeen, events) -> {
throw new HttpError("message", 0, 0) {
@Override
public boolean discardHarvestData() {
return true;
}
};
}, mock(Logger.class));
assertNull(harvestResult);
assertEquals(0, target.getOrCreateReservoir(APP_NAME).size());
assertEquals(0, target.getOrCreateReservoir(APP_NAME).getNumberOfTries());
}
use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.
the class CollectorSpanEventReservoirManagerTest method getOrCreateReturnsSameReservoir.
@Test
public void getOrCreateReturnsSameReservoir() {
ConfigService mockConfigService = mock21Samples();
CollectorSpanEventReservoirManager target = initWith25Tries(mockConfigService);
assertEquals(21, target.getOrCreateReservoir(APP_NAME).size());
assertTrue(target.getOrCreateReservoir(APP_NAME).isFull());
}
use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.
the class CoreServiceImpl method doStart.
@Override
protected void doStart() {
ConfigService configService = ServiceFactory.getConfigService();
AgentConfig config = configService.getDefaultAgentConfig();
AgentLogManager.configureLogger(config);
logHostIp();
Agent.LOG.info(MessageFormat.format("New Relic Agent v{0} is initializing...", Agent.getVersion()));
enabled = config.isAgentEnabled();
if (!enabled) {
Agent.LOG.info("New Relic agent is disabled.");
}
if (config.liteMode()) {
Agent.LOG.info("New Relic agent is running in lite mode. All instrumentation modules are disabled");
StatsService statsService = ServiceFactory.getServiceManager().getStatsService();
statsService.getMetricAggregator().incrementCounter(MetricNames.SUPPORTABILITY_LITE_MODE);
}
instrumentationProxy = InstrumentationProxy.getInstrumentationProxy(instrumentation);
initializeBridgeApis();
final long startTime = System.currentTimeMillis();
Runnable runnable = new Runnable() {
@Override
public void run() {
jvmShutdown(startTime);
}
};
Thread shutdownThread = new Thread(runnable, "New Relic JVM Shutdown");
Runtime.getRuntime().addShutdownHook(shutdownThread);
}
use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.
the class HeadersUtilTest method createDTHeadersSetsSpanIdEvenIfTxNotSampled.
@Test
public void createDTHeadersSetsSpanIdEvenIfTxNotSampled() {
ConfigService mockConfigService = new MockConfigService(AgentConfigImpl.createAgentConfig(ImmutableMap.of(AgentConfigImpl.APP_NAME, "Unit Test", AgentConfigImpl.DISTRIBUTED_TRACING, Collections.singletonMap(DistributedTracingConfig.ENABLED, true), AgentConfigImpl.SPAN_EVENTS, ImmutableMap.of(SpanEventsConfig.ENABLED, true, SpanEventsConfig.COLLECT_SPAN_EVENTS, true))));
MockServiceManager mockServiceManager = new MockServiceManager(mockConfigService);
mockServiceManager.setDistributedTraceService(new MockDistributedTraceService());
ServiceFactory.setServiceManager(mockServiceManager);
Transaction tx = Transaction.getTransaction();
tx.setPriorityIfNotNull(0F);
tx.startTransactionIfBeginning(new MockDispatcherTracer(tx));
Tracer mockTracer = new DefaultTracer(tx, new ClassMethodSignature(getClass().getName(), "tracerMethod", "()V"), this);
OutboundHeadersMap map = new OutboundHeadersMap(HeaderType.HTTP);
assertTrue("DT headers should have been set", HeadersUtil.createAndSetDistributedTraceHeaders(tx, mockTracer, map));
assertFalse(tx.sampled());
assertTrue("map should contain newrelic header", map.containsKey("newrelic"));
String decodedHeader = new String(Base64.decodeBase64(map.get("newrelic")), StandardCharsets.UTF_8);
JsonObject jsonObject = new Gson().fromJson(decodedHeader, JsonObject.class);
assertFalse("d.sa should be false because tx is not sampled", jsonObject.getAsJsonObject("d").get("sa").getAsBoolean());
assertEquals("d.pr should be zero", 0f, jsonObject.getAsJsonObject("d").get("pr").getAsFloat(), 0.0001);
assertNotNull("d.id should not be null", jsonObject.getAsJsonObject("d").get("id"));
assertEquals("d.id should be the span id.", mockTracer.getGuid(), jsonObject.getAsJsonObject("d").get("id").getAsString());
String traceParent = map.get("traceparent");
assertEquals("traceparent parentId field should match span id.", mockTracer.getGuid(), traceParent.split("-")[2]);
String traceState = map.get("tracestate");
assertEquals("tracestate spanId field should match span id.", mockTracer.getGuid(), traceState.split("-")[4]);
assertEquals("tracestate txId field should match tx id.", tx.getGuid(), traceState.split("-")[5]);
}
use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.
the class AgentImplTest method createServiceManager.
private static void createServiceManager(Map<String, Object> map) throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
AgentConfig agentConfig = AgentHelper.createAgentConfig(true, map, Collections.<String, Object>emptyMap());
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, map);
serviceManager.setConfigService(configService);
TransactionTraceService transactionTraceService = new TransactionTraceService();
serviceManager.setTransactionTraceService(transactionTraceService);
}
Aggregations