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);
}
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);
}
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");
}
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);
}
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();
}
Aggregations