Skip to content

Commit

Permalink
Option 1
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Nov 11, 2021
1 parent e75d884 commit cf5b048
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Feature> javaVendorFeatureMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> decodeInstrumentations(long number) {
Expand Down

0 comments on commit cf5b048

Please sign in to comment.