Search in sources :

Example 1 with ErrorServiceImpl

use of com.newrelic.agent.errors.ErrorServiceImpl in project newrelic-java-agent by newrelic.

the class TransactionDataTestBuilder method build.

public TransactionData build() {
    when(tx.getRootTracer()).thenReturn(tracer);
    if (synJobId == null || synMonitorId == null || synResourceId == null) {
        when(tx.isSynthetic()).thenReturn(false);
    } else {
        when(tx.isSynthetic()).thenReturn(true);
    }
    when(tx.getGuid()).thenReturn("guid");
    Dispatcher mockDispatcher = mock(Dispatcher.class);
    when(mockDispatcher.getUri()).thenReturn(requestUri);
    when(mockDispatcher.isWebTransaction()).thenReturn(dispatcher == null ? true : dispatcher.isWebTransaction());
    when(tx.getDispatcher()).thenReturn(mockDispatcher);
    if (throwable != null) {
        when(tx.getThrowable()).thenReturn(new TransactionThrowable(throwable, expectedError, null));
    }
    PriorityTransactionName priorityTransactionName = mock(PriorityTransactionName.class);
    when(priorityTransactionName.getName()).thenReturn(frontendMetricName);
    when(tx.getPriorityTransactionName()).thenReturn(priorityTransactionName);
    Map<String, Map<String, String>> prefixed = new HashMap<>();
    prefixed.put("request.parameters.", requestParams);
    when(tx.getPrefixedAgentAttributes()).thenReturn(prefixed);
    when(tx.getUserAttributes()).thenReturn(userParams);
    when(tx.getAgentAttributes()).thenReturn(agentParams);
    when(tx.getErrorAttributes()).thenReturn(errorParams);
    when(tx.getIntrinsicAttributes()).thenReturn(intrinsics);
    when(tx.isIgnore()).thenReturn(false);
    when(tx.getStatus()).thenReturn(responseStatus);
    when(tx.getStatusMessage()).thenReturn(statusMessage);
    when(tx.isErrorReportableAndNotIgnored()).thenReturn(true);
    when(tx.getSpanProxy()).thenReturn(new SpanProxy());
    ErrorServiceImpl errorService = mock(ErrorServiceImpl.class);
    IRPMService rpmService = mock(IRPMService.class);
    when(rpmService.getApplicationName()).thenReturn(appName);
    when(rpmService.getErrorService()).thenReturn(errorService);
    when(tx.getRPMService()).thenReturn(rpmService);
    when(tx.getAgentConfig()).thenReturn(agentConfig);
    when(tx.getWallClockStartTimeMs()).thenReturn(startTime);
    if (slowQueryListener != null) {
        when(tx.getSlowQueryListener(anyBoolean())).thenReturn(slowQueryListener);
    }
    when(tx.getTracers()).thenReturn(tracers);
    CrossProcessTransactionState crossProcessTransactionState = mock(CrossProcessTransactionState.class);
    when(tx.getCrossProcessTransactionState()).thenReturn(crossProcessTransactionState);
    when(crossProcessTransactionState.getTripId()).thenReturn("tripId");
    InboundHeaderState ihs = mock(InboundHeaderState.class);
    when(ihs.getSyntheticsJobId()).thenReturn(synJobId);
    when(ihs.getSyntheticsMonitorId()).thenReturn(synMonitorId);
    when(ihs.getSyntheticsResourceId()).thenReturn(synResourceId);
    when(ihs.getSyntheticsVersion()).thenReturn(HeadersUtil.SYNTHETICS_MIN_VERSION);
    when(tx.getInboundHeaderState()).thenReturn(ihs);
    TransactionTimer timer = new TransactionTimer(tracer.getStartTime());
    timer.markTransactionActivityAsDone(tracer.getEndTime(), tracer.getDuration());
    timer.markTransactionAsDone();
    when(tx.getTransactionTimer()).thenReturn(timer);
    // when(tx.getApplicationName()).thenReturn(appName);
    Set<TransactionActivity> activities = new HashSet<>();
    for (Map.Entry<Long, Collection<Duration>> entry : threadIdToDuration.asMap().entrySet()) {
        for (Duration duration : entry.getValue()) {
            TransactionActivity activity = mock(TransactionActivity.class);
            when(activity.getThreadId()).thenReturn(entry.getKey());
            Tracer rootTracer = mock(Tracer.class);
            when(rootTracer.getStartTime()).thenReturn(duration.startTime);
            when(rootTracer.getEndTime()).thenReturn(duration.endTime);
            when(activity.getRootTracer()).thenReturn(rootTracer);
            activities.add(activity);
        }
    }
    when(tx.getFinishedChildren()).thenReturn(activities);
    if (includeDistributedTracePayload) {
        SpanProxy spanProxy = mock(SpanProxy.class);
        DistributedTracePayloadImpl payload = DistributedTracePayloadImpl.createDistributedTracePayload("abc", "def", "def", new Random().nextFloat());
        when(spanProxy.getInboundDistributedTracePayload()).thenReturn(payload);
        when(tx.getSpanProxy()).thenReturn(spanProxy);
    }
    return new TransactionData(tx, 0);
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) SpanProxy(com.newrelic.agent.tracing.SpanProxy) Tracer(com.newrelic.agent.tracers.Tracer) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Random(java.util.Random) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) Collection(java.util.Collection) TransactionTimer(com.newrelic.agent.transaction.TransactionTimer) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with ErrorServiceImpl

