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 @@ -10,20 +10,25 @@
import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.readFileBytes;
import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.validateEndpoint;

import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigException;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.common.ComponentLoader;
import io.opentelemetry.exporter.internal.IncubatingExporterBuilderUtil;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.common.InternalTelemetryVersion;
import io.opentelemetry.sdk.common.export.MemoryMode;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.net.URL;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
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 @@ -48,6 +53,7 @@ public static String getStructuredConfigOtlpProtocol(DeclarativeConfigProperties
public static void configureOtlpExporterBuilder(
String dataType,
DeclarativeConfigProperties config,
ConfigProvider configProvider,
Consumer<ComponentLoader> setComponentLoader,
Consumer<String> setEndpoint,
BiConsumer<String, String> addHeader,
Expand All @@ -57,7 +63,8 @@ public static void configureOtlpExporterBuilder(
BiConsumer<byte[], byte[]> setClientTls,
Consumer<RetryPolicy> setRetryPolicy,
Consumer<MemoryMode> setMemoryMode,
boolean isHttpProtobuf) {
boolean isHttpProtobuf,
Consumer<InternalTelemetryVersion> internalTelemetryVersionConsumer) {
setComponentLoader.accept(config.getComponentLoader());

URL endpoint = validateEndpoint(config.getString("endpoint"), isHttpProtobuf);
Expand Down Expand Up @@ -119,6 +126,30 @@ public static void configureOtlpExporterBuilder(
}

IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, setMemoryMode);

InternalTelemetryVersion internalTelemetryVersion = getInternalTelemetryVersion(configProvider);
if (internalTelemetryVersion != null) {
internalTelemetryVersionConsumer.accept(internalTelemetryVersion);
}
}

@Nullable
private static InternalTelemetryVersion getInternalTelemetryVersion(
ConfigProvider configProvider) {
String internalTelemetryVersion =
configProvider.getInstrumentationConfig("otel_sdk").getString("internal_telemetry_version");
if (internalTelemetryVersion == null) {
return null;
}
switch (internalTelemetryVersion.toLowerCase(Locale.ROOT)) {
case "legacy":
return InternalTelemetryVersion.LEGACY;
case "latest":
return InternalTelemetryVersion.LATEST;
default:
throw new DeclarativeConfigException(
"Invalid sdk telemetry version: " + internalTelemetryVersion);
}
}

private OtlpDeclarativeConfigUtil() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.DATA_TYPE_LOGS;

import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter;
import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ExtendedComponentProvider;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;

/**
Expand All @@ -19,7 +20,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpGrpcLogRecordExporterComponentProvider implements ComponentProvider {
public class OtlpGrpcLogRecordExporterComponentProvider implements ExtendedComponentProvider {

@Override
public Class<LogRecordExporter> getType() {
Expand All @@ -32,12 +33,14 @@ public String getName() {
}

@Override
public LogRecordExporter create(DeclarativeConfigProperties config) {
public LogRecordExporter create(
DeclarativeConfigProperties config, ConfigProvider configProvider) {
OtlpGrpcLogRecordExporterBuilder builder = grpcBuilder();

OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_LOGS,
config,
configProvider,
builder::setComponentLoader,
builder::setEndpoint,
builder::addHeader,
Expand All @@ -47,7 +50,8 @@ public LogRecordExporter create(DeclarativeConfigProperties config) {
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ false);
/* isHttpProtobuf= */ false,
builder::setInternalTelemetryVersion);

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.DATA_TYPE_METRICS;

import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.exporter.internal.IncubatingExporterBuilderUtil;
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter;
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ExtendedComponentProvider;
import io.opentelemetry.sdk.metrics.export.MetricExporter;

