Search in sources :

Example 1 with Configuration

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration in project ApplicationInsights-Java by microsoft.

the class RpConfigurationPollingTest method shouldUpdate.

@Test
void shouldUpdate() throws URISyntaxException {
    // given
    RpConfiguration rpConfiguration = new RpConfiguration();
    rpConfiguration.connectionString = "InstrumentationKey=11111111-1111-1111-1111-111111111111";
    rpConfiguration.sampling.percentage = 90;
    rpConfiguration.configPath = Paths.get(RpConfigurationPollingTest.class.getResource("/applicationinsights-rp.json").toURI());
    rpConfiguration.lastModifiedTime = 0;
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setConnectionString("InstrumentationKey=00000000-0000-0000-0000-000000000000");
    AppIdSupplier appIdSupplier = new AppIdSupplier(telemetryClient);
    BytecodeUtilImpl.samplingPercentage = 100;
    // pre-check
    assertThat(telemetryClient.getInstrumentationKey()).isEqualTo("00000000-0000-0000-0000-000000000000");
    assertThat(BytecodeUtilImpl.samplingPercentage).isEqualTo(100);
    assertThat(getCurrentSamplingPercentage()).isEqualTo(100);
    // when
    new RpConfigurationPolling(rpConfiguration, new Configuration(), telemetryClient, appIdSupplier).run();
    // then
    assertThat(telemetryClient.getInstrumentationKey()).isEqualTo("00000000-0000-0000-0000-000000000000");
    assertThat(BytecodeUtilImpl.samplingPercentage).isEqualTo(10);
    assertThat(getCurrentSamplingPercentage()).isEqualTo(10);
}
Also used : Configuration(com.microsoft.applicationinsights.agent.internal.configuration.Configuration) RpConfiguration(com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration) RpConfiguration(com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Test(org.junit.jupiter.api.Test)

Example 2 with Configuration

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration in project ApplicationInsights-Java by microsoft.

the class RpConfigurationPollingTest method shouldBePopulatedByEnvVars.

@Test
void shouldBePopulatedByEnvVars() throws URISyntaxException {
    // given
    RpConfiguration rpConfiguration = new RpConfiguration();
    rpConfiguration.connectionString = "InstrumentationKey=11111111-1111-1111-1111-111111111111";
    rpConfiguration.sampling.percentage = 90;
    rpConfiguration.configPath = Paths.get(RpConfigurationPollingTest.class.getResource("/applicationinsights-rp.json").toURI());
    rpConfiguration.lastModifiedTime = 0;
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setConnectionString("InstrumentationKey=00000000-0000-0000-0000-000000000000");
    AppIdSupplier appIdSupplier = new AppIdSupplier(telemetryClient);
    BytecodeUtilImpl.samplingPercentage = 100;
    envVars.set("APPLICATIONINSIGHTS_CONNECTION_STRING", "InstrumentationKey=00000000-0000-0000-0000-000000000000");
    envVars.set("APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE", "90");
    // pre-check
    assertThat(telemetryClient.getInstrumentationKey()).isEqualTo("00000000-0000-0000-0000-000000000000");
    assertThat(BytecodeUtilImpl.samplingPercentage).isEqualTo(100);
    assertThat(getCurrentSamplingPercentage()).isEqualTo(100);
    // when
    new RpConfigurationPolling(rpConfiguration, new Configuration(), telemetryClient, appIdSupplier).run();
    // then
    assertThat(telemetryClient.getInstrumentationKey()).isEqualTo("00000000-0000-0000-0000-000000000000");
    assertThat(BytecodeUtilImpl.samplingPercentage).isEqualTo(100);
    assertThat(getCurrentSamplingPercentage()).isEqualTo(100);
}
Also used : Configuration(com.microsoft.applicationinsights.agent.internal.configuration.Configuration) RpConfiguration(com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration) RpConfiguration(com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Test(org.junit.jupiter.api.Test)

Example 3 with Configuration

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration in project ApplicationInsights-Java by microsoft.

the class CustomDimensionsTest method testCustomDimensionsConfigShouldNotImpactStatsbeatCustomDimensions.

@Test
public void testCustomDimensionsConfigShouldNotImpactStatsbeatCustomDimensions() {
    Configuration configuration = new Configuration();
    configuration.customDimensions.put("firstTag", "abc");
    configuration.customDimensions.put("secondTag", "def");
    TelemetryClient telemetryClient = TelemetryClient.builder().setCustomDimensions(configuration.customDimensions).build();
    NetworkStatsbeat networkStatsbeat = new NetworkStatsbeat();
    TelemetryItem networkItem = networkStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-network", 0.0);
    assertThat(networkItem.getTags()).doesNotContainKey("firstTag");
    assertThat(networkItem.getTags()).doesNotContainKey("secondTag");
    assertThat(((MetricsData) networkItem.getData().getBaseData()).getProperties()).doesNotContainKey("firstTag");
    assertThat(((MetricsData) networkItem.getData().getBaseData()).getProperties()).doesNotContainKey("secondTag");
    AttachStatsbeat attachStatsbeat = new AttachStatsbeat(new CustomDimensions());
    TelemetryItem attachItem = attachStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-attach", 0.0);
    assertThat(attachItem.getTags()).doesNotContainKey("firstTag");
    assertThat(attachItem.getTags()).doesNotContainKey("secondTag");
    assertThat(((MetricsData) attachItem.getData().getBaseData()).getProperties()).doesNotContainKey("firstTag");
    assertThat(((MetricsData) attachItem.getData().getBaseData()).getProperties()).doesNotContainKey("secondTag");
    FeatureStatsbeat featureStatsbeat = new FeatureStatsbeat(new CustomDimensions(), FeatureType.FEATURE);
    TelemetryItem featureItem = featureStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-feature", 0.0);
    assertThat(featureItem.getTags()).doesNotContainKey("firstTag");
    assertThat(featureItem.getTags()).doesNotContainKey("secondTag");
    assertThat(((MetricsData) featureItem.getData().getBaseData()).getProperties()).doesNotContainKey("firstTag");
    assertThat(((MetricsData) featureItem.getData().getBaseData()).getProperties()).doesNotContainKey("secondTag");
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) Configuration(com.microsoft.applicationinsights.agent.internal.configuration.Configuration) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Test(org.junit.jupiter.api.Test)

Example 4 with Configuration

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration in project ApplicationInsights-Java by microsoft.

the class FeatureStatsbeatTest method testFeature.

private static void testFeature(BiConsumer<Configuration, Boolean> init, Feature feature, boolean configValue, boolean featureValue) {
    // given
    FeatureStatsbeat featureStatsbeat = new FeatureStatsbeat(new CustomDimensions(), FeatureType.FEATURE);
    Configuration config = newConfiguration();
    init.accept(config, configValue);
    // when
    featureStatsbeat.trackConfigurationOptions(config);
    // then
    assertThat(getBitAtIndex(featureStatsbeat.getFeature(), feature.getBitmapIndex())).isEqualTo(featureValue);
}
Also used : Configuration(com.microsoft.applicationinsights.agent.internal.configuration.Configuration)

Example 5 with Configuration

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration in project ApplicationInsights-Java by microsoft.

the class OpenTelemetryConfigurer method createExporter.

private static BatchSpanProcessor createExporter(Configuration configuration) {
    List<ProcessorConfig> processors = configuration.preview.processors.stream().filter(processor -> processor.type != Configuration.ProcessorType.METRIC_FILTER).collect(Collectors.toCollection(ArrayList::new));
    // Reversing the order of processors before passing it to SpanProcessor
    Collections.reverse(processors);
    SpanExporter currExporter = new Exporter(TelemetryClient.getActive(), configuration.preview.captureHttpServer4xxAsError);
    // flushing TelemetryClient
    if (!processors.isEmpty()) {
        for (ProcessorConfig processorConfig : processors) {
            switch(processorConfig.type) {
                case ATTRIBUTE:
                    currExporter = new ExporterWithAttributeProcessor(processorConfig, currExporter);
                    break;
                case SPAN:
                    currExporter = new ExporterWithSpanProcessor(processorConfig, currExporter);
                    break;
                case LOG:
                    currExporter = new ExporterWithLogProcessor(processorConfig, currExporter);
                    break;
                default:
                    throw new IllegalStateException("Not an expected ProcessorType: " + processorConfig.type);
            }
        }
        // this is temporary until semantic attributes stabilize and we make breaking change
        // then can use java.util.functions.Predicate<Attributes>
        currExporter = new BackCompatHttpUrlProcessor(currExporter);
    }
    // using BatchSpanProcessor in order to get off of the application thread as soon as possible
    BatchSpanProcessorBuilder builder = BatchSpanProcessor.builder(currExporter);
    String delayMillisStr = System.getenv("APPLICATIONINSIGHTS_PREVIEW_BSP_SCHEDULE_DELAY");
    if (delayMillisStr != null) {
        // experimenting with flushing at small interval instead of using batch size 1
        // (suspect this may be better performance on small containers)
        builder.setScheduleDelay(Duration.ofMillis(Integer.parseInt(delayMillisStr)));
    } else {
        // using batch size 1 because need to convert to SpanData as soon as possible to grab data for
        // live metrics. the real batching is done at a lower level
        builder.setMaxExportBatchSize(1);
    }
    return builder.build();
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) AiLegacyHeaderSpanProcessor(com.microsoft.applicationinsights.agent.internal.legacyheaders.AiLegacyHeaderSpanProcessor) Samplers(com.microsoft.applicationinsights.agent.internal.sampling.Samplers) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) DelegatingPropagator(com.microsoft.applicationinsights.agent.internal.legacyheaders.DelegatingPropagator) ArrayList(java.util.ArrayList) SdkTracerProviderConfigurer(io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Duration(java.time.Duration) DelegatingSampler(com.microsoft.applicationinsights.agent.internal.sampling.DelegatingSampler) BatchSpanProcessor(io.opentelemetry.sdk.trace.export.BatchSpanProcessor) Configuration(com.microsoft.applicationinsights.agent.internal.configuration.Configuration) Collection(java.util.Collection) ExporterWithLogProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithLogProcessor) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) SdkTracerProviderBuilder(io.opentelemetry.sdk.trace.SdkTracerProviderBuilder) Collectors(java.util.stream.Collectors) MySpanData(com.microsoft.applicationinsights.agent.internal.processors.MySpanData) AttributesBuilder(io.opentelemetry.api.common.AttributesBuilder) Exporter(com.microsoft.applicationinsights.agent.internal.exporter.Exporter) List(java.util.List) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) AutoService(com.google.auto.service.AutoService) SpanData(io.opentelemetry.sdk.trace.data.SpanData) ExporterWithAttributeProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithAttributeProcessor) ExporterWithSpanProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithSpanProcessor) BatchSpanProcessorBuilder(io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder) Collections(java.util.Collections) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) ExporterWithSpanProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithSpanProcessor) ExporterWithLogProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithLogProcessor) ExporterWithAttributeProcessor(com.microsoft.applicationinsights.agent.internal.processors.ExporterWithAttributeProcessor) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) BatchSpanProcessorBuilder(io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Exporter(com.microsoft.applicationinsights.agent.internal.exporter.Exporter) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig)

