Search in sources :

Example 1 with ConfigServiceFactory

use of com.newrelic.agent.config.ConfigServiceFactory in project newrelic-java-agent by newrelic.

the class AgentAttributeSenderTest method testCustomAttributesInTransaction.

@Test
public void testCustomAttributesInTransaction() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        manager.setAttributesService(new AttributesService());
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        impl.addCustomParameter("abc.thread", "1");
        impl.addCustomParameter("request.many", "1");
        impl.addCustomParameter("message.many", "1");
        impl.addCustomParameter("message.bool", true);
        Map<String, Object> customParamMap = new HashMap<>();
        customParamMap.put("key1", "val1");
        customParamMap.put("key2", 2);
        customParamMap.put("key3", new HashMap<>());
        customParamMap.put("key4", true);
        customParamMap.put("key5", null);
        impl.addCustomParameters(customParamMap);
        Set<String> expected = Sets.newHashSet("abc.thread", "request.many", "message.many", "key1", "key2", "key4", "message.bool");
        verifyOutput(t.getUserAttributes(), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) HashMap(java.util.HashMap) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ConfigServiceFactory(com.newrelic.agent.config.ConfigServiceFactory) Transaction(com.newrelic.agent.Transaction) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test)

Example 2 with ConfigServiceFactory

use of com.newrelic.agent.config.ConfigServiceFactory in project newrelic-java-agent by newrelic.

the class AgentAttributeSenderTest method testErrorAttributesTypes.

@Test
public void testErrorAttributesTypes() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        Transaction t = Transaction.getTransaction();
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        Map<String, Object> attributes = new HashMap<>();
        attributes.put("MyNumber", 54);
        attributes.put("MyAtomicInteger", new AtomicInteger(54));
        attributes.put("MyAtomicLong", new AtomicLong(54));
        attributes.put("MyAtomicBool", new AtomicBoolean(true));
        // Invalid attribute values
        attributes.put("MyBigDecimal", BigDecimal.valueOf(10.000000));
        attributes.put("MyBigInteger", BigInteger.valueOf(10000000L));
        attributes.put("MyNaN", Double.NaN);
        attributes.put("MyPosInf", Double.POSITIVE_INFINITY);
        attributes.put("MyNegInf", Double.NEGATIVE_INFINITY);
        Exception exception = new Exception("~~ oops ~~");
        impl.noticeError(exception, attributes);
        // no tx - no atts
        Set<String> expected = new HashSet<>();
        verifyOutput(t.getUserAttributes(), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) HashMap(java.util.HashMap) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConfigServiceFactory(com.newrelic.agent.config.ConfigServiceFactory) AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(com.newrelic.agent.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ConfigServiceFactory

use of com.newrelic.agent.config.ConfigServiceFactory in project newrelic-java-agent by newrelic.

the class AgentAttributeSenderTest method shouldTruncateLongAttributeValues.

@Test
public void shouldTruncateLongAttributeValues() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        manager.setAttributesService(new AttributesService());
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        impl.addCustomParameter(makeLongString("ignored-key-too-long"), "vv");
        String valueVeryLong = makeLongString("v2");
        impl.addCustomParameter("truncated-single-value", valueVeryLong);
        Map<String, Object> customParamMap = new HashMap<>();
        customParamMap.put(makeLongString("ignored-key-too-long-also"), "vx");
        customParamMap.put("truncated-map-value", makeLongString("v4"));
        impl.addCustomParameters(customParamMap);
        Set<String> expected = Sets.newHashSet("truncated-single-value", "truncated-map-value");
        Map<String, Object> attribs = t.getUserAttributes();
        Assert.assertEquals(expected, attribs.keySet());
        Assert.assertEquals(255, attribs.get("truncated-single-value").toString().length());
        Assert.assertNotEquals(255, valueVeryLong.length());
        Assert.assertEquals(255, attribs.get("truncated-map-value").toString().length());
        Assert.assertNotEquals(255, customParamMap.get("truncated-map-value"));
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : ConfigServiceFactory(com.newrelic.agent.config.ConfigServiceFactory) TransactionService(com.newrelic.agent.TransactionService) Transaction(com.newrelic.agent.Transaction) HashMap(java.util.HashMap) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test)

Example 4 with ConfigServiceFactory

use of com.newrelic.agent.config.ConfigServiceFactory in project newrelic-java-agent by newrelic.

the class AgentAttributeSenderTest method testCustomAttributesOutsideTransaction.

@Test
public void testCustomAttributesOutsideTransaction() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        Transaction t = Transaction.getTransaction();
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        impl.addCustomParameter("abc.thread", "1");
        impl.addCustomParameter("request.many", "1");
        impl.addCustomParameter("message.many", "1");
        Map<String, Object> customParamMap = new HashMap<>();
        customParamMap.put("key1", "val1");
        customParamMap.put("key2", 2);
        customParamMap.put("key3", new HashMap<>());
        customParamMap.put("key4", true);
        customParamMap.put("key5", null);
        impl.addCustomParameters(customParamMap);
        // no tx - no atts
        Set<String> expected = new HashSet<>();
        verifyOutput(t.getUserAttributes(), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : ConfigServiceFactory(com.newrelic.agent.config.ConfigServiceFactory) TransactionService(com.newrelic.agent.TransactionService) Transaction(com.newrelic.agent.Transaction) HashMap(java.util.HashMap) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ConfigServiceFactory

use of com.newrelic.agent.config.ConfigServiceFactory in project newrelic-java-agent by newrelic.

the class HighSecurityRemoteInstTest method performSetupWork.

private RemoteInstrumentationServiceImpl performSetupWork(boolean highSecurity) {
    Map<String, Object> settings = new HashMap<>();
    settings.put("app_name", APP_NAME);
    if (highSecurity) {
        settings.put(AgentConfigImpl.HIGH_SECURITY, Boolean.TRUE);
    } else {
        settings.put(AgentConfigImpl.HIGH_SECURITY, Boolean.FALSE);
    }
    manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
    TransactionService transactionService = new TransactionService();
    manager.setTransactionService(transactionService);
    MockCoreService agent = new MockCoreService();
    manager.setCoreService(agent);
    agent.setInstrumentation(new InstrumentationProxy(new TestInstrumentation(), false));
    // Needed by Transaction
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    manager.setTransactionTraceService(transactionTraceService);
    manager.setAttributesService(new AttributesService());
    // Needed by Transaction
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    manager.setRPMServiceManager(rpmServiceManager);
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName(APP_NAME);
    rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
    rpmServiceManager.setRPMService(rpmService);
    RemoteInstrumentationServiceImpl impl = new RemoteInstrumentationServiceImpl();
    manager.setReinstrumentService(impl);
    return impl;
}
Also used : RemoteInstrumentationServiceImpl(com.newrelic.agent.reinstrument.RemoteInstrumentationServiceImpl) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) AttributesService(com.newrelic.agent.attributes.AttributesService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ConfigServiceFactory(com.newrelic.agent.config.ConfigServiceFactory)

Aggregations

ConfigServiceFactory (com.newrelic.agent.config.ConfigServiceFactory)5 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)5 HashMap (java.util.HashMap)5 Transaction (com.newrelic.agent.Transaction)4 TransactionService (com.newrelic.agent.TransactionService)4 NewRelicApiImplementation (com.newrelic.api.agent.NewRelicApiImplementation)4 Test (org.junit.Test)4 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)2 HashSet (java.util.HashSet)2 AttributesService (com.newrelic.agent.attributes.AttributesService)1 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)1 RemoteInstrumentationServiceImpl (com.newrelic.agent.reinstrument.RemoteInstrumentationServiceImpl)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1