From cf5b04876235abbfdc01a6638c55578a54176b94 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 11 Nov 2021 14:53:46 -0800 Subject: [PATCH 1/9] Option 1 --- .../internal/configuration/Configuration.java | 1 + .../configuration/ConfigurationBuilder.java | 4 +++ .../agent/internal/init/ConfigOverride.java | 19 +++++++++++++ .../agent/internal/statsbeat/Feature.java | 3 ++- .../internal/statsbeat/FeatureStatsbeat.java | 3 +++ .../configuration/ConfigurationTest.java | 10 +++++++ .../statsbeat/FeatureStatsbeatTest.java | 7 +++++ .../statsbeat/StatsbeatTestUtils.java | 27 +++---------------- 8 files changed, 49 insertions(+), 25 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java index f4d4cb35db2..3be9e347550 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java @@ -136,6 +136,7 @@ public static class Instrumentation { public EnabledByDefaultInstrumentation azureSdk = new EnabledByDefaultInstrumentation(); public EnabledByDefaultInstrumentation cassandra = new EnabledByDefaultInstrumentation(); + public EnabledByDefaultInstrumentation httpClient = new EnabledByDefaultInstrumentation(); public EnabledByDefaultInstrumentation jdbc = new EnabledByDefaultInstrumentation(); public EnabledByDefaultInstrumentation jms = new EnabledByDefaultInstrumentation(); public EnabledByDefaultInstrumentation kafka = new EnabledByDefaultInstrumentation(); diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java index 9840f5e9612..6278a9d8792 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java @@ -271,6 +271,10 @@ private static void overlayInstrumentationEnabledEnvVars(Configuration config) { overlayWithEnvVar( "APPLICATIONINSIGHTS_INSTRUMENTATION_CASSANDRA_ENABLED", config.instrumentation.cassandra.enabled); + config.instrumentation.httpClient.enabled = + overlayWithEnvVar( + "APPLICATIONINSIGHTS_INSTRUMENTATION_HTTP_CLIENT_ENABLED", + config.instrumentation.httpClient.enabled); config.instrumentation.jdbc.enabled = overlayWithEnvVar( "APPLICATIONINSIGHTS_INSTRUMENTATION_JDBC_ENABLED", diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/ConfigOverride.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/ConfigOverride.java index c26e3c89ebd..5c1051c4f65 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/ConfigOverride.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/ConfigOverride.java @@ -49,6 +49,25 @@ static Config getConfig(Configuration config) { if (!config.instrumentation.cassandra.enabled) { properties.put("otel.instrumentation.cassandra.enabled", "false"); } + if (!config.instrumentation.httpClient.enabled) { + // some of these haven't been included yet, but is trying to be a bit future-proof + // note: there's currently no way to disable netty client or ameria client instrumentation + // separate from their respective server instrumentation + properties.put("otel.instrumentation.akka-http-client.enabled", "false"); + properties.put("otel.instrumentation.apache-httpasyncclient.enabled", "false"); + properties.put("otel.instrumentation.apache-httpclient.enabled", "false"); + properties.put("otel.instrumentation.async-http-client.enabled", "false"); + properties.put("otel.instrumentation.google-http-client.enabled", "false"); + properties.put("otel.instrumentation.http-url-connection.enabled", "false"); + properties.put("otel.instrumentation.java-http-client.enabled", "false"); + properties.put("otel.instrumentation.jaxrs-client.enabled", "false"); + properties.put("otel.instrumentation.jetty-httpclient.enabled", "false"); + properties.put("otel.instrumentation.okhttp.enabled", "false"); + properties.put("otel.instrumentation.play-ws.enabled", "false"); + properties.put("otel.instrumentation.spring-web.enabled", "false"); + properties.put("otel.instrumentation.spring-webflux-client.enabled", "false"); + properties.put("otel.instrumentation.vertx-client.enabled", "false"); + } if (!config.instrumentation.jdbc.enabled) { properties.put("otel.instrumentation.jdbc.enabled", "false"); } diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/Feature.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/Feature.java index d5d501e2a5c..30849135169 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/Feature.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/Feature.java @@ -53,7 +53,8 @@ enum Feature { APACHE_CAMEL_DISABLED(22), // preview instrumentation, apache camel is ON by default in OTEL AKKA_DISABLED(23), // preview instrumentation, akka is ON by default in OTEL PROPAGATION_DISABLED(24), - PLAY_DISABLED(25); // preview instrumentation, play is ON by default in OTEL + PLAY_DISABLED(25), // preview instrumentation, play is ON by default in OTEL + HTTP_CLIENT_DISABLED(7); private static final Map javaVendorFeatureMap; diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeat.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeat.java index 1e97e3cbd40..e7b08fd546c 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeat.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeat.java @@ -103,6 +103,9 @@ void trackConfigurationOptions(Configuration config) { if (!config.instrumentation.cassandra.enabled) { featureList.add(Feature.CASSANDRA_DISABLED); } + if (!config.instrumentation.httpClient.enabled) { + featureList.add(Feature.HTTP_CLIENT_DISABLED); + } if (!config.instrumentation.jdbc.enabled) { featureList.add(Feature.JDBC_DISABLED); } diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationTest.java index c5c069fcafd..899b2fc7112 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationTest.java @@ -520,6 +520,16 @@ void shouldOverrideInstrumentationCassandraEnabled() throws IOException { assertThat(configuration.instrumentation.cassandra.enabled).isFalse(); } + @Test + void shouldOverrideInstrumentationHttpClientEnabled() throws IOException { + envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_HTTP_CLIENT_ENABLED", "false"); + + Configuration configuration = loadConfiguration(); + ConfigurationBuilder.overlayFromEnv(configuration); + + assertThat(configuration.instrumentation.httpClient.enabled).isFalse(); + } + @Test void shouldOverrideInstrumentationJdbcEnabled() throws IOException { envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_JDBC_ENABLED", "false"); diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeatTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeatTest.java index 505f457e314..fae9403f99d 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeatTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeatTest.java @@ -50,6 +50,13 @@ public void testCassandraEnabled() { Feature.CASSANDRA_DISABLED); } + @Test + public void testHttpClientEnabled() { + testFeatureTrackingDisablement( + (config, enabled) -> config.instrumentation.httpClient.enabled = enabled, + Feature.HTTP_CLIENT_DISABLED); + } + @Test public void testJdbcEnabled() { testFeatureTrackingDisablement( diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/StatsbeatTestUtils.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/StatsbeatTestUtils.java index ff7dc2050e3..0a09994d9f4 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/StatsbeatTestUtils.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/StatsbeatTestUtils.java @@ -91,30 +91,9 @@ public final class StatsbeatTestUtils { INSTRUMENTATION_MAP_DECODING.put(54, "io.opentelemetry.spring-scheduling-3.1"); FEATURE_MAP_DECODING = new HashMap<>(); - FEATURE_MAP_DECODING.put(0, Feature.JAVA_VENDOR_ORACLE); - FEATURE_MAP_DECODING.put(1, Feature.JAVA_VENDOR_ZULU); - FEATURE_MAP_DECODING.put(2, Feature.JAVA_VENDOR_MICROSOFT); - FEATURE_MAP_DECODING.put(3, Feature.JAVA_VENDOR_ADOPT_OPENJDK); - FEATURE_MAP_DECODING.put(4, Feature.JAVA_VENDOR_REDHAT); - FEATURE_MAP_DECODING.put(5, Feature.JAVA_VENDOR_OTHER); - FEATURE_MAP_DECODING.put(6, Feature.AAD); - FEATURE_MAP_DECODING.put(7, Feature.CASSANDRA_DISABLED); - FEATURE_MAP_DECODING.put(8, Feature.JDBC_DISABLED); - FEATURE_MAP_DECODING.put(9, Feature.JMS_DISABLED); - FEATURE_MAP_DECODING.put(10, Feature.KAFKA_DISABLED); - FEATURE_MAP_DECODING.put(11, Feature.MICROMETER_DISABLED); - FEATURE_MAP_DECODING.put(12, Feature.MONGO_DISABLED); - FEATURE_MAP_DECODING.put(13, Feature.REDIS_DISABLED); - FEATURE_MAP_DECODING.put(14, Feature.SPRING_SCHEDULING_DISABLED); - FEATURE_MAP_DECODING.put(15, Feature.AZURE_SDK_DISABLED); - FEATURE_MAP_DECODING.put(16, Feature.RABBITMQ_DISABLED); - FEATURE_MAP_DECODING.put(17, Feature.SPRING_INTEGRATION_DISABLED); - FEATURE_MAP_DECODING.put(18, Feature.LEGACY_PROPAGATION_DISABLED); - FEATURE_MAP_DECODING.put(19, Feature.GRIZZLY_ENABLED); - FEATURE_MAP_DECODING.put(20, Feature.STATSBEAT_DISABLED); - FEATURE_MAP_DECODING.put(21, Feature.QUARTZ_DISABLED); - FEATURE_MAP_DECODING.put(22, Feature.APACHE_CAMEL_DISABLED); - FEATURE_MAP_DECODING.put(23, Feature.AKKA_DISABLED); + for (Feature feature : Feature.values()) { + FEATURE_MAP_DECODING.put(feature.getBitmapIndex(), feature); + } } static Set decodeInstrumentations(long number) { From aa88f253cb6674d5370951249270973c598814f9 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 11 Nov 2021 14:53:50 -0800 Subject: [PATCH 2/9] Revert "Option 1" This reverts commit cf5b04876235abbfdc01a6638c55578a54176b94. --- .../internal/configuration/Configuration.java | 1 - .../configuration/ConfigurationBuilder.java | 4 --- .../agent/internal/init/ConfigOverride.java | 19 ------------- .../agent/internal/statsbeat/Feature.java | 3 +-- .../internal/statsbeat/FeatureStatsbeat.java | 3 --- .../configuration/ConfigurationTest.java | 10 ------- .../statsbeat/FeatureStatsbeatTest.java | 7 ----- .../statsbeat/StatsbeatTestUtils.java | 27 ++++++++++++++++--- 8 files changed, 25 insertions(+), 49 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java index 3be9e347550..f4d4cb35db2 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java @@ -136,7 +136,6 @@ public static class Instrumentation { public EnabledByDefaultInstrumentation azureSdk = new EnabledByDefaultInstrumentation(); public EnabledByDefaultInstrumentation cassandra = new EnabledByDefaultInstrumentation(); - public EnabledByDefaultInstrumentation httpClient = new EnabledByDefaultInstrumentation(); public EnabledByDefaultInstrumentation jdbc = new EnabledByDefaultInstrumentation(); public EnabledByDefaultInstrumentation jms = new EnabledByDefaultInstrumentation(); public EnabledByDefaultInstrumentation kafka = new EnabledByDefaultInstrumentation(); diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java index 6278a9d8792..9840f5e9612 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java @@ -271,10 +271,6 @@ private static void overlayInstrumentationEnabledEnvVars(Configuration config) { overlayWithEnvVar( "APPLICATIONINSIGHTS_INSTRUMENTATION_CASSANDRA_ENABLED", config.instrumentation.cassandra.enabled); - config.instrumentation.httpClient.enabled = - overlayWithEnvVar( - "APPLICATIONINSIGHTS_INSTRUMENTATION_HTTP_CLIENT_ENABLED", - config.instrumentation.httpClient.enabled); config.instrumentation.jdbc.enabled = overlayWithEnvVar( "APPLICATIONINSIGHTS_INSTRUMENTATION_JDBC_ENABLED", diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/ConfigOverride.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/ConfigOverride.java index 5c1051c4f65..c26e3c89ebd 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/ConfigOverride.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/ConfigOverride.java @@ -49,25 +49,6 @@ static Config getConfig(Configuration config) { if (!config.instrumentation.cassandra.enabled) { properties.put("otel.instrumentation.cassandra.enabled", "false"); } - if (!config.instrumentation.httpClient.enabled) { - // some of these haven't been included yet, but is trying to be a bit future-proof - // note: there's currently no way to disable netty client or ameria client instrumentation - // separate from their respective server instrumentation - properties.put("otel.instrumentation.akka-http-client.enabled", "false"); - properties.put("otel.instrumentation.apache-httpasyncclient.enabled", "false"); - properties.put("otel.instrumentation.apache-httpclient.enabled", "false"); - properties.put("otel.instrumentation.async-http-client.enabled", "false"); - properties.put("otel.instrumentation.google-http-client.enabled", "false"); - properties.put("otel.instrumentation.http-url-connection.enabled", "false"); - properties.put("otel.instrumentation.java-http-client.enabled", "false"); - properties.put("otel.instrumentation.jaxrs-client.enabled", "false"); - properties.put("otel.instrumentation.jetty-httpclient.enabled", "false"); - properties.put("otel.instrumentation.okhttp.enabled", "false"); - properties.put("otel.instrumentation.play-ws.enabled", "false"); - properties.put("otel.instrumentation.spring-web.enabled", "false"); - properties.put("otel.instrumentation.spring-webflux-client.enabled", "false"); - properties.put("otel.instrumentation.vertx-client.enabled", "false"); - } if (!config.instrumentation.jdbc.enabled) { properties.put("otel.instrumentation.jdbc.enabled", "false"); } diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/Feature.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/Feature.java index 30849135169..d5d501e2a5c 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/Feature.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/Feature.java @@ -53,8 +53,7 @@ enum Feature { APACHE_CAMEL_DISABLED(22), // preview instrumentation, apache camel is ON by default in OTEL AKKA_DISABLED(23), // preview instrumentation, akka is ON by default in OTEL PROPAGATION_DISABLED(24), - PLAY_DISABLED(25), // preview instrumentation, play is ON by default in OTEL - HTTP_CLIENT_DISABLED(7); + PLAY_DISABLED(25); // preview instrumentation, play is ON by default in OTEL private static final Map javaVendorFeatureMap; diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeat.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeat.java index e7b08fd546c..1e97e3cbd40 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeat.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeat.java @@ -103,9 +103,6 @@ void trackConfigurationOptions(Configuration config) { if (!config.instrumentation.cassandra.enabled) { featureList.add(Feature.CASSANDRA_DISABLED); } - if (!config.instrumentation.httpClient.enabled) { - featureList.add(Feature.HTTP_CLIENT_DISABLED); - } if (!config.instrumentation.jdbc.enabled) { featureList.add(Feature.JDBC_DISABLED); } diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationTest.java index 899b2fc7112..c5c069fcafd 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationTest.java @@ -520,16 +520,6 @@ void shouldOverrideInstrumentationCassandraEnabled() throws IOException { assertThat(configuration.instrumentation.cassandra.enabled).isFalse(); } - @Test - void shouldOverrideInstrumentationHttpClientEnabled() throws IOException { - envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_HTTP_CLIENT_ENABLED", "false"); - - Configuration configuration = loadConfiguration(); - ConfigurationBuilder.overlayFromEnv(configuration); - - assertThat(configuration.instrumentation.httpClient.enabled).isFalse(); - } - @Test void shouldOverrideInstrumentationJdbcEnabled() throws IOException { envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_JDBC_ENABLED", "false"); diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeatTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeatTest.java index fae9403f99d..505f457e314 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeatTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/FeatureStatsbeatTest.java @@ -50,13 +50,6 @@ public void testCassandraEnabled() { Feature.CASSANDRA_DISABLED); } - @Test - public void testHttpClientEnabled() { - testFeatureTrackingDisablement( - (config, enabled) -> config.instrumentation.httpClient.enabled = enabled, - Feature.HTTP_CLIENT_DISABLED); - } - @Test public void testJdbcEnabled() { testFeatureTrackingDisablement( diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/StatsbeatTestUtils.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/StatsbeatTestUtils.java index 0a09994d9f4..ff7dc2050e3 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/StatsbeatTestUtils.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/statsbeat/StatsbeatTestUtils.java @@ -91,9 +91,30 @@ public final class StatsbeatTestUtils { INSTRUMENTATION_MAP_DECODING.put(54, "io.opentelemetry.spring-scheduling-3.1"); FEATURE_MAP_DECODING = new HashMap<>(); - for (Feature feature : Feature.values()) { - FEATURE_MAP_DECODING.put(feature.getBitmapIndex(), feature); - } + FEATURE_MAP_DECODING.put(0, Feature.JAVA_VENDOR_ORACLE); + FEATURE_MAP_DECODING.put(1, Feature.JAVA_VENDOR_ZULU); + FEATURE_MAP_DECODING.put(2, Feature.JAVA_VENDOR_MICROSOFT); + FEATURE_MAP_DECODING.put(3, Feature.JAVA_VENDOR_ADOPT_OPENJDK); + FEATURE_MAP_DECODING.put(4, Feature.JAVA_VENDOR_REDHAT); + FEATURE_MAP_DECODING.put(5, Feature.JAVA_VENDOR_OTHER); + FEATURE_MAP_DECODING.put(6, Feature.AAD); + FEATURE_MAP_DECODING.put(7, Feature.CASSANDRA_DISABLED); + FEATURE_MAP_DECODING.put(8, Feature.JDBC_DISABLED); + FEATURE_MAP_DECODING.put(9, Feature.JMS_DISABLED); + FEATURE_MAP_DECODING.put(10, Feature.KAFKA_DISABLED); + FEATURE_MAP_DECODING.put(11, Feature.MICROMETER_DISABLED); + FEATURE_MAP_DECODING.put(12, Feature.MONGO_DISABLED); + FEATURE_MAP_DECODING.put(13, Feature.REDIS_DISABLED); + FEATURE_MAP_DECODING.put(14, Feature.SPRING_SCHEDULING_DISABLED); + FEATURE_MAP_DECODING.put(15, Feature.AZURE_SDK_DISABLED); + FEATURE_MAP_DECODING.put(16, Feature.RABBITMQ_DISABLED); + FEATURE_MAP_DECODING.put(17, Feature.SPRING_INTEGRATION_DISABLED); + FEATURE_MAP_DECODING.put(18, Feature.LEGACY_PROPAGATION_DISABLED); + FEATURE_MAP_DECODING.put(19, Feature.GRIZZLY_ENABLED); + FEATURE_MAP_DECODING.put(20, Feature.STATSBEAT_DISABLED); + FEATURE_MAP_DECODING.put(21, Feature.QUARTZ_DISABLED); + FEATURE_MAP_DECODING.put(22, Feature.APACHE_CAMEL_DISABLED); + FEATURE_MAP_DECODING.put(23, Feature.AKKA_DISABLED); } static Set decodeInstrumentations(long number) { From 02d04ad45ff9a379284e4015d6824010b139641b Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 11 Nov 2021 16:23:34 -0800 Subject: [PATCH 3/9] Add span kind to sampling overrides --- .../internal/configuration/Configuration.java | 28 ++++- .../agent/internal/sampling/AiSampler.java | 2 +- .../internal/sampling/SamplingOverrides.java | 14 ++- .../sampling/SamplingOverridesTest.java | 117 ++++++++++++++---- ...elemetryfiltering_applicationinsights.json | 2 + 5 files changed, 128 insertions(+), 35 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java index f4d4cb35db2..27216b065b3 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java @@ -37,6 +37,7 @@ import java.util.Map; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import org.checkerframework.checker.nullness.qual.Nullable; // an assumption is made throughout this file that user will not explicitly use `null` value in json // file @@ -62,6 +63,25 @@ private static boolean isEmpty(String str) { return str == null || str.trim().isEmpty(); } + public enum SpanKind { + @JsonProperty("server") + SERVER(io.opentelemetry.api.trace.SpanKind.SERVER), + @JsonProperty("client") + CLIENT(io.opentelemetry.api.trace.SpanKind.CLIENT), + @JsonProperty("consumer") + CONSUMER(io.opentelemetry.api.trace.SpanKind.CONSUMER), + @JsonProperty("producer") + PRODUCER(io.opentelemetry.api.trace.SpanKind.PRODUCER), + @JsonProperty("internal") + INTERNAL(io.opentelemetry.api.trace.SpanKind.INTERNAL); + + public final io.opentelemetry.api.trace.SpanKind otelSpanKind; + + SpanKind(io.opentelemetry.api.trace.SpanKind otelSpanKind) { + this.otelSpanKind = otelSpanKind; + } + } + public enum MatchType { @JsonProperty("strict") STRICT, @@ -373,6 +393,8 @@ private static String getDefaultPath() { } public static class SamplingOverride { + // TODO (trask) consider making this required when moving out of preview + @Nullable public SpanKind spanKind; // not using include/exclude, because you can still get exclude with this by adding a second // (exclude) override above it // (since only the first matching override is used) @@ -381,11 +403,11 @@ public static class SamplingOverride { public String id; // optional, used for debugging purposes only public void validate() { - if (attributes.isEmpty()) { + if (spanKind == null && attributes.isEmpty()) { // TODO add doc and go link, similar to telemetry processors throw new FriendlyException( - "A sampling override configuration has no attributes.", - "Please provide one or more attributes for the sampling override configuration."); + "A sampling override configuration is missing \"spanKind\" and has no attributes.", + "Please provide at least one of \"spanKind\" or \"attributes\" for the sampling override configuration."); } if (percentage == null) { // TODO add doc and go link, similar to telemetry processors diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/AiSampler.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/AiSampler.java index b2d63c80a3e..2e22ece25de 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/AiSampler.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/AiSampler.java @@ -87,7 +87,7 @@ public SamplingResult shouldSample( Attributes attributes, List parentLinks) { - MatcherGroup override = samplingOverrides.getOverride(attributes); + MatcherGroup override = samplingOverrides.getOverride(spanKind, attributes); if (override != null) { return getSamplingResult( diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java index 93a796d7993..aafbf832139 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java @@ -28,6 +28,7 @@ import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryUtil; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.sdk.trace.samplers.SamplingDecision; import io.opentelemetry.sdk.trace.samplers.SamplingResult; @@ -37,7 +38,7 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -import org.checkerframework.checker.nullness.qual.Nullable; +import javax.annotation.Nullable; // TODO find a better name for this class (and MatcherGroup too) class SamplingOverrides { @@ -52,10 +53,10 @@ class SamplingOverrides { } @Nullable - MatcherGroup getOverride(Attributes attributes) { + MatcherGroup getOverride(SpanKind spanKind, Attributes attributes) { LazyHttpUrl lazyHttpUrl = new LazyHttpUrl(attributes); for (MatcherGroup matcherGroups : matcherGroups) { - if (matcherGroups.matches(attributes, lazyHttpUrl)) { + if (matcherGroups.matches(spanKind, attributes, lazyHttpUrl)) { return matcherGroups; } } @@ -143,11 +144,13 @@ public TraceState getUpdatedTraceState(TraceState parentTraceState) { } static class MatcherGroup { + @Nullable private final SpanKind spanKind; private final List predicates; private final double percentage; private final SamplingResult recordAndSampleAndOverwriteTraceState; private MatcherGroup(SamplingOverride override) { + spanKind = override.spanKind != null ? override.spanKind.otelSpanKind : null; predicates = new ArrayList<>(); for (SamplingOverrideAttribute attribute : override.attributes) { predicates.add(toPredicate(attribute)); @@ -165,7 +168,10 @@ SamplingResult getRecordAndSampleAndOverwriteTraceState() { return recordAndSampleAndOverwriteTraceState; } - private boolean matches(Attributes attributes, LazyHttpUrl lazyHttpUrl) { + private boolean matches(SpanKind spanKind, Attributes attributes, LazyHttpUrl lazyHttpUrl) { + if (!spanKind.equals(this.spanKind)) { + return false; + } for (TempPredicate predicate : predicates) { if (!predicate.test(attributes, lazyHttpUrl)) { return false; diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java index 2b4c4bf68f6..cd46461f1c0 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java @@ -24,11 +24,13 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; +import com.microsoft.applicationinsights.agent.internal.configuration.Configuration; import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.MatchType; import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverride; import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverrideAttribute; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.SpanKind; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -44,79 +46,131 @@ void shouldSampleByDefault() { Attributes attributes = Attributes.empty(); // expect - assertThat(sampler.getOverride(attributes)).isNull(); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); + } + + @Test + void shouldNotFilterByNullSpanKind() { + // given + List overrides = singletonList(newOverride(null, 0)); + SamplingOverrides sampler = new SamplingOverrides(overrides); + Attributes attributes = Attributes.empty(); + + // expect + assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); + } + + @Test + void shouldFilterBySpanKind() { + // given + List overrides = singletonList(newOverride(Configuration.SpanKind.SERVER, 0)); + SamplingOverrides sampler = new SamplingOverrides(overrides); + Attributes attributes = Attributes.empty(); + + // expect + assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNotNull(); + } + + @Test + void shouldNotFilterBySpanKind() { + // given + List overrides = singletonList(newOverride(Configuration.SpanKind.SERVER, 0)); + SamplingOverrides sampler = new SamplingOverrides(overrides); + Attributes attributes = Attributes.empty(); + + // expect + assertThat(sampler.getOverride(SpanKind.CLIENT, attributes)).isNull(); } @Test void shouldFilterStrictMatch() { // given List overrides = - singletonList(newOverride(0, newStrictAttribute("one", "1"))); + singletonList( + newOverride(Configuration.SpanKind.SERVER, 0, newStrictAttribute("one", "1"))); + SamplingOverrides sampler = new SamplingOverrides(overrides); + Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "1"); + + // expect + assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0); + } + + @Test + void shouldNotFilterStrictMatchWithWrongSpanKind() { + // given + List overrides = + singletonList( + newOverride(Configuration.SpanKind.SERVER, 0, newStrictAttribute("one", "1"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "1"); // expect - assertThat(sampler.getOverride(attributes).getPercentage()).isEqualTo(0); + assertThat(sampler.getOverride(SpanKind.CLIENT, attributes)).isNull(); } @Test void shouldNotFilterStrictMatch() { // given List overrides = - singletonList(newOverride(0, newStrictAttribute("one", "1"))); + singletonList( + newOverride(Configuration.SpanKind.SERVER, 0, newStrictAttribute("one", "1"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "2"); // expect - assertThat(sampler.getOverride(attributes)).isNull(); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); } @Test void shouldNotFilterMissingStrictMatch() { // given List overrides = - singletonList(newOverride(0, newStrictAttribute("one", "1"))); + singletonList( + newOverride(Configuration.SpanKind.SERVER, 0, newStrictAttribute("one", "1"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("two"), "1"); // expect - assertThat(sampler.getOverride(attributes)).isNull(); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); } @Test void shouldFilterRegexpMatch() { // given List overrides = - singletonList(newOverride(0, newRegexpAttribute("one", "1.*"))); + singletonList( + newOverride(Configuration.SpanKind.SERVER, 0, newRegexpAttribute("one", "1.*"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "11"); // expect - assertThat(sampler.getOverride(attributes).getPercentage()).isEqualTo(0); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0); } @Test void shouldNotFilterRegexpMatch() { // given List overrides = - singletonList(newOverride(0, newRegexpAttribute("one", "1.*"))); + singletonList( + newOverride(Configuration.SpanKind.SERVER, 0, newRegexpAttribute("one", "1.*"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "22"); // expect - assertThat(sampler.getOverride(attributes)).isNull(); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); } @Test void shouldNotFilterMissingRegexpMatch() { // given List overrides = - singletonList(newOverride(0, newRegexpAttribute("one", "1.*"))); + singletonList( + newOverride(Configuration.SpanKind.SERVER, 0, newRegexpAttribute("one", "1.*"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("two"), "11"); // expect - assertThat(sampler.getOverride(attributes)).isNull(); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); } @Test @@ -124,13 +178,17 @@ void shouldFilterMultiAttributes() { // given List overrides = singletonList( - newOverride(0, newStrictAttribute("one", "1"), newRegexpAttribute("two", "2.*"))); + newOverride( + Configuration.SpanKind.SERVER, + 0, + newStrictAttribute("one", "1"), + newRegexpAttribute("two", "2.*"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "1", AttributeKey.stringKey("two"), "22"); // expect - assertThat(sampler.getOverride(attributes).getPercentage()).isEqualTo(0); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0); } @Test @@ -138,13 +196,17 @@ void shouldNotFilterMultiAttributes() { // given List overrides = singletonList( - newOverride(0, newStrictAttribute("one", "1"), newRegexpAttribute("two", "2.*"))); + newOverride( + Configuration.SpanKind.SERVER, + 0, + newStrictAttribute("one", "1"), + newRegexpAttribute("two", "2.*"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "2", AttributeKey.stringKey("two"), "22"); // expect - assertThat(sampler.getOverride(attributes)).isNull(); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); } @Test @@ -152,14 +214,14 @@ void shouldFilterMultiConfigsBothMatch() { // given List overrides = Arrays.asList( - newOverride(0, newStrictAttribute("one", "1")), - newOverride(0, newRegexpAttribute("two", "2.*"))); + newOverride(Configuration.SpanKind.SERVER, 0, newStrictAttribute("one", "1")), + newOverride(Configuration.SpanKind.SERVER, 0, newRegexpAttribute("two", "2.*"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "1", AttributeKey.stringKey("two"), "22"); // expect - assertThat(sampler.getOverride(attributes).getPercentage()).isEqualTo(0); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0); } @Test @@ -167,14 +229,14 @@ void shouldFilterMultiConfigsOneMatch() { // given List overrides = Arrays.asList( - newOverride(0, newStrictAttribute("one", "1")), - newOverride(0, newRegexpAttribute("two", "2.*"))); + newOverride(Configuration.SpanKind.SERVER, 0, newStrictAttribute("one", "1")), + newOverride(Configuration.SpanKind.SERVER, 0, newRegexpAttribute("two", "2.*"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "2", AttributeKey.stringKey("two"), "22"); // expect - assertThat(sampler.getOverride(attributes).getPercentage()).isEqualTo(0); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0); } @Test @@ -182,19 +244,20 @@ void shouldNotFilterMultiConfigsNoMatch() { // given List overrides = Arrays.asList( - newOverride(0, newStrictAttribute("one", "1")), - newOverride(0, newRegexpAttribute("two", "2.*"))); + newOverride(Configuration.SpanKind.SERVER, 0, newStrictAttribute("one", "1")), + newOverride(Configuration.SpanKind.SERVER, 0, newRegexpAttribute("two", "2.*"))); SamplingOverrides sampler = new SamplingOverrides(overrides); Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "2", AttributeKey.stringKey("two"), "33"); // expect - assertThat(sampler.getOverride(attributes)).isNull(); + assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); } private static SamplingOverride newOverride( - float percentage, SamplingOverrideAttribute... attribute) { + Configuration.SpanKind spanKind, float percentage, SamplingOverrideAttribute... attribute) { SamplingOverride override = new SamplingOverride(); + override.spanKind = spanKind; override.attributes = Arrays.asList(attribute); override.percentage = percentage; return override; diff --git a/test/smoke/appServers/global-resources/telemetryfiltering_applicationinsights.json b/test/smoke/appServers/global-resources/telemetryfiltering_applicationinsights.json index 818b6bd4a0a..4423d0e6279 100644 --- a/test/smoke/appServers/global-resources/telemetryfiltering_applicationinsights.json +++ b/test/smoke/appServers/global-resources/telemetryfiltering_applicationinsights.json @@ -7,6 +7,7 @@ "sampling": { "overrides": [ { + "spanKind": "server", "attributes": [ { "key": "http.url", @@ -18,6 +19,7 @@ "id": "filter out health check" }, { + "spanKind": "client", "attributes": [ { "key": "db.statement", From 4b99b4cf4b84baefce4d0f7cdff6f57b292f5628 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 11 Nov 2021 17:08:09 -0800 Subject: [PATCH 4/9] Support key-only matches --- .../internal/configuration/Configuration.java | 8 ++--- .../internal/sampling/SamplingOverrides.java | 19 ++++++++++++ .../sampling/SamplingOverridesTest.java | 30 +++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java index 27216b065b3..cdb8447e7a6 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java @@ -429,8 +429,8 @@ public void validate() { public static class SamplingOverrideAttribute { public String key; - public String value; - public MatchType matchType; + @Nullable public String value; + @Nullable public MatchType matchType; private void validate() { if (isEmpty(key)) { @@ -439,9 +439,9 @@ private void validate() { "A sampling override configuration has an attribute section that is missing a \"key\".", "Please provide a \"key\" under the attribute section of the sampling override configuration."); } - if (matchType == null) { + if (matchType == null && value != null) { throw new FriendlyException( - "A sampling override configuration has an attribute section that is missing a \"matchType\".", + "A sampling override configuration has an attribute section with a \"value\" that is missing a \"matchType\".", "Please provide a \"matchType\" under the attribute section of the sampling override configuration."); } if (matchType == MatchType.REGEXP) { diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java index aafbf832139..d756edadce0 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java @@ -185,6 +185,8 @@ private static TempPredicate toPredicate(SamplingOverrideAttribute attribute) { return new StrictMatcher(attribute.key, attribute.value); } else if (attribute.matchType == MatchType.REGEXP) { return new RegexpMatcher(attribute.key, attribute.value); + } else if (attribute.matchType == null) { + return new KeyOnlyMatcher(attribute.key); } else { throw new IllegalStateException("Unexpected match type: " + attribute.matchType); } @@ -229,6 +231,23 @@ public boolean test(Attributes attributes, LazyHttpUrl lazyHttpUrl) { } } + private static class KeyOnlyMatcher implements TempPredicate { + private final AttributeKey key; + + private KeyOnlyMatcher(String key) { + this.key = AttributeKey.stringKey(key); + } + + @Override + public boolean test(Attributes attributes, LazyHttpUrl lazyHttpUrl) { + String val = attributes.get(key); + if (val == null && key.getKey().equals(SemanticAttributes.HTTP_URL.getKey())) { + val = lazyHttpUrl.get(); + } + return val != null; + } + } + // this is temporary until semantic attributes stabilize and we make breaking change private static class LazyHttpUrl { private final Attributes attributes; diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java index cd46461f1c0..2b6ae782367 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java @@ -173,6 +173,30 @@ void shouldNotFilterMissingRegexpMatch() { assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); } + @Test + void shouldFilterKeyOnlyMatch() { + // given + List overrides = + singletonList(newOverride(Configuration.SpanKind.SERVER, 0, newKeyOnlyAttribute("one"))); + SamplingOverrides sampler = new SamplingOverrides(overrides); + Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "11"); + + // expect + assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0); + } + + @Test + void shouldNotFilterKeyOnlyMatch() { + // given + List overrides = + singletonList(newOverride(Configuration.SpanKind.SERVER, 0, newKeyOnlyAttribute("one"))); + SamplingOverrides sampler = new SamplingOverrides(overrides); + Attributes attributes = Attributes.of(AttributeKey.stringKey("two"), "22"); + + // expect + assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); + } + @Test void shouldFilterMultiAttributes() { // given @@ -278,4 +302,10 @@ private static SamplingOverrideAttribute newRegexpAttribute(String key, String v attribute.matchType = MatchType.REGEXP; return attribute; } + + private static SamplingOverrideAttribute newKeyOnlyAttribute(String key) { + SamplingOverrideAttribute attribute = new SamplingOverrideAttribute(); + attribute.key = key; + return attribute; + } } From 48bfc9fcc1c4b43c12ad67649ef27a6fbdff35c6 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 11 Nov 2021 17:45:55 -0800 Subject: [PATCH 5/9] Fix --- .../agent/internal/sampling/SamplingOverrides.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java index d756edadce0..8a7f92c5219 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java @@ -169,7 +169,7 @@ SamplingResult getRecordAndSampleAndOverwriteTraceState() { } private boolean matches(SpanKind spanKind, Attributes attributes, LazyHttpUrl lazyHttpUrl) { - if (!spanKind.equals(this.spanKind)) { + if (this.spanKind != null && !this.spanKind.equals(spanKind)) { return false; } for (TempPredicate predicate : predicates) { From 1332abd9b1bb59001b56f49b24f4ffdc78af6702 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 11 Nov 2021 17:53:14 -0800 Subject: [PATCH 6/9] Bump version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 41a2d9dd0d3..5e38a248c5a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ // Project properties -version=3.2.3 +version=3.2.4-BETA group=com.microsoft.azure # gradle default is 256m which causes sporadic failures - https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m From dcd772102da69e9009e9506d5e3a0b47bf95718e Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 11 Nov 2021 21:42:13 -0800 Subject: [PATCH 7/9] Fix sporadic test failure --- .../agent/internal/heartbeat/HeartbeatTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/heartbeat/HeartbeatTests.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/heartbeat/HeartbeatTests.java index 7164ea6bd1c..e39a1d562e0 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/heartbeat/HeartbeatTests.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/heartbeat/HeartbeatTests.java @@ -86,7 +86,7 @@ void heartBeatPayloadContainsDataByDefault() throws InterruptedException { provider.initialize(TelemetryClient.createForTest()); // some of the initialization above happens in a separate thread - Thread.sleep(100); + Thread.sleep(500); // then MetricsData t = (MetricsData) provider.gatherData().getData().getBaseData(); From 8259d1d7d9abec499cdc9db608feeca1609afdb6 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 11 Nov 2021 23:14:38 -0800 Subject: [PATCH 8/9] Fix test --- .../sampling/SamplingOverridesTest.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java index 2b6ae782367..e541b3103fe 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverridesTest.java @@ -49,17 +49,6 @@ void shouldSampleByDefault() { assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); } - @Test - void shouldNotFilterByNullSpanKind() { - // given - List overrides = singletonList(newOverride(null, 0)); - SamplingOverrides sampler = new SamplingOverrides(overrides); - Attributes attributes = Attributes.empty(); - - // expect - assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull(); - } - @Test void shouldFilterBySpanKind() { // given @@ -95,6 +84,18 @@ void shouldFilterStrictMatch() { assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0); } + @Test + void shouldFilterStrictMatchWithNullSpanKind() { + // given + List overrides = + singletonList(newOverride(null, 0, newStrictAttribute("one", "1"))); + SamplingOverrides sampler = new SamplingOverrides(overrides); + Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "1"); + + // expect + assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0); + } + @Test void shouldNotFilterStrictMatchWithWrongSpanKind() { // given From 8553cae72e939af8d6a28ffc1d588737648390d6 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 15 Nov 2021 08:42:37 -0800 Subject: [PATCH 9/9] Add todo --- .../agent/internal/configuration/Configuration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java index cdb8447e7a6..7db54305437 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java @@ -63,6 +63,7 @@ private static boolean isEmpty(String str) { return str == null || str.trim().isEmpty(); } + // TODO (trask) investigate options for mapping lowercase values to otel enum directly public enum SpanKind { @JsonProperty("server") SERVER(io.opentelemetry.api.trace.SpanKind.SERVER),