use of com.newrelic.agent.errors.ErrorServiceImpl 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 3 with ErrorServiceImpl

use of com.newrelic.agent.errors.ErrorServiceImpl in project newrelic-java-agent by newrelic.

the class RequestUriConfigTests method createServiceManager.

private void createServiceManager(Map<String, Object> configMap) throws Exception {
    ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(configMap);
    MockServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.setHarvestService(new MockHarvestService());
    serviceManager.setSqlTraceService(new SqlTraceServiceImpl());
    serviceManager.setAttributesService(new AttributesService());
    serviceManager.setNormalizationService(new NormalizationServiceImpl());
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName(serviceManager.getConfigService().getDefaultAgentConfig().getApplicationName());
    rpmService.setEverConnected(true);
    rpmService.setIsConnected(true);
    rpmService.setErrorService(new ErrorServiceImpl(serviceManager.getConfigService().getDefaultAgentConfig().getApplicationName()));
    rpmServiceManager.setRPMService(rpmService);
    serviceManager.start();
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) SqlTraceServiceImpl(com.newrelic.agent.sql.SqlTraceServiceImpl) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) NormalizationServiceImpl(com.newrelic.agent.normalization.NormalizationServiceImpl)

Example 4 with ErrorServiceImpl

use of com.newrelic.agent.errors.ErrorServiceImpl in project newrelic-java-agent by newrelic.

the class BrowserConfigTest method setupManager.

public void setupManager(boolean captureParams, boolean setSslForHttpToTrue) {
    MockServiceManager manager = new MockServiceManager();
    ServiceFactory.setServiceManager(manager);
    Map<String, Object> params = new HashMap<>();
    if (captureParams || setSslForHttpToTrue) {
        Map<String, Object> bProps = new HashMap<>();
        params.put("browser_monitoring", bProps);
        if (captureParams) {
            Map<String, Object> baProps = new HashMap<>();
            bProps.put("attributes", baProps);
            baProps.put("enabled", Boolean.TRUE);
        }
        if (setSslForHttpToTrue) {
            bProps.put("ssl_for_http", Boolean.TRUE);
        }
    }
    params.put("license_key", LICENSE_KEY);
    ImmutableMap<String, Object> distributedTracingSettings = ImmutableMap.<String, Object>builder().put(DistributedTracingConfig.ENABLED, Boolean.FALSE).build();
    params.put(AgentConfigImpl.DISTRIBUTED_TRACING, distributedTracingSettings);
    manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(params));
    manager.setTransactionService(new TransactionService());
    manager.setTransactionTraceService(new TransactionTraceService());
    MockRPMServiceManager rpmServiceMgr = new MockRPMServiceManager();
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName(APP_NAME);
    rpmService.setEverConnected(true);
    rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
    rpmServiceMgr.setRPMService(rpmService);
    manager.setRPMServiceManager(rpmServiceMgr);
    AttributesService attService = new AttributesService();
    manager.setAttributesService(attService);
    ServiceFactory.setServiceManager(manager);
    Transaction.clearTransaction();
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) MockRPMService(com.newrelic.agent.MockRPMService)

Example 5 with ErrorServiceImpl

use of com.newrelic.agent.errors.ErrorServiceImpl 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)

Aggregations

ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)34 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)22 TransactionService (com.newrelic.agent.TransactionService)19 MockRPMService (com.newrelic.agent.MockRPMService)17 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)17 ConfigService (com.newrelic.agent.config.ConfigService)17 MockServiceManager (com.newrelic.agent.MockServiceManager)16 StatsService (com.newrelic.agent.stats.StatsService)16 MockCoreService (com.newrelic.agent.MockCoreService)13 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)13 MockHarvestService (com.newrelic.agent.MockHarvestService)12 ThreadService (com.newrelic.agent.ThreadService)12 HarvestService (com.newrelic.agent.HarvestService)11 AttributesService (com.newrelic.agent.attributes.AttributesService)11 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)9 AgentConfig (com.newrelic.agent.config.AgentConfig)8 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)8 HashMap (java.util.HashMap)8 NormalizationServiceImpl (com.newrelic.agent.normalization.NormalizationServiceImpl)7 Test (org.junit.Test)7