Search in sources :

Example 1 with AgentConfigImpl

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

the class HibernateStatsTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    final NoopSamplerService samplerService = new NoopSamplerService() {

        @Override
        public Closeable addSampler(Runnable sampler, long period, TimeUnit timeUnit) {
            samplers.add(sampler);
            return null;
        }
    };
    ConfigService configService = spy(ServiceFactory.getConfigService());
    AgentConfigImpl agentConfig = spy((AgentConfigImpl) configService.getDefaultAgentConfig());
    doReturn(true).when(agentConfig).getValue("instrumentation.hibernate.stats_sampler.enabled", false);
    doReturn(agentConfig).when(configService).getDefaultAgentConfig();
    ServiceManager serviceManager = spy(ServiceFactory.getServiceManager());
    doReturn(samplerService).when(serviceManager).getSamplerService();
    doReturn(configService).when(serviceManager).getConfigService();
    ServiceFactory.setServiceManager(serviceManager);
}
Also used : AgentConfigImpl(com.newrelic.agent.config.AgentConfigImpl) ConfigService(com.newrelic.agent.config.ConfigService) ServiceManager(com.newrelic.agent.service.ServiceManager) TimeUnit(java.util.concurrent.TimeUnit) NoopSamplerService(com.newrelic.agent.samplers.NoopSamplerService) BeforeClass(org.junit.BeforeClass)

Example 2 with AgentConfigImpl

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

the class AgentLinkingMetadataTest method getLinkingMetadata.

@Test
public void getLinkingMetadata() {
    // Given
    final String expectedTraceId = "traceId1234";
    final String expectedSpanId = "spanId5678";
    final String expectedEntityGuid = "entityGuid91011";
    final String expectedEntityName = "entityName91011";
    final String expectedEntityType = AgentLinkingMetadata.ENTITY_TYPE_DEFAULT;
    TraceMetadataImpl traceMetadataMock = mock(TraceMetadataImpl.class);
    ServiceManagerImpl serviceManagerMock = mock(ServiceManagerImpl.class);
    RPMServiceManagerImpl rpmServiceManagerMock = mock(RPMServiceManagerImpl.class);
    RPMService rpmServiceMock = mock(RPMService.class);
    ConfigServiceImpl configServiceMock = mock(ConfigServiceImpl.class);
    AgentConfigImpl agentConfigMock = mock(AgentConfigImpl.class);
    ServiceFactory.setServiceManager(serviceManagerMock);
    // When
    when(traceMetadataMock.getTraceId()).thenReturn(expectedTraceId);
    when(traceMetadataMock.getSpanId()).thenReturn(expectedSpanId);
    when(serviceManagerMock.getRPMServiceManager()).thenReturn(rpmServiceManagerMock);
    when(serviceManagerMock.getConfigService()).thenReturn(configServiceMock);
    when(rpmServiceManagerMock.getRPMService()).thenReturn(rpmServiceMock);
    when(configServiceMock.getDefaultAgentConfig()).thenReturn(agentConfigMock);
    when(agentConfigMock.getApplicationName()).thenReturn(expectedEntityName);
    when(rpmServiceMock.getEntityGuid()).thenReturn(expectedEntityGuid);
    // Then
    Map<String, String> linkingMetadata = AgentLinkingMetadata.getLinkingMetadata(traceMetadataMock, ServiceFactory.getConfigService(), ServiceFactory.getRPMService());
    assertFalse("linkingMetadata map shouldn't be empty", linkingMetadata.isEmpty());
    // Can't assert on a specific hostname value as it will resolve to the actual hostname of the machine running the test
    assertFalse("hostname shouldn't be empty", linkingMetadata.get(AgentLinkingMetadata.HOSTNAME).isEmpty());
    assertEquals(expectedEntityGuid, linkingMetadata.get(AgentLinkingMetadata.ENTITY_GUID));
    assertEquals(expectedEntityName, linkingMetadata.get(AgentLinkingMetadata.ENTITY_NAME));
    assertEquals(expectedEntityType, linkingMetadata.get(AgentLinkingMetadata.ENTITY_TYPE));
    assertEquals(expectedTraceId, linkingMetadata.get(AgentLinkingMetadata.TRACE_ID));
    assertEquals(expectedSpanId, linkingMetadata.get(AgentLinkingMetadata.SPAN_ID));
}
Also used : AgentConfigImpl(com.newrelic.agent.config.AgentConfigImpl) ServiceManagerImpl(com.newrelic.agent.service.ServiceManagerImpl) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) Test(org.junit.Test)

Example 3 with AgentConfigImpl

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

the class CrossProcessAndSyntheticsConfigTest method testConfig.

