Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class NoSharedInternalCodeTest {
"opentelemetry-exporter-common",
"opentelemetry-exporter-logging-otlp",
"opentelemetry-exporter-prometheus",
"opentelemetry-extension-trace-propagators",
"opentelemetry-opencensus-shim",
"opentelemetry-sdk",
"opentelemetry-sdk-logs",
Expand All @@ -52,9 +51,7 @@ class NoSharedInternalCodeTest {
"opentelemetry-exporter-otlp",
"opentelemetry-exporter-otlp-common",
"opentelemetry-exporter-otlp-profiles",
"opentelemetry-exporter-sender-grpc-managed-channel",
"opentelemetry-exporter-sender-jdk",
"opentelemetry-exporter-sender-okhttp");
"opentelemetry-exporter-sender-grpc-managed-channel");

private static final String OTEL_BASE_PACKAGE = "io.opentelemetry";
private static final Logger logger = Logger.getLogger(NoSharedInternalCodeTest.class.getName());
Expand Down
18 changes: 17 additions & 1 deletion docs/apidiffs/current_vs_latest/opentelemetry-sdk-common.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
Comparing source compatibility of opentelemetry-sdk-common-1.69.0-SNAPSHOT.jar against opentelemetry-sdk-common-1.68.0.jar
No changes.
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.common.export.GrpcSenderConfig (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) java.util.Set<io.opentelemetry.sdk.common.export.GrpcStatusCode> getRetryableGrpcStatusCodes()
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.common.export.HttpSenderConfig (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) java.util.Set<java.lang.Integer> getRetryableHttpResponseCodes()
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.common.export.impl.HttpExportUtil (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) STATIC(+) java.util.OptionalLong retryAfterNanos(java.lang.String)
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.common.impl.DaemonThreadFactory (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW INTERFACE: java.util.concurrent.ThreadFactory
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.impl.DaemonThreadFactory create(java.lang.String)
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.common.impl.DaemonThreadFactory createWithDelegate(java.lang.String, java.util.concurrent.ThreadFactory)
+++ NEW METHOD: PUBLIC(+) java.lang.Thread newThread(java.lang.Runnable)
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@
package io.opentelemetry.exporter.internal;

import io.opentelemetry.sdk.common.export.GrpcStatusCode;
import java.time.Duration;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.OptionalLong;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
Expand All @@ -27,6 +20,16 @@
public final class RetryUtil {

private static final Set<String> RETRYABLE_GRPC_STATUS_CODES;
private static final Set<GrpcStatusCode> RETRYABLE_GRPC_STATUS_CODE_ENUMS =
Collections.unmodifiableSet(
EnumSet.of(
GrpcStatusCode.CANCELLED,
GrpcStatusCode.DEADLINE_EXCEEDED,
GrpcStatusCode.RESOURCE_EXHAUSTED,
GrpcStatusCode.ABORTED,
GrpcStatusCode.OUT_OF_RANGE,
GrpcStatusCode.UNAVAILABLE,
GrpcStatusCode.DATA_LOSS));
private static final Set<Integer> RETRYABLE_HTTP_STATUS_CODES =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(429, 502, 503, 504)));

Expand All @@ -51,45 +54,13 @@ public static Set<String> retryableGrpcStatusCodes() {
return RETRYABLE_GRPC_STATUS_CODES;
}

/** Returns the retryable {@link GrpcStatusCode}s. */
public static Set<GrpcStatusCode> retryableGrpcStatusCodeEnums() {
return RETRYABLE_GRPC_STATUS_CODE_ENUMS;
}

/** Returns the retryable HTTP status codes. */
public static Set<Integer> retryableHttpResponseCodes() {
return RETRYABLE_HTTP_STATUS_CODES;
}

/**
* Returns the delay specified by a {@code Retry-After} header, or empty if the value is absent or
* malformed.
*/
public static OptionalLong retryAfterNanos(@Nullable String retryAfter) {
return retryAfterNanos(retryAfter, Instant.now());
}

