Search in sources :

Example 1 with IRPMService

use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.

the class TransactionTraceService method afterHarvest.

@Override
public void afterHarvest(String appName) {
    List<TransactionTrace> traces = new ArrayList<>();
    if (autoAppNameEnabled) {
        traces.addAll(getNamedSamplerTraces(appName));
    } else {
        traces.addAll(getNamedSamplerTraces(TransactionTracerConfigImpl.REQUEST_CATEGORY_NAME));
        traces.addAll(getNamedSamplerTraces(TransactionTracerConfigImpl.BACKGROUND_CATEGORY_NAME));
    }
    traces.addAll(this.syntheticsTransactionSampler.harvest(appName));
    for (ITransactionSampler transactionSampler : transactionSamplers) {
        traces.addAll(transactionSampler.harvest(appName));
    }
    if (!traces.isEmpty()) {
        IRPMService rpmService = ServiceFactory.getRPMServiceManager().getOrCreateRPMService(appName);
        sendTraces(rpmService, traces);
    }
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IRPMService(com.newrelic.agent.IRPMService)

Example 2 with IRPMService

use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.

the class DistributedTraceServiceImplTest method testConnectFields.

@Test
public void testConnectFields() {
    assertNull(DistributedTraceServiceImplTest.distributedTraceService.getApplicationId());
    assertNull(DistributedTraceServiceImplTest.distributedTraceService.getTrustKey());
    assertNull(DistributedTraceServiceImplTest.distributedTraceService.getAccountId());
    IRPMService rpmService = rpmServiceManager.getOrCreateRPMService("Test");
    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");
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
    DistributedTraceServiceImplTest.distributedTraceService.connected(rpmService, agentConfig);
    assertEquals("accountId", DistributedTraceServiceImplTest.distributedTraceService.getAccountId());
    assertEquals("primaryApplicationId", DistributedTraceServiceImplTest.distributedTraceService.getApplicationId());
    assertEquals("trustKey", DistributedTraceServiceImplTest.distributedTraceService.getTrustKey());
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) HashMap(java.util.HashMap) IRPMService(com.newrelic.agent.IRPMService) Test(org.junit.Test)

Example 3 with IRPMService

use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.

the class StartProfilerCommandTest method validArgs.

@Test
public void validArgs() throws CommandException {
    IRPMService rpmService = null;
    final long profileId = 1L;
    final long duration = 60000L;
    final long samplePeriod = 500L;
    final boolean onlyRunnableThreads = true;
    final boolean onlyRequestThreads = true;
    final boolean profileAgentCode = true;
    Map<String, Object> args = new HashMap<String, Object>() {

        private static final long serialVersionUID = 1L;

        {
            put("profile_id", profileId);
            put("sample_period", samplePeriod);
            put("duration", duration);
            put("only_runnable_threads", onlyRunnableThreads);
            put("only_request_threads", onlyRequestThreads);
            put("profile_agent_code", profileAgentCode);
        }
    };
    startProfilerCommand.process(rpmService, args);
    Assert.assertEquals(duration * 1000L, profilerParameters.getDurationInMillis().longValue());
    Assert.assertEquals(samplePeriod * 1000L, profilerParameters.getSamplePeriodInMillis().longValue());
    Assert.assertEquals(profileId, profilerParameters.getProfileId().longValue());
    Assert.assertEquals(onlyRunnableThreads, profilerParameters.isRunnablesOnly());
    Assert.assertEquals(onlyRequestThreads, profilerParameters.isOnlyRequestThreads());
    Assert.assertEquals(profileAgentCode, profilerParameters.isProfileAgentThreads());
    Assert.assertNull(profilerParameters.getKeyTransaction());
}
Also used : HashMap(java.util.HashMap) IRPMService(com.newrelic.agent.IRPMService) Test(org.junit.Test)

Example 4 with IRPMService

use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.

the class StartProfilerCommandTest method noArguments.

@Test(expected = CommandException.class)
public void noArguments() throws CommandException {
    IRPMService rpmService = null;
    startProfilerCommand.process(rpmService, Collections.EMPTY_MAP);
}
Also used : IRPMService(com.newrelic.agent.IRPMService) Test(org.junit.Test)

Example 5 with IRPMService

use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.

the class StartProfilerCommandTest method validArgsNullDefault.

@Test
public void validArgsNullDefault() throws CommandException {
    IRPMService rpmService = null;
    final long profileId = 1L;
    final long duration = 60000L;
    final long samplePeriod = 500L;
    final boolean onlyRunnableThreads = true;
    final boolean onlyRequestThreads = true;
    final Object profileAgentCode = null;
    Map<String, Object> args = new HashMap<String, Object>() {

        private static final long serialVersionUID = 1L;

        {
            put("profile_id", profileId);
            put("sample_period", samplePeriod);
            put("duration", duration);
            put("only_runnable_threads", onlyRunnableThreads);
            put("only_request_threads", onlyRequestThreads);
            put("profile_agent_code", profileAgentCode);
        }
    };
    startProfilerCommand.process(rpmService, args);
    Assert.assertEquals(duration * 1000L, profilerParameters.getDurationInMillis().longValue());
    Assert.assertEquals(samplePeriod * 1000L, profilerParameters.getSamplePeriodInMillis().longValue());
    Assert.assertEquals(profileId, profilerParameters.getProfileId().longValue());
    Assert.assertEquals(onlyRunnableThreads, profilerParameters.isRunnablesOnly());
    Assert.assertEquals(onlyRequestThreads, profilerParameters.isOnlyRequestThreads());
    Assert.assertEquals(false, profilerParameters.isProfileAgentThreads());
    Assert.assertNull(profilerParameters.getKeyTransaction());
}
Also used : HashMap(java.util.HashMap) IRPMService(com.newrelic.agent.IRPMService) Test(org.junit.Test)

Aggregations

IRPMService (com.newrelic.agent.IRPMService)17 Test (org.junit.Test)11 HashMap (java.util.HashMap)9 AgentConfig (com.newrelic.agent.config.AgentConfig)4 MockServiceManager (com.newrelic.agent.MockServiceManager)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)1 RPMServiceManager (com.newrelic.agent.RPMServiceManager)1 TransactionService (com.newrelic.agent.TransactionService)1 ConfigServiceImpl (com.newrelic.agent.config.ConfigServiceImpl)1 ErrorService (com.newrelic.agent.errors.ErrorService)1 ClassTransformerService (com.newrelic.agent.instrumentation.ClassTransformerService)1 ServiceManager (com.newrelic.agent.service.ServiceManager)1 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)1 HttpError (com.newrelic.agent.transport.HttpError)1 JSONException (com.newrelic.agent.util.JSONException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1