// The "expected value" arguments are all about the newrelic.yml. We're not varying the collector JSON here.
public void testConfig(String ymlFilePath, boolean expectedValueOfCatEnable, boolean expectedValueOfBrowserEnabled) throws Exception {
    System.setProperty("newrelic.config.file", ymlFilePath);
    ConfigService configService = ConfigServiceFactory.createConfigService(mock(Logger.class), false);
    AgentConfig agentConfig = configService.getAgentConfig(appName);
    assertEquals(appName, agentConfig.getApplicationName());
    assertTrue(agentConfig instanceof AgentConfigImpl);
    assertTrue(configService instanceof ConfigServiceImpl);
    IRPMService rpmService = mock(IRPMService.class);
    Mockito.when(rpmService.getApplicationName()).thenReturn(appName);
    org.json.simple.parser.JSONParser parser = new org.json.simple.parser.JSONParser();
    @SuppressWarnings("unchecked") Map<String, Object> serverData = (Map<String, Object>) parser.parse(collectorJson);
    ((ConfigServiceImpl) configService).connected(rpmService, serverData);
    assertEquals(configService.getAgentConfig(appName).getBrowserMonitoringConfig().isAutoInstrumentEnabled(), expectedValueOfBrowserEnabled);
    assertEquals(configService.getAgentConfig(appName).getCrossProcessConfig().isCrossApplicationTracing(), expectedValueOfCatEnable);
    String s = configService.getAgentConfig(appName).getValue("cross_application_tracer.encoding_key");
    assertEquals(s, encodingKey);
}
Also used : Logger(com.newrelic.api.agent.Logger) AgentConfig(com.newrelic.agent.config.AgentConfig) AgentConfigImpl(com.newrelic.agent.config.AgentConfigImpl) ConfigService(com.newrelic.agent.config.ConfigService) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) Map(java.util.Map)

Example 4 with AgentConfigImpl

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

the class AgentLinkingMetadataTest method getLogEventLinkingMetadataWithEmptyTraceAttributes.

@Test
public void getLogEventLinkingMetadataWithEmptyTraceAttributes() {
    // Given
    final String expectedTraceId = "";
    final String expectedSpanId = "";
    final String expectedEntityGuid = "entityGuid91011";
    final String expectedEntityName = "entityName91011";
    TraceMetadataImpl traceMetadataMock = mock(TraceMetadataImpl.class);
    ServiceManagerImpl serviceManagerMock = mock(ServiceManagerImpl.class);
    RPMServiceManagerImpl rpmServiceManagerMock = mock(RPMServiceManagerImpl.class);
    RPMService rpmServiceMock = mock(RPMService.class);
    ConfigServiceImpl configServiceMock = mock(ConfigServiceImpl.class);
    AgentConfigImpl agentConfigMock = mock(AgentConfigImpl.class);
    ServiceFactory.setServiceManager(serviceManagerMock);
    // When
    when(traceMetadataMock.getTraceId()).thenReturn(expectedTraceId);
    when(traceMetadataMock.getSpanId()).thenReturn(expectedSpanId);
    when(serviceManagerMock.getRPMServiceManager()).thenReturn(rpmServiceManagerMock);
    when(serviceManagerMock.getConfigService()).thenReturn(configServiceMock);
    when(rpmServiceManagerMock.getRPMService()).thenReturn(rpmServiceMock);
    when(configServiceMock.getDefaultAgentConfig()).thenReturn(agentConfigMock);
    when(agentConfigMock.getApplicationName()).thenReturn(expectedEntityName);
    when(rpmServiceMock.getEntityGuid()).thenReturn(expectedEntityGuid);
    // Then
    Map<String, String> linkingMetadata = AgentLinkingMetadata.getLogEventLinkingMetadata(traceMetadataMock, ServiceFactory.getConfigService(), ServiceFactory.getRPMService());
    assertFalse("linkingMetadata map shouldn't be empty", linkingMetadata.isEmpty());
    // Can't assert on a specific hostname value as it will resolve to the actual hostname of the machine running the test
    assertFalse("hostname shouldn't be empty", linkingMetadata.get(AgentLinkingMetadata.HOSTNAME).isEmpty());
    assertFalse("entity.type should not be included in LogEvent linking metadata", linkingMetadata.containsKey(AgentLinkingMetadata.ENTITY_TYPE));
    assertEquals(expectedEntityName, linkingMetadata.get(AgentLinkingMetadata.ENTITY_NAME));
    assertEquals(expectedEntityGuid, linkingMetadata.get(AgentLinkingMetadata.ENTITY_GUID));
    // trace.id and span.id would be empty values if getLogEventLinkingMetadata was called outside of a transaction, in which case they are omitted
    assertFalse("empty trace.id value should not be included in LogEvent linking metadata", linkingMetadata.containsKey(AgentLinkingMetadata.TRACE_ID));
    assertFalse("empty span.id value should not be included in LogEvent linking metadata", linkingMetadata.containsKey(AgentLinkingMetadata.SPAN_ID));
}
Also used : AgentConfigImpl(com.newrelic.agent.config.AgentConfigImpl) ServiceManagerImpl(com.newrelic.agent.service.ServiceManagerImpl) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) Test(org.junit.Test)

