Search in sources :

Example 1 with NewRelicApiImplementation

use of com.newrelic.api.agent.NewRelicApiImplementation in project newrelic-java-agent by newrelic.

the class NoticeErrorAttributesTest method testNoticeErrorAPIFirstCallWins.

@Test
public void testNoticeErrorAPIFirstCallWins() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        AttributesService service = new AttributesService();
        manager.setAttributesService(service);
        RPMServiceManager mockRPMServiceManager = manager.getRPMServiceManager();
        RPMService mockRPMService = mock(RPMService.class);
        ErrorService errorService = new ErrorServiceImpl(APP_NAME);
        when(mockRPMServiceManager.getRPMService()).thenReturn(mockRPMService);
        when(mockRPMService.getErrorService()).thenReturn(errorService);
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        Map<String, String> atts = new HashMap<>();
        atts.put("test.foo", "1");
        impl.noticeError("hello", atts);
        Map<String, String> atts2 = new HashMap<>();
        atts.put("test.bar", "2");
        impl.noticeError("hello", atts2);
        Set<String> expected = Sets.newHashSet("test.foo");
        verifyOutput(t.getErrorAttributes(), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) RPMServiceManager(com.newrelic.agent.RPMServiceManager) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ErrorService(com.newrelic.agent.errors.ErrorService) Transaction(com.newrelic.agent.Transaction) RPMService(com.newrelic.agent.RPMService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test)

Example 2 with NewRelicApiImplementation

use of com.newrelic.api.agent.NewRelicApiImplementation in project newrelic-java-agent by newrelic.

the class HighSecurityAttributesTest method testHighSecurityOnWithOtherDefaultsThroughNoticeErrorAPIMessage.

@Test
public void testHighSecurityOnWithOtherDefaultsThroughNoticeErrorAPIMessage() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        settings.put("high_security", Boolean.TRUE);
        enableBrowser(settings);
        manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        AttributesService service = new AttributesService();
        manager.setAttributesService(service);
        RPMServiceManager mockRPMServiceManager = manager.getRPMServiceManager();
        RPMService mockRPMService = mock(RPMService.class);
        ErrorService errorService = new ErrorServiceImpl(APP_NAME);
        when(mockRPMServiceManager.getRPMService()).thenReturn(mockRPMService);
        when(mockRPMService.getErrorService()).thenReturn(errorService);
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        Map<String, String> atts = new HashMap<>();
        atts.put("abc.thread", "1");
        atts.put("request.many", "1");
        atts.put("message.many", "1");
        atts.put("request.parameters.foo", "1");
        atts.put("request.parameters.bar", "1");
        atts.put("message.parameters.foo", "1");
        atts.put("message.parameters.bar", "1");
        impl.noticeError("hello", atts);
        // user attributes should be off
        Set<String> expected = new HashSet<>();
        verifyOutput(service.filterErrorEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionTraceAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterBrowserAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterSpanEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionSegmentAttributes(APP_NAME, t.getErrorAttributes()), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) RPMServiceManager(com.newrelic.agent.RPMServiceManager) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ErrorService(com.newrelic.agent.errors.ErrorService) Transaction(com.newrelic.agent.Transaction) RPMService(com.newrelic.agent.RPMService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with NewRelicApiImplementation

use of com.newrelic.api.agent.NewRelicApiImplementation in project newrelic-java-agent by newrelic.

the class HighSecurityAttributesTest method testHighSecurityOnWithOtherDefaultsThroughNoticeErrorAPIThrowable.

@Test
public void testHighSecurityOnWithOtherDefaultsThroughNoticeErrorAPIThrowable() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        settings.put("high_security", Boolean.TRUE);
        enableBrowser(settings);
        manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        AttributesService service = new AttributesService();
        manager.setAttributesService(service);
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        Map<String, String> atts = new HashMap<>();
        atts.put("abc.thread", "1");
        atts.put("request.many", "1");
        atts.put("message.many", "1");
        atts.put("request.parameters.foo", "1");
        atts.put("request.parameters.bar", "1");
        atts.put("message.parameters.foo", "1");
        atts.put("message.parameters.bar", "1");
        impl.noticeError(new Throwable("hello"), atts);
        // user attributes should be off
        Set<String> expected = new HashSet<>();
        verifyOutput(service.filterErrorEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionTraceAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterBrowserAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterSpanEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionSegmentAttributes(APP_NAME, t.getErrorAttributes()), 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) Transaction(com.newrelic.agent.Transaction) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with NewRelicApiImplementation

use of com.newrelic.api.agent.NewRelicApiImplementation in project newrelic-java-agent by newrelic.

the class WeaveTest method before.

@Before
public void before() {
    test = new TestClass();
    errorMessage = null;
    throwable = null;
    libraryName = null;
    instrumentationThrowable = null;
    AgentBridge.publicApi = new NewRelicApiImplementation() {

        @Override
        public void noticeError(String message) {
            errorMessage = message;
        }

        @Override
        public void noticeError(Throwable throwable) {
            WeaveTest.this.throwable = throwable;
        }
    };
    AgentBridge.instrumentation = new InstrumentationImpl(Agent.LOG) {

        @Override
        public void noticeInstrumentationError(Throwable throwable, String libraryName) {
            WeaveTest.this.instrumentationThrowable = throwable;
            WeaveTest.this.libraryName = libraryName;
        }
    };
}
Also used : InstrumentationImpl(com.newrelic.agent.instrumentation.InstrumentationImpl) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) Before(org.junit.Before)

Example 5 with NewRelicApiImplementation

use of com.newrelic.api.agent.NewRelicApiImplementation 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)

Aggregations

NewRelicApiImplementation (com.newrelic.api.agent.NewRelicApiImplementation)12 Transaction (com.newrelic.agent.Transaction)11 TransactionService (com.newrelic.agent.TransactionService)11 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)11 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)8 HashSet (java.util.HashSet)5 RPMService (com.newrelic.agent.RPMService)4 RPMServiceManager (com.newrelic.agent.RPMServiceManager)4 ConfigServiceFactory (com.newrelic.agent.config.ConfigServiceFactory)4 ErrorService (com.newrelic.agent.errors.ErrorService)4 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)4 InstrumentationImpl (com.newrelic.agent.instrumentation.InstrumentationImpl)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Before (org.junit.Before)1