/**
Expand All @@ -20,7 +21,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpGrpcMetricExporterComponentProvider implements ComponentProvider {
public class OtlpGrpcMetricExporterComponentProvider implements ExtendedComponentProvider {

@Override
public Class<MetricExporter> getType() {
Expand All @@ -33,12 +34,13 @@ public String getName() {
}

@Override
public MetricExporter create(DeclarativeConfigProperties config) {
public MetricExporter create(DeclarativeConfigProperties config, ConfigProvider configProvider) {
OtlpGrpcMetricExporterBuilder builder = grpcBuilder();

OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_METRICS,
config,
configProvider,
builder::setComponentLoader,
builder::setEndpoint,
builder::addHeader,
Expand All @@ -48,7 +50,8 @@ public MetricExporter create(DeclarativeConfigProperties config) {
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ false);
/* isHttpProtobuf= */ false,
builder::setInternalTelemetryVersion);
IncubatingExporterBuilderUtil.configureOtlpAggregationTemporality(
config, builder::setAggregationTemporalitySelector);
IncubatingExporterBuilderUtil.configureOtlpHistogramDefaultAggregation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.DATA_TYPE_TRACES;

import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ExtendedComponentProvider;
import io.opentelemetry.sdk.trace.export.SpanExporter;

/**
Expand All @@ -19,7 +20,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpGrpcSpanExporterComponentProvider implements ComponentProvider {
public class OtlpGrpcSpanExporterComponentProvider implements ExtendedComponentProvider {

@Override
public Class<SpanExporter> getType() {
Expand All @@ -32,12 +33,13 @@ public String getName() {
}

@Override
public SpanExporter create(DeclarativeConfigProperties config) {
public SpanExporter create(DeclarativeConfigProperties config, ConfigProvider configProvider) {
OtlpGrpcSpanExporterBuilder builder = grpcBuilder();

OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_TRACES,
config,
configProvider,
builder::setComponentLoader,
builder::setEndpoint,
builder::addHeader,
Expand All @@ -47,7 +49,8 @@ public SpanExporter create(DeclarativeConfigProperties config) {
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ false);
/* isHttpProtobuf= */ false,
builder::setInternalTelemetryVersion);

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.DATA_TYPE_LOGS;

import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter;
import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ExtendedComponentProvider;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;

/**
Expand All @@ -19,7 +20,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpHttpLogRecordExporterComponentProvider implements ComponentProvider {
public class OtlpHttpLogRecordExporterComponentProvider implements ExtendedComponentProvider {

@Override
public Class<LogRecordExporter> getType() {
Expand All @@ -32,12 +33,14 @@ public String getName() {
}

@Override
public LogRecordExporter create(DeclarativeConfigProperties config) {
public LogRecordExporter create(
DeclarativeConfigProperties config, ConfigProvider configProvider) {
OtlpHttpLogRecordExporterBuilder builder = httpBuilder();

OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_LOGS,
config,
configProvider,
builder::setComponentLoader,
builder::setEndpoint,
builder::addHeader,
Expand All @@ -47,7 +50,8 @@ public LogRecordExporter create(DeclarativeConfigProperties config) {
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ true);
/* isHttpProtobuf= */ true,
builder::setInternalTelemetryVersion);

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.DATA_TYPE_METRICS;

import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.exporter.internal.IncubatingExporterBuilderUtil;
import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter;
import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ExtendedComponentProvider;
import io.opentelemetry.sdk.metrics.export.MetricExporter;

/**
Expand All @@ -20,7 +21,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpHttpMetricExporterComponentProvider implements ComponentProvider {
public class OtlpHttpMetricExporterComponentProvider implements ExtendedComponentProvider {

@Override
public Class<MetricExporter> getType() {
Expand All @@ -33,12 +34,13 @@ public String getName() {
}

@Override
public MetricExporter create(DeclarativeConfigProperties config) {
public MetricExporter create(DeclarativeConfigProperties config, ConfigProvider configProvider) {
OtlpHttpMetricExporterBuilder builder = httpBuilder();

OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_METRICS,
config,
configProvider,
builder::setComponentLoader,
builder::setEndpoint,
builder::addHeader,
Expand All @@ -48,7 +50,8 @@ public MetricExporter create(DeclarativeConfigProperties config) {
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ true);
/* isHttpProtobuf= */ true,
builder::setInternalTelemetryVersion);
IncubatingExporterBuilderUtil.configureOtlpAggregationTemporality(
config, builder::setAggregationTemporalitySelector);
IncubatingExporterBuilderUtil.configureOtlpHistogramDefaultAggregation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.DATA_TYPE_TRACES;