Example 5 with AgentConfigImpl

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

the class AgentLinkingMetadataTest method getLinkingMetadataWithEmptyTraceAttributes.

@Test
public void getLinkingMetadataWithEmptyTraceAttributes() {
    // Given
    final String expectedTraceId = "";
    final String expectedSpanId = "";
    final String expectedEntityGuid = "entityGuid91011";
    final String expectedEntityName = "entityName91011";
    final String expectedEntityType = AgentLinkingMetadata.ENTITY_TYPE_DEFAULT;
    TraceMetadataImpl traceMetadataMock = mock(TraceMetadataImpl.class);
    ServiceManagerImpl serviceManagerMock = mock(ServiceManagerImpl.class);
    RPMServiceManagerImpl rpmServiceManagerMock = mock(RPMServiceManagerImpl.class);
    RPMService rpmServiceMock = mock(RPMService.class);
    ConfigServiceImpl configServiceMock = mock(ConfigServiceImpl.class);
    AgentConfigImpl agentConfigMock = mock(AgentConfigImpl.class);
    ServiceFactory.setServiceManager(serviceManagerMock);
    // When
    when(traceMetadataMock.getTraceId()).thenReturn(expectedTraceId);
    when(traceMetadataMock.getSpanId()).thenReturn(expectedSpanId);
    when(serviceManagerMock.getRPMServiceManager()).thenReturn(rpmServiceManagerMock);
    when(serviceManagerMock.getConfigService()).thenReturn(configServiceMock);
    when(rpmServiceManagerMock.getRPMService()).thenReturn(rpmServiceMock);
    when(configServiceMock.getDefaultAgentConfig()).thenReturn(agentConfigMock);
    when(agentConfigMock.getApplicationName()).thenReturn(expectedEntityName);
    when(rpmServiceMock.getEntityGuid()).thenReturn(expectedEntityGuid);
    // Then
    Map<String, String> linkingMetadata = AgentLinkingMetadata.getLinkingMetadata(traceMetadataMock, ServiceFactory.getConfigService(), ServiceFactory.getRPMService());
    assertFalse("linkingMetadata map shouldn't be empty", linkingMetadata.isEmpty());
    // Can't assert on a specific hostname value as it will resolve to the actual hostname of the machine running the test
    assertFalse("hostname shouldn't be empty", linkingMetadata.get(AgentLinkingMetadata.HOSTNAME).isEmpty());
    assertEquals(expectedEntityGuid, linkingMetadata.get(AgentLinkingMetadata.ENTITY_GUID));
    assertEquals(expectedEntityName, linkingMetadata.get(AgentLinkingMetadata.ENTITY_NAME));
    assertEquals(expectedEntityType, linkingMetadata.get(AgentLinkingMetadata.ENTITY_TYPE));
    // trace.id and span.id would be empty values if getLinkingMetadata was called outside of a transaction.
    // With the getLinkingMetadata API the returned map includes keys with empty values
    assertEquals(expectedTraceId, linkingMetadata.get(AgentLinkingMetadata.TRACE_ID));
    assertEquals(expectedSpanId, linkingMetadata.get(AgentLinkingMetadata.SPAN_ID));
}
Also used : AgentConfigImpl(com.newrelic.agent.config.AgentConfigImpl) ServiceManagerImpl(com.newrelic.agent.service.ServiceManagerImpl) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) Test(org.junit.Test)

Aggregations

AgentConfigImpl (com.newrelic.agent.config.AgentConfigImpl)7 ConfigServiceImpl (com.newrelic.agent.config.ConfigServiceImpl)5 ServiceManagerImpl (com.newrelic.agent.service.ServiceManagerImpl)4 Test (org.junit.Test)4 ConfigService (com.newrelic.agent.config.ConfigService)3 BeforeClass (org.junit.BeforeClass)2 MockServiceManager (com.newrelic.agent.MockServiceManager)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 ClassTransformerConfig (com.newrelic.agent.config.ClassTransformerConfig)1 NoopSamplerService (com.newrelic.agent.samplers.NoopSamplerService)1 ServiceManager (com.newrelic.agent.service.ServiceManager)1 Logger (com.newrelic.api.agent.Logger)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1