Skip to content

Commit

Permalink
Change default OTLP protocol to http/protobuf (#9993)
Browse files Browse the repository at this point in the history
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
  • Loading branch information
heyams and trask authored Jan 4, 2024
1 parent 325477e commit f617691
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
io.opentelemetry.javaagent.tooling.config.ConfigurationPropertiesSupplier
io.opentelemetry.javaagent.tooling.config.OtlpProtocolPropertiesSupplier
io.opentelemetry.javaagent.tooling.config.ConfigurationPropertiesSupplierTest$UserCustomPropertiesSupplier
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ protected Map<String, String> 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");
Expand Down

0 comments on commit f617691

Please sign in to comment.