Search in sources :

Example 1 with Consumer

use of com.newrelic.agent.interfaces.backport.Consumer in project newrelic-java-agent by newrelic.

the class WeavePackageAnalyzerTest method weavePackageConstructionReadsAttributesFromJars.

@Test
public void weavePackageConstructionReadsAttributesFromJars() {
    URL url = getClass().getResource('/' + ExtensionServiceTest.class.getPackage().getName().replace('.', '/') + '/' + ExtensionServiceTest.WEAVE_INSTRUMENTATION);
    final List<JarData> jarData = new ArrayList<>();
    Consumer<JarData> mockConsumer = new Consumer<JarData>() {

        @Override
        public void accept(JarData x) {
            jarData.add(x);
        }
    };
    WeavePackageAnalyzer target = new WeavePackageAnalyzer(new File(url.getFile()), mockConsumer, mock(Logger.class));
    target.run();
    assertEquals(1, jarData.size());
    assertEquals("com.newrelic.instrumentation.spring-jms-2", jarData.get(0).getName());
    assertEquals("1.0", jarData.get(0).getVersion());
    assertEquals(url.toString(), jarData.get(0).getJarInfo().attributes.get("weaveFile"));
    assertEquals("10ce178a632add8d5a98442a9cf1220f34c95874", jarData.get(0).getJarInfo().attributes.get("sha1Checksum"));
}
Also used : Consumer(com.newrelic.agent.interfaces.backport.Consumer) ArrayList(java.util.ArrayList) Logger(com.newrelic.api.agent.Logger) File(java.io.File) URL(java.net.URL) ExtensionServiceTest(com.newrelic.agent.extension.ExtensionServiceTest) Test(org.junit.Test)

Example 2 with Consumer

use of com.newrelic.agent.interfaces.backport.Consumer in project newrelic-java-agent by newrelic.

the class IntrospectorServiceManager method setup.

private void setup(Map<String, Object> config) {
    configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), Collections.<String, Object>emptyMap());
    ServiceFactory.setServiceManager(this);
    coreService = new IntrospectorCoreService();
    threadService = new ThreadService();
    environmentService = new EnvironmentServiceImpl();
    transactionService = new TransactionService();
    rpmConnectionService = new IntrospectorRPMConnectService();
    rpmServiceManager = new IntrospectorRPMServiceManager();
    transactionTraceService = new IntrospectorTransactionTraceService();
    asyncTxService = new AsyncTransactionService();
    profilerService = new ProfilerService();
    statsService = new IntrospectorStatsService();
    harvestService = new IntrospectorHarvestService();
    sqlTraceService = new SqlTraceServiceImpl();
    insightsService = new IntrospectorInsightsService();
    logSenderService = new IntrospectorLogSenderService();
    expirationService = new ExpirationService();
    dbService = new DatabaseService();
    jarCollectorService = new IgnoringJarCollectorService();
    distributedTraceService = new DistributedTraceServiceImpl();
    TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
    transactionEventsService = new TransactionEventsService(transactionDataToDistributedTraceIntrinsics);
    normalizationService = new NormalizationServiceImpl();
    extensionService = new ExtensionService(configService, ExtensionsLoadedListener.NOOP);
    tracerService = new TracerService();
    commandParser = new CommandParser();
    remoteInstrumentationService = new RemoteInstrumentationServiceImpl();
    sourceLanguageService = new SourceLanguageService();
    classTransformerService = new NoOpClassTransformerService();
    jmxService = new JmxService(configService.getDefaultAgentConfig().getJmxConfig());
    attributesService = new AttributesService();
    circuitBreakerService = new CircuitBreakerService();
    AgentConfig agentConfig = createAgentConfig(config, (Map) config.get("distributed_tracing"));
    distributedTraceService.connected(null, agentConfig);
    ReservoirManager<SpanEvent> reservoirManager = new CollectorSpanEventReservoirManager(configService);
    ReservoirManager.EventSender<SpanEvent> collectorSender = new CollectorSpanEventSender(rpmServiceManager);
    Consumer<SpanEvent> infiniteTracing = new Consumer<SpanEvent>() {

        @Override
        public void accept(SpanEvent spanEvent) {
        }
    };
    SpanEventCreationDecider spanEventCreationDecider = new SpanEventCreationDecider(configService);
    spanEventsService = new IntrospectorSpanEventService(agentConfig, reservoirManager, collectorSender, infiniteTracing, spanEventCreationDecider, environmentService, transactionDataToDistributedTraceIntrinsics);
    configService.addIAgentConfigListener((IntrospectorSpanEventService) spanEventsService);
    transactionService.addTransactionListener((IntrospectorSpanEventService) spanEventsService);
    try {
        transactionTraceService.start();
        transactionEventsService.start();
        transactionService.start();
    } catch (Exception e) {
    // fall through
    }
}
Also used : ReservoirManager(com.newrelic.agent.interfaces.ReservoirManager) CommandParser(com.newrelic.agent.commands.CommandParser) Consumer(com.newrelic.agent.interfaces.backport.Consumer) ProfilerService(com.newrelic.agent.profile.ProfilerService) CircuitBreakerService(com.newrelic.agent.circuitbreaker.CircuitBreakerService) NormalizationServiceImpl(com.newrelic.agent.normalization.NormalizationServiceImpl) ExtensionService(com.newrelic.agent.extension.ExtensionService) RemoteInstrumentationServiceImpl(com.newrelic.agent.reinstrument.RemoteInstrumentationServiceImpl) SqlTraceServiceImpl(com.newrelic.agent.sql.SqlTraceServiceImpl) AsyncTransactionService(com.newrelic.agent.service.async.AsyncTransactionService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) JmxService(com.newrelic.agent.jmx.JmxService) AttributesService(com.newrelic.agent.attributes.AttributesService) AsyncTransactionService(com.newrelic.agent.service.async.AsyncTransactionService) DatabaseService(com.newrelic.agent.database.DatabaseService) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) SpanEvent(com.newrelic.agent.model.SpanEvent) SourceLanguageService(com.newrelic.agent.language.SourceLanguageService)

