Skip to content

Commit

Permalink
Refactored OTLP exporter schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg committed Dec 4, 2024
1 parent 5bf6a97 commit 9d0c25e
Show file tree
Hide file tree
Showing 28 changed files with 512 additions and 409 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ public static String getOtlpProtocol(String dataType, ConfigProperties config) {
return config.getString("otel.exporter.otlp.protocol", PROTOCOL_GRPC);
}

/** Determine the configured OTLP protocol for the {@code dataType}. */
public static String getStructuredConfigOtlpProtocol(StructuredConfigProperties config) {
// NOTE: The default OTLP protocol is different for declarative config than for env var / system
// property based config. This is intentional. OpenTelemetry changed the default protocol
// recommendation from grpc to http/protobuf, but the autoconfigure's env var / system property
// based config did not update to reflect this before stabilizing, and changing is a breaking
// change requiring a major version bump. Declarative config is not yet stable and therefore can
// switch to the current default recommendation, which aligns also aligns with the behavior of
// the OpenTelemetry Java Agent 2.x+.
return config.getString("protocol", PROTOCOL_HTTP_PROTOBUF);
}

/** Invoke the setters with the OTLP configuration for the {@code dataType}. */
@SuppressWarnings("TooManyParameters")
public static void configureOtlpExporterBuilder(
Expand Down Expand Up @@ -176,9 +164,8 @@ public static void configureOtlpExporterBuilder(
Consumer<byte[]> setTrustedCertificates,
BiConsumer<byte[], byte[]> setClientTls,
Consumer<RetryPolicy> setRetryPolicy,
Consumer<MemoryMode> setMemoryMode) {
String protocol = getStructuredConfigOtlpProtocol(config);
boolean isHttpProtobuf = protocol.equals(PROTOCOL_HTTP_PROTOBUF);
Consumer<MemoryMode> setMemoryMode,
boolean isHttpProtobuf) {
URL endpoint = validateEndpoint(config.getString("endpoint"), isHttpProtobuf);
if (endpoint != null) {
setEndpoint.accept(endpoint.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.otlp.internal;

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

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.StructuredConfigProperties;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;

/**
* Declarative configuration SPI implementation for {@link OtlpGrpcLogRecordExporter}.
*
* <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<LogRecordExporter> {

@Override
public Class<LogRecordExporter> getType() {
return LogRecordExporter.class;
}

@Override
public String getName() {
return "otlp_grpc";
}

@Override
public LogRecordExporter create(StructuredConfigProperties config) {
OtlpGrpcLogRecordExporterBuilder builder = grpcBuilder();

OtlpConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_LOGS,
config,
builder::setEndpoint,
builder::addHeader,
builder::setCompression,
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ false);

return builder.build();
}

// Visible for testing
OtlpGrpcLogRecordExporterBuilder grpcBuilder() {
return OtlpGrpcLogRecordExporter.builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.otlp.internal;

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

import io.opentelemetry.exporter.internal.ExporterBuilderUtil;
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.StructuredConfigProperties;
import io.opentelemetry.sdk.metrics.export.MetricExporter;

/**
* Declarative configuration SPI implementation for {@link OtlpGrpcMetricExporter}.
*
* <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<MetricExporter> {

@Override
public Class<MetricExporter> getType() {
return MetricExporter.class;
}

@Override
public String getName() {
return "otlp_grpc";
}

@Override
public MetricExporter create(StructuredConfigProperties config) {
OtlpGrpcMetricExporterBuilder builder = grpcBuilder();

OtlpConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_METRICS,
config,
builder::setEndpoint,
builder::addHeader,
builder::setCompression,
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ false);
ExporterBuilderUtil.configureOtlpAggregationTemporality(
config, builder::setAggregationTemporalitySelector);
ExporterBuilderUtil.configureOtlpHistogramDefaultAggregation(
config, builder::setDefaultAggregationSelector);

return builder.build();
}

// Visible for testing
OtlpGrpcMetricExporterBuilder grpcBuilder() {
return OtlpGrpcMetricExporter.builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.otlp.internal;

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

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.StructuredConfigProperties;
import io.opentelemetry.sdk.trace.export.SpanExporter;

/**
* Declarative configuration SPI implementation for {@link OtlpGrpcSpanExporter}.
*
* <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<SpanExporter> {

@Override
public Class<SpanExporter> getType() {
return SpanExporter.class;
}

@Override
public String getName() {
return "otlp_grpc";
}

@Override
public SpanExporter create(StructuredConfigProperties config) {
OtlpGrpcSpanExporterBuilder builder = grpcBuilder();

OtlpConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_TRACES,
config,
builder::setEndpoint,
builder::addHeader,
builder::setCompression,
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ false);

return builder.build();
}

// Visible for testing
OtlpGrpcSpanExporterBuilder grpcBuilder() {
return OtlpGrpcSpanExporter.builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.otlp.internal;

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

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.StructuredConfigProperties;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;

/**
* Declarative configuration SPI implementation for {@link OtlpHttpLogRecordExporter}.
*
* <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<LogRecordExporter> {

@Override
public Class<LogRecordExporter> getType() {
return LogRecordExporter.class;
}

@Override
public String getName() {
return "otlp_http";
}

@Override
public LogRecordExporter create(StructuredConfigProperties config) {
OtlpHttpLogRecordExporterBuilder builder = httpBuilder();

OtlpConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_LOGS,
config,
builder::setEndpoint,
builder::addHeader,
builder::setCompression,
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ true);

return builder.build();
}

// Visible for testing
OtlpHttpLogRecordExporterBuilder httpBuilder() {
return OtlpHttpLogRecordExporter.builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.otlp.internal;

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

import io.opentelemetry.exporter.internal.ExporterBuilderUtil;
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.StructuredConfigProperties;
import io.opentelemetry.sdk.metrics.export.MetricExporter;

/**
* Declarative configuration SPI implementation for {@link OtlpHttpMetricExporter}.
*
* <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<MetricExporter> {

@Override
public Class<MetricExporter> getType() {
return MetricExporter.class;
}

@Override
public String getName() {
return "otlp_http";
}

@Override
public MetricExporter create(StructuredConfigProperties config) {
OtlpHttpMetricExporterBuilder builder = httpBuilder();

OtlpConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_METRICS,
config,
builder::setEndpoint,
builder::addHeader,
builder::setCompression,
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ true);
ExporterBuilderUtil.configureOtlpAggregationTemporality(
config, builder::setAggregationTemporalitySelector);
ExporterBuilderUtil.configureOtlpHistogramDefaultAggregation(
config, builder::setDefaultAggregationSelector);

return builder.build();
}

// Visible for testing
OtlpHttpMetricExporterBuilder httpBuilder() {
return OtlpHttpMetricExporter.builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.otlp.internal;

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

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.StructuredConfigProperties;
import io.opentelemetry.sdk.trace.export.SpanExporter;

/**
* Declarative configuration SPI implementation for {@link OtlpHttpSpanExporter}.
*
* <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<SpanExporter> {

@Override
public Class<SpanExporter> getType() {
return SpanExporter.class;
}

@Override
public String getName() {
return "otlp_http";
}

@Override
public SpanExporter create(StructuredConfigProperties config) {
OtlpHttpSpanExporterBuilder builder = httpBuilder();

OtlpConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_TRACES,
config,
builder::setEndpoint,
builder::addHeader,
builder::setCompression,
builder::setTimeout,
builder::setTrustedCertificates,
builder::setClientTls,
builder::setRetryPolicy,
builder::setMemoryMode,
/* isHttpProtobuf= */ true);

return builder.build();
}

// Visible for testing
OtlpHttpSpanExporterBuilder httpBuilder() {
return OtlpHttpSpanExporter.builder();
}
}
Loading

0 comments on commit 9d0c25e

Please sign in to comment.