Aggregations

Configuration (com.microsoft.applicationinsights.agent.internal.configuration.Configuration)8 TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)6 RpConfiguration (com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration)3 Test (org.junit.jupiter.api.Test)3 ProcessorConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig)2 AiLegacyHeaderSpanProcessor (com.microsoft.applicationinsights.agent.internal.legacyheaders.AiLegacyHeaderSpanProcessor)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 AutoService (com.google.auto.service.AutoService)1 FriendlyException (com.microsoft.applicationinsights.agent.internal.common.FriendlyException)1 ProfilerConfiguration (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProfilerConfiguration)1 Exporter (com.microsoft.applicationinsights.agent.internal.exporter.Exporter)1 MetricsData (com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData)1 TelemetryItem (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)1 DelegatingPropagator (com.microsoft.applicationinsights.agent.internal.legacyheaders.DelegatingPropagator)1 BytecodeUtilImpl (com.microsoft.applicationinsights.agent.internal.legacysdk.BytecodeUtilImpl)1 ExporterWithAttributeProcessor (com.microsoft.applicationinsights.agent.internal.processors.ExporterWithAttributeProcessor)1 ExporterWithLogProcessor (com.microsoft.applicationinsights.agent.internal.processors.ExporterWithLogProcessor)1 ExporterWithSpanProcessor (com.microsoft.applicationinsights.agent.internal.processors.ExporterWithSpanProcessor)1 MySpanData (com.microsoft.applicationinsights.agent.internal.processors.MySpanData)1 DelegatingSampler (com.microsoft.applicationinsights.agent.internal.sampling.DelegatingSampler)1