Example 3 with Consumer

use of com.newrelic.agent.interfaces.backport.Consumer in project newrelic-java-agent by newrelic.

the class SpanEventsServiceTest method before.

@Before
public void before() throws Exception {
    MockitoAnnotations.initMocks(this);
    serviceManager = new MockServiceManager();
    Map<String, Object> localSettings = new HashMap<>();
    localSettings.put(AgentConfigImpl.APP_NAME, APP_NAME);
    localSettings.put("distributed_tracing", Collections.singletonMap("enabled", true));
    localSettings.put("span_events", Collections.singletonMap("collect_span_events", true));
    when(spanEventCreationDecider.shouldCreateSpans(any(TransactionData.class))).thenReturn(true);
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, localSettings, new HashMap<String, Object>());
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, localSettings);
    serviceManager.setConfigService(configService);
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.setTransactionService(new TransactionService());
    serviceManager.setThreadService(new ThreadService());
    final MockSpanEventReservoirManager reservoirManager = new MockSpanEventReservoirManager(configService);
    Consumer<SpanEvent> backendConsumer = spanEvent -> reservoirManager.getOrCreateReservoir(APP_NAME).add(spanEvent);
    SpanErrorBuilder defaultSpanErrorBuilder = new SpanErrorBuilder(new ErrorAnalyzerImpl(agentConfig.getErrorCollectorConfig()), new ErrorMessageReplacer(agentConfig.getStripExceptionConfig()));
    Map<String, SpanErrorBuilder> map = new HashMap<>();
    map.put(agentConfig.getApplicationName(), defaultSpanErrorBuilder);
    EnvironmentService environmentService = mock(EnvironmentService.class, RETURNS_DEEP_STUBS);
    TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = mock(TransactionDataToDistributedTraceIntrinsics.class);
    when(transactionDataToDistributedTraceIntrinsics.buildDistributedTracingIntrinsics(any(TransactionData.class), anyBoolean())).thenReturn(Collections.<String, Object>emptyMap());
    TracerToSpanEvent tracerToSpanEvent = new TracerToSpanEvent(map, environmentService, transactionDataToDistributedTraceIntrinsics, defaultSpanErrorBuilder);
    SpanEventsServiceImpl spanEventsService = SpanEventsServiceImpl.builder().agentConfig(agentConfig).reservoirManager(reservoirManager).collectorSender(mock(CollectorSpanEventSender.class)).eventBackendStorage(backendConsumer).spanEventCreationDecider(spanEventCreationDecider).tracerToSpanEvent(tracerToSpanEvent).build();
    serviceManager.setSpansEventService(spanEventsService);
    serviceManager.setAttributesService(new AttributesService());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) AttributesService(com.newrelic.agent.attributes.AttributesService) TransactionStats(com.newrelic.agent.stats.TransactionStats) HashMap(java.util.HashMap) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) MockitoAnnotations(org.mockito.MockitoAnnotations) After(org.junit.After) Map(java.util.Map) Before(org.junit.Before) ErrorMessageReplacer(com.newrelic.agent.errors.ErrorMessageReplacer) Tracer(com.newrelic.agent.tracers.Tracer) Test(org.junit.Test) SpanEvent(com.newrelic.agent.model.SpanEvent) com.newrelic.agent.config(com.newrelic.agent.config) com.newrelic.agent(com.newrelic.agent) Mockito(org.mockito.Mockito) ErrorAnalyzerImpl(com.newrelic.agent.errors.ErrorAnalyzerImpl) SERVER_SPAN_HARVEST_CONFIG(com.newrelic.agent.config.SpanEventsConfig.SERVER_SPAN_HARVEST_CONFIG) SamplingPriorityQueue(com.newrelic.agent.interfaces.SamplingPriorityQueue) Consumer(com.newrelic.agent.interfaces.backport.Consumer) SpanCategory(com.newrelic.agent.model.SpanCategory) Collections(java.util.Collections) ServiceFactory(com.newrelic.agent.service.ServiceFactory) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) ErrorAnalyzerImpl(com.newrelic.agent.errors.ErrorAnalyzerImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) SpanEvent(com.newrelic.agent.model.SpanEvent) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) ErrorMessageReplacer(com.newrelic.agent.errors.ErrorMessageReplacer) Before(org.junit.Before)