import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ExtendedComponentProvider;
import io.opentelemetry.sdk.trace.export.SpanExporter;

/**
Expand All @@ -19,7 +20,7 @@
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class OtlpHttpSpanExporterComponentProvider implements ComponentProvider {
public class OtlpHttpSpanExporterComponentProvider implements ExtendedComponentProvider {

@Override
public Class<SpanExporter> getType() {
Expand All @@ -32,12 +33,13 @@ public String getName() {
}

@Override
public SpanExporter create(DeclarativeConfigProperties config) {
public SpanExporter create(DeclarativeConfigProperties config, ConfigProvider configProvider) {
OtlpHttpSpanExporterBuilder builder = httpBuilder();

OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_TRACES,
config,
configProvider,
builder::setComponentLoader,
builder::setEndpoint,
builder::addHeader,
Expand All @@ -47,7 +49,8 @@ public SpanExporter create(DeclarativeConfigProperties config) {
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ true);
/* isHttpProtobuf= */ true,
builder::setInternalTelemetryVersion);

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.sdk.autoconfigure.spi.internal;

import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;

/**
* Extended version of {@link ComponentProvider} that allows access to the {@link ConfigProvider}.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public interface ExtendedComponentProvider extends ComponentProvider {

/**
* Configure an instance of the SDK extension component according to the {@code config}.
*
* <p>While this is the method called by the SDK, implementations can safely only implement {@link
* #create(DeclarativeConfigProperties)} since the default implementation delegates to it.
*
* @param config the configuration provided where the component is referenced in a configuration
* file.
* @param configProvider the configuration provider.
* @return an instance the SDK extension component
*/
Object create(DeclarativeConfigProperties config, ConfigProvider configProvider);

@Override
default Object create(DeclarativeConfigProperties config) {
return create(config, ConfigProvider.noop());
}
Copy link
Member Author

Choose a reason for hiding this comment

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

For the OTLP epxorters to be able to access instrumentation/development.java.otel_sdk, I needed to figure out a strategy to provide access to ConfigProvider. Considered adding an accessor to DeclarativeConfigProperties but couldn't make it work.

Also considered a breaking change to ComponentProvider to add ConfigProvider param to create. But breaking change means churn and only a select few ComponentProvider implementations will need access ConfigProvider.

This pattern strikes a balance.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not deep on the general design of the types, but an idea that came to mind is just adding a getter to DeclarativeConfigProperties. While purists might want it to be "only the config for that component", we already have ComponentLoader there which seems to break from that, an escape hatch into the global config doesn't seem that bad and has no churn (I didn't verify it's possible but couldn't think of a reason it wouldn't be)

Copy link
Contributor

Choose a reason for hiding this comment

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

Considered adding an accessor to DeclarativeConfigProperties but couldn't make it work.

Oops! What was the problem with that?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was a couple things:

  • chicken and egg problem, where SdkConfigProvider is initialized from DeclarativeConfigProperites, and DeclarativeConfigProperites needs a ref to ConfigProvider during initialization. Can solve with something like an Atomic reference, but gets sloppy.
  • we make liberal use of a stateless DeclarativeConfigProperites.empty() instance, which would need to now hold a ref to a specific ConfigProvider instance

I could probably make it all work, but the amount of impacted code was growing quickly so I looked for other options before learning the full extent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks - sorry for the noise that indeed looks worse than this approach which I could check by looking closer at the code

}
Loading
Loading