From f6176919e4a0fa194bc7aa747984c3ac09a64604 Mon Sep 17 00:00:00 2001 From: Helen <56097766+heyams@users.noreply.github.com> Date: Thu, 4 Jan 2024 13:30:17 -0800 Subject: [PATCH] Change default OTLP protocol to http/protobuf (#9993) Co-authored-by: Trask Stalnaker --- .../javaagent/smoketest/SmokeTest.java | 3 ++ .../javaagent/smoketest/IntegrationTest.java | 3 ++ .../OtlpProtocolPropertiesSupplier.java | 27 ++++++++++ .../OtlpProtocolPropertiesSupplierTest.java | 53 +++++++++++++++++++ ...re.spi.AutoConfigurationCustomizerProvider | 1 + .../AbstractTestContainerManager.java | 5 ++ 6 files changed, 92 insertions(+) create mode 100644 javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/OtlpProtocolPropertiesSupplier.java create mode 100644 javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/config/OtlpProtocolPropertiesSupplierTest.java diff --git a/examples/distro/smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java b/examples/distro/smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java index dd78e18167b8..6c382ab6424f 100644 --- a/examples/distro/smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java +++ b/examples/distro/smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java @@ -82,6 +82,9 @@ void startTarget(int jdk) { .withEnv("JAVA_TOOL_OPTIONS", "-javaagent:/opentelemetry-javaagent.jar") .withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1") .withEnv("OTEL_BSP_SCHEDULE_DELAY", "10") + // TODO (heya) update smoke tests to run using http/protobuf + // in the meantime, force smoke tests to use grpc protocol for all exporters + .withEnv("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc") .withEnv("OTEL_PROPAGATORS", "tracecontext,baggage,demo") .withEnv(getExtraEnv()) .waitingFor(getTargetWaitStrategy()); diff --git a/examples/extension/src/test/java/com/example/javaagent/smoketest/IntegrationTest.java b/examples/extension/src/test/java/com/example/javaagent/smoketest/IntegrationTest.java index 25d8ec5126f3..fd04c164ccbf 100644 --- a/examples/extension/src/test/java/com/example/javaagent/smoketest/IntegrationTest.java +++ b/examples/extension/src/test/java/com/example/javaagent/smoketest/IntegrationTest.java @@ -101,6 +101,9 @@ private GenericContainer buildTargetContainer(String agentPath, String extens .withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1") .withEnv("OTEL_BSP_SCHEDULE_DELAY", "10") .withEnv("OTEL_PROPAGATORS", "tracecontext,baggage,demo") + // TODO (heya) update smoke tests to run using http/protobuf + // in the meantime, force smoke tests to use grpc protocol for all exporters + .withEnv("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc") .withEnv(getExtraEnv()) .waitingFor(getTargetWaitStrategy()); // If external extensions are requested diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/OtlpProtocolPropertiesSupplier.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/OtlpProtocolPropertiesSupplier.java new file mode 100644 index 000000000000..ca624f1f7e5e --- /dev/null +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/OtlpProtocolPropertiesSupplier.java @@ -0,0 +1,27 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.tooling.config; + +import com.google.auto.service.AutoService; +import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer; +import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; +import java.util.Collections; + +@AutoService(AutoConfigurationCustomizerProvider.class) +public class OtlpProtocolPropertiesSupplier implements AutoConfigurationCustomizerProvider { + + @Override + public void customize(AutoConfigurationCustomizer autoConfigurationCustomizer) { + autoConfigurationCustomizer.addPropertiesSupplier( + () -> Collections.singletonMap("otel.exporter.otlp.protocol", "http/protobuf")); + } + + @Override + public int order() { + // make sure it runs BEFORE all the user-provided customizers + return Integer.MIN_VALUE; + } +} diff --git a/javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/config/OtlpProtocolPropertiesSupplierTest.java b/javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/config/OtlpProtocolPropertiesSupplierTest.java new file mode 100644 index 000000000000..ed3cedcc3d55 --- /dev/null +++ b/javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/config/OtlpProtocolPropertiesSupplierTest.java @@ -0,0 +1,53 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.tooling.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.events.GlobalEventEmitterProvider; +import io.opentelemetry.javaagent.tooling.OpenTelemetryInstaller; +import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; +import io.opentelemetry.sdk.autoconfigure.internal.AutoConfigureUtil; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.SetSystemProperty; + +class OtlpProtocolPropertiesSupplierTest { + + @AfterEach + void cleanUp() { + GlobalOpenTelemetry.resetForTest(); + GlobalEventEmitterProvider.resetForTest(); + } + + @SetSystemProperty( + key = "otel.exporter.otlp.protocol", + value = "grpc") // user explicitly sets grpc + @Test + void keepUserOtlpProtocolConfiguration() { + // when + AutoConfiguredOpenTelemetrySdk autoConfiguredSdk = + OpenTelemetryInstaller.installOpenTelemetrySdk(this.getClass().getClassLoader()); + + // then + assertThat( + AutoConfigureUtil.getConfig(autoConfiguredSdk).getString("otel.exporter.otlp.protocol")) + .isEqualTo("grpc"); + } + + @Test + void defaultHttpProtobufOtlpProtocolConfiguration() { + // when + AutoConfiguredOpenTelemetrySdk autoConfiguredSdk = + OpenTelemetryInstaller.installOpenTelemetrySdk(this.getClass().getClassLoader()); + + // then + assertThat( + AutoConfigureUtil.getConfig(autoConfiguredSdk).getString("otel.exporter.otlp.protocol")) + .isEqualTo("http/protobuf"); + } +} diff --git a/javaagent-tooling/src/test/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider b/javaagent-tooling/src/test/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider index b3f48d038005..2c506cefe2ba 100644 --- a/javaagent-tooling/src/test/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider +++ b/javaagent-tooling/src/test/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider @@ -1,2 +1,3 @@ io.opentelemetry.javaagent.tooling.config.ConfigurationPropertiesSupplier +io.opentelemetry.javaagent.tooling.config.OtlpProtocolPropertiesSupplier io.opentelemetry.javaagent.tooling.config.ConfigurationPropertiesSupplierTest$UserCustomPropertiesSupplier diff --git a/smoke-tests/src/test/java/io/opentelemetry/smoketest/AbstractTestContainerManager.java b/smoke-tests/src/test/java/io/opentelemetry/smoketest/AbstractTestContainerManager.java index 7ea179775ddc..111a6709933a 100644 --- a/smoke-tests/src/test/java/io/opentelemetry/smoketest/AbstractTestContainerManager.java +++ b/smoke-tests/src/test/java/io/opentelemetry/smoketest/AbstractTestContainerManager.java @@ -30,6 +30,11 @@ protected Map getAgentEnvironment( // Liberty20Jdk11, Payara6Jdk11 and Payara6Jdk17 fail with // java.util.zip.ZipException: Invalid CEN header (invalid zip64 extra data field size) + " -Djdk.util.zip.disableZip64ExtraFieldValidation=true"); + + // TODO (heya) update smoke tests to run using http/protobuf + // in the meantime, force smoke tests to use grpc protocol for all exporters + environment.put("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc"); + environment.put("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", "1"); environment.put("OTEL_BSP_SCHEDULE_DELAY", "10ms"); environment.put("OTEL_METRIC_EXPORT_INTERVAL", "1000");