Example 4 with Consumer

use of com.newrelic.agent.interfaces.backport.Consumer in project newrelic-java-agent by newrelic.

the class WeavePackageAnalyzerTest method usesWeavePackageConfigForAttributes.

@Test
public void usesWeavePackageConfigForAttributes() {
    URL url = getClass().getResource('/' + ExtensionServiceTest.class.getPackage().getName().replace('.', '/') + '/' + ExtensionServiceTest.WEAVE_INSTRUMENTATION);
    Consumer<JarData> mockConsumer = new Consumer<JarData>() {

        @Override
        public void accept(JarData x) {
        }
    };
    WeavePackageAnalyzer target = new WeavePackageAnalyzer(new File(url.getFile()), mockConsumer, mock(Logger.class));
    JarData jarData = target.getWeaveJar(new File(url.getFile()), WeavePackageConfig.builder().name("jms").version(6.66f).source(url.getPath()).build());
    assertEquals("jms", jarData.getName());
    assertEquals("6.66", jarData.getVersion());
    assertEquals(url.getFile(), jarData.getJarInfo().attributes.get("weaveFile"));
    assertEquals("10ce178a632add8d5a98442a9cf1220f34c95874", jarData.getJarInfo().attributes.get("sha1Checksum"));
}
Also used : Consumer(com.newrelic.agent.interfaces.backport.Consumer) Logger(com.newrelic.api.agent.Logger) File(java.io.File) URL(java.net.URL) ExtensionServiceTest(com.newrelic.agent.extension.ExtensionServiceTest) Test(org.junit.Test)

Aggregations

Consumer (com.newrelic.agent.interfaces.backport.Consumer)4 Test (org.junit.Test)3 AttributesService (com.newrelic.agent.attributes.AttributesService)2 ExtensionServiceTest (com.newrelic.agent.extension.ExtensionServiceTest)2 SpanEvent (com.newrelic.agent.model.SpanEvent)2 Logger (com.newrelic.api.agent.Logger)2 File (java.io.File)2 URL (java.net.URL)2 com.newrelic.agent (com.newrelic.agent)1 CircuitBreakerService (com.newrelic.agent.circuitbreaker.CircuitBreakerService)1 CommandParser (com.newrelic.agent.commands.CommandParser)1 com.newrelic.agent.config (com.newrelic.agent.config)1 SERVER_SPAN_HARVEST_CONFIG (com.newrelic.agent.config.SpanEventsConfig.SERVER_SPAN_HARVEST_CONFIG)1 DatabaseService (com.newrelic.agent.database.DatabaseService)1 EnvironmentService (com.newrelic.agent.environment.EnvironmentService)1 EnvironmentServiceImpl (com.newrelic.agent.environment.EnvironmentServiceImpl)1 ErrorAnalyzerImpl (com.newrelic.agent.errors.ErrorAnalyzerImpl)1 ErrorMessageReplacer (com.newrelic.agent.errors.ErrorMessageReplacer)1 ExtensionService (com.newrelic.agent.extension.ExtensionService)1 ReservoirManager (com.newrelic.agent.interfaces.ReservoirManager)1