static OptionalLong retryAfterNanos(@Nullable String retryAfter, Instant now) {
if (retryAfter == null) {
return OptionalLong.empty();
}

try {
long delaySeconds = Long.parseLong(retryAfter);
// RFC 9110 delay-seconds is 1*DIGIT. Long.parseLong also accepts signs and non-ASCII digits.
for (int i = 0; i < retryAfter.length(); i++) {
char digit = retryAfter.charAt(i);
if (digit < '0' || digit > '9') {
return OptionalLong.empty();
}
}
return OptionalLong.of(TimeUnit.SECONDS.toNanos(delaySeconds));
} catch (NumberFormatException ignored) {
// Fall through and try the HTTP-date form.
}

try {
Instant retryAfterInstant =
ZonedDateTime.parse(retryAfter, DateTimeFormatter.RFC_1123_DATE_TIME).toInstant();
long delayNanos = Duration.between(now, retryAfterInstant).toNanos();
return OptionalLong.of(Math.max(0, delayNanos));
} catch (DateTimeParseException | ArithmeticException ignored) {
return OptionalLong.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,15 @@ public X509KeyManager getKeyManager() {
}

/** Get the {@link X509TrustManager}. */
@Nullable
public X509TrustManager getTrustManager() {
return trustManager;
if (trustManager != null) {
return trustManager;
}
try {
return TlsUtil.defaultTrustManager();
Comment on lines +122 to +123

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we resolve the SSL context and default trust manager as a pair once per build? getSslContext() calls getTrustManager() internally, then exporter construction calls getTrustManager() again. With no explicit manager configured, these resolve separate instances rather than passing the manager used to initialize the context. This also repeats default trust-store initialization. The resolved pair should not prevent subsequent builder configuration.

} catch (SSLException e) {
throw new IllegalStateException("Could not build default TrustManager.", e);
}
}

/** Get the {@link SSLContext}. */
Expand All @@ -129,9 +135,10 @@ public SSLContext getSslContext() {

try {
SSLContext sslContext = SSLContext.getInstance("TLS");
X509TrustManager resolvedTrustManager = getTrustManager();
sslContext.init(
keyManager == null ? null : new KeyManager[] {keyManager},
trustManager == null ? null : new TrustManager[] {trustManager},
new TrustManager[] {resolvedTrustManager},
null);
return sslContext;
} catch (NoSuchAlgorithmException | KeyManagementException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,34 @@
package io.opentelemetry.exporter.internal;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.argumentSet;

import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.OptionalLong;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import io.opentelemetry.sdk.common.export.GrpcStatusCode;
import org.junit.jupiter.api.Test;

class RetryUtilTest {

private static final Instant NOW = Instant.parse("2026-07-17T00:00:00Z");

@ParameterizedTest
@MethodSource("retryAfterArgs")
void retryAfterNanos(String retryAfter, Instant now, Long expectedNanos) {
OptionalLong delayNanos = RetryUtil.retryAfterNanos(retryAfter, now);
@Test
void retryableGrpcStatusCodes() {
assertThat(RetryUtil.retryableGrpcStatusCodes())
.containsExactlyInAnyOrder("1", "4", "8", "10", "11", "14", "15");
}

if (expectedNanos == null) {
assertThat(delayNanos).isEmpty();
} else {
assertThat(delayNanos).hasValue(expectedNanos);
}
@Test
void retryableGrpcStatusCodeEnums() {
assertThat(RetryUtil.retryableGrpcStatusCodeEnums())
.containsExactlyInAnyOrder(
GrpcStatusCode.CANCELLED,
GrpcStatusCode.DEADLINE_EXCEEDED,
GrpcStatusCode.RESOURCE_EXHAUSTED,
GrpcStatusCode.ABORTED,
GrpcStatusCode.OUT_OF_RANGE,
GrpcStatusCode.UNAVAILABLE,
GrpcStatusCode.DATA_LOSS);
}

private static Stream<Arguments> retryAfterArgs() {
return Stream.of(
argumentSet("null", null, Instant.EPOCH, null),
argumentSet("seconds", "30", Instant.EPOCH, TimeUnit.SECONDS.toNanos(30)),
argumentSet("zero seconds", "0", Instant.EPOCH, 0L),
argumentSet("leading zeros", "0030", Instant.EPOCH, TimeUnit.SECONDS.toNanos(30)),
argumentSet("positive sign", "+30", Instant.EPOCH, null),
argumentSet("negative zero", "-0", Instant.EPOCH, null),
argumentSet("non-ASCII digits", "٣٠", Instant.EPOCH, null),
argumentSet("empty", "", Instant.EPOCH, null),
argumentSet("negative seconds", "-1", Instant.EPOCH, null),
argumentSet("malformed", "bad-value", Instant.EPOCH, null),
argumentSet(
"future date",
ZonedDateTime.ofInstant(NOW.plusSeconds(45), ZoneOffset.UTC)
.format(DateTimeFormatter.RFC_1123_DATE_TIME),
NOW,
TimeUnit.SECONDS.toNanos(45)),
argumentSet(
"past date clamps to zero",
ZonedDateTime.ofInstant(NOW.minusSeconds(1), ZoneOffset.UTC)
.format(DateTimeFormatter.RFC_1123_DATE_TIME),
NOW,
0L));
@Test
void retryableHttpResponseCodes() {
assertThat(RetryUtil.retryableHttpResponseCodes())
.containsExactlyInAnyOrder(429, 502, 503, 504);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.exporter.internal;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension;
Expand Down Expand Up @@ -109,4 +110,28 @@ void setSslContext_AlreadyExists_Throws() throws Exception {
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("keyManager has been previously configured");
}

@Test
void getTrustManager_notConfigured_resolvesDefaultTrustManager() {
assertThat(helper.getTrustManager()).isNotNull();
assertThat(helper.getSslContext()).isNotNull();
}

@Test
void gettersDoNotMutateState_allowsSubsequentConfiguration() throws Exception {
helper.getSslContext();
helper.getTrustManager();

TlsConfigHelper certCopy = helper.copy();
assertThatCode(() -> certCopy.setTrustManagerFromCerts(serverTls.certificate().getEncoded()))
.doesNotThrowAnyException();
assertThat(certCopy.getTrustManager()).isNotNull();

TlsConfigHelper keyCopy = helper.copy();
assertThatCode(() ->
keyCopy.setKeyManagerFromCerts(
serverTls.privateKey().getEncoded(), serverTls.certificate().getEncoded()))
.doesNotThrowAnyException();
assertThat(keyCopy.getKeyManager()).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public void setUp() {
null,
null,
Long.MAX_VALUE,
null),
null,
Collections.emptySet()),
InternalTelemetryVersion.LATEST,
ComponentId.generateLazy(StandardComponentId.ExporterType.OTLP_GRPC_SPAN_EXPORTER),
MeterProvider::noop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
package io.opentelemetry.exporter.otlp.internal;

import com.google.auto.value.AutoValue;
import io.opentelemetry.exporter.internal.RetryUtil;
import io.opentelemetry.exporter.internal.grpc.ExtendedGrpcSenderConfig;
import io.opentelemetry.sdk.common.export.Compressor;
import io.opentelemetry.sdk.common.export.GrpcStatusCode;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.net.URI;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -63,4 +66,9 @@ public static ImmutableGrpcSenderConfig create(
@Override
@Nullable
public abstract List<String> getEnabledProtocols();

@Override
public Set<GrpcStatusCode> getRetryableGrpcStatusCodes() {
return RetryUtil.retryableGrpcStatusCodeEnums();
Comment on lines +70 to +72

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could both ImmutableGrpcSenderConfig and ImmutableHttpSenderConfig inherit the interface defaults instead of overriding them to call RetryUtil? The defaults already contain the same OTLP retryable codes. We could then remove RetryUtil and its tests after updating the remaining test-infrastructure caller, ManagedChannelTelemetryExporterBuilder, to obtain the codes from a sender config. This avoids maintaining duplicate lists.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.exporter.otlp.internal;

import com.google.auto.value.AutoValue;
import io.opentelemetry.exporter.internal.RetryUtil;
import io.opentelemetry.sdk.common.export.Compressor;
import io.opentelemetry.sdk.common.export.HttpSenderConfig;
import io.opentelemetry.sdk.common.export.ProxyOptions;
Expand All @@ -14,6 +15,7 @@
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -60,4 +62,9 @@ static HttpSenderConfig create(
@Override
@Nullable
public abstract List<String> getEnabledProtocols();

@Override
public Set<Integer> getRetryableHttpResponseCodes() {
return RetryUtil.retryableHttpResponseCodes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ private ManagedChannelTelemetryExporterBuilder(TelemetryExporterBuilder<T> deleg
private final TelemetryExporterBuilder<T> delegate;

@Nullable private ManagedChannelBuilder<?> channelBuilder;
private boolean isHttps = false;

private final TlsConfigHelper tlsConfigHelper = new TlsConfigHelper();

@Override
public TelemetryExporterBuilder<T> setEndpoint(String endpoint) {
delegate.setEndpoint(endpoint);
URI uri = URI.create(endpoint);
isHttps = uri.getScheme().equals("https");
channelBuilder = ManagedChannelBuilder.forAddress(uri.getHost(), uri.getPort());
if (!uri.getScheme().equals("https")) {
if (!isHttps) {
channelBuilder.usePlaintext();
}
// User-Agent can only be set at the channel level with upstream gRPC client. If a user wants
Expand Down Expand Up @@ -241,10 +243,12 @@ public TelemetryExporterBuilder<T> setInternalTelemetryVersion(
public TelemetryExporter<T> build() {
Runnable shutdownCallback;
if (channelBuilder != null) {
try {
setSslContext(channelBuilder, tlsConfigHelper);
} catch (SSLException e) {
throw new IllegalStateException(e);
if (isHttps) {
try {
setSslContext(channelBuilder, tlsConfigHelper);
} catch (SSLException e) {
throw new IllegalStateException(e);
}
}

ManagedChannel channel = channelBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.sun.net.httpserver.HttpHandler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.export.MemoryMode;
import io.opentelemetry.sdk.common.internal.DaemonThreadFactory;
import io.opentelemetry.sdk.common.impl.DaemonThreadFactory;
import io.opentelemetry.sdk.metrics.Aggregation;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
Expand Down Expand Up @@ -95,7 +95,7 @@ public static PrometheusHttpServerBuilder builder() {
0L,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(),
new DaemonThreadFactory("prometheus-http-server"));
DaemonThreadFactory.create("prometheus-http-server"));
}
HTTPServer.Builder httpServerBuilder = HTTPServer.builder();
if (translationStrategy != TranslationStrategy.UNDERSCORE_ESCAPING_WITH_SUFFIXES) {
Expand Down
Loading
Loading