Skip to content

Commit

Permalink
Remove deprecations from autoconfigure module (#3923)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Dec 17, 2021
1 parent bbbde5d commit 2fb3d63
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 342 deletions.
1 change: 0 additions & 1 deletion sdk-extensions/autoconfigure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ These properties can be used to control the maximum size of recordings per span.
| System property | Environment variable | Description |
|--------------------------|--------------------------|-----------------------------------------------------------------------------------|
| otel.metric.export.interval | OTEL_METRIC_EXPORT_INTERVAL | The interval, in milliseconds, between the start of two export attempts. Default is `60000`.|
| otel.imr.export.interval | OTEL_IMR_EXPORT_INTERVAL | **DEPRECATED for removal in 1.10.0.** The interval, in milliseconds, between the start of two export attempts. Default is `60000`.|

## Customizing the OpenTelemetry SDK

Expand Down
4 changes: 2 additions & 2 deletions sdk-extensions/autoconfigure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ testing {
environment("OTEL_RESOURCE_ATTRIBUTES", "service.name=test,cat=meow")
environment("OTEL_PROPAGATORS", "tracecontext,baggage,b3,b3multi,jaeger,ottrace,xray,test")
environment("OTEL_BSP_SCHEDULE_DELAY", "10")
environment("OTEL_IMR_EXPORT_INTERVAL", "10")
environment("OTEL_METRIC_EXPORT_INTERVAL", "10")
environment("OTEL_EXPORTER_OTLP_HEADERS", "cat=meow,dog=bark")
environment("OTEL_EXPORTER_OTLP_TIMEOUT", "5000")
environment("OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT", "2")
Expand Down Expand Up @@ -168,7 +168,7 @@ testing {
testTask {
environment("OTEL_TRACES_EXPORTER", "none")
environment("OTEL_METRICS_EXPORTER", "prometheus")
environment("OTEL_IMR_EXPORT_INTERVAL", "10")
environment("OTEL_METRIC_EXPORT_INTERVAL", "10")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@

import static java.util.Objects.requireNonNull;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.OpenTelemetrySdkBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import java.util.Collections;
Expand Down Expand Up @@ -160,7 +166,6 @@ public AutoConfiguredOpenTelemetrySdkBuilder setServiceClassLoader(
* Returns a new {@link AutoConfiguredOpenTelemetrySdk} holding components auto-configured using
* the settings of this {@link AutoConfiguredOpenTelemetrySdkBuilder}.
*/
@SuppressWarnings("deprecation") // Using classes which will be made package-private later.
public AutoConfiguredOpenTelemetrySdk build() {
if (!customized) {
customized = true;
Expand All @@ -171,18 +176,38 @@ public AutoConfiguredOpenTelemetrySdk build() {
}

ConfigProperties config = getConfig();
Resource resource =
OpenTelemetryResourceAutoConfiguration.configureResource(config, resourceCustomizer);
OpenTelemetrySdk sdk =
OpenTelemetrySdkAutoConfiguration.newOpenTelemetrySdk(
config,
Resource resource = ResourceConfiguration.configureResource(config, resourceCustomizer);

MeterProvider meterProvider =
MeterProviderConfiguration.configureMeterProvider(resource, config, serviceClassLoader);

SdkTracerProvider tracerProvider =
TracerProviderConfiguration.configureTracerProvider(
resource,
config,
serviceClassLoader,
propagatorCustomizer,
meterProvider,
spanExporterCustomizer,
samplerCustomizer,
setResultAsGlobal);
return AutoConfiguredOpenTelemetrySdk.create(sdk, resource, config);
samplerCustomizer);

ContextPropagators propagators =
PropagatorConfiguration.configurePropagators(
config, serviceClassLoader, propagatorCustomizer);

OpenTelemetrySdkBuilder sdkBuilder =
OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).setPropagators(propagators);

if (meterProvider instanceof SdkMeterProvider) {
sdkBuilder.setMeterProvider((SdkMeterProvider) meterProvider);
}

OpenTelemetrySdk openTelemetrySdk = sdkBuilder.build();

if (setResultAsGlobal) {
GlobalOpenTelemetry.set(openTelemetrySdk);
}

return AutoConfiguredOpenTelemetrySdk.create(openTelemetrySdk, resource, config);
}

private ConfigProperties getConfig() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.sdk.autoconfigure;

import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.metrics.SdkMeterProviderConfigurer;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder;
import io.opentelemetry.sdk.metrics.exemplar.ExemplarFilter;
import io.opentelemetry.sdk.resources.Resource;
import java.util.ServiceLoader;

final class MeterProviderConfiguration {

@SuppressWarnings("deprecation") // Allow call to deprecated GlobalMeterProvider until removed
static MeterProvider configureMeterProvider(
Resource resource, ConfigProperties config, ClassLoader serviceClassLoader) {
SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder().setResource(resource);

// Configure default exemplar filters.
String exemplarFilter = config.getString("otel.metrics.exemplar.filter");
if (exemplarFilter == null) {
exemplarFilter = "with_sampled_trace";
}
switch (exemplarFilter) {
case "none":
meterProviderBuilder.setExemplarFilter(ExemplarFilter.neverSample());
break;
case "all":
meterProviderBuilder.setExemplarFilter(ExemplarFilter.alwaysSample());
break;
case "with_sampled_trace":
default:
meterProviderBuilder.setExemplarFilter(ExemplarFilter.sampleWithTraces());
break;
}

for (SdkMeterProviderConfigurer configurer :
ServiceLoader.load(SdkMeterProviderConfigurer.class, serviceClassLoader)) {
configurer.configure(meterProviderBuilder, config);
}

String exporterName = config.getString("otel.metrics.exporter");
if (exporterName == null || exporterName.equals("none")) {
// In the event no exporters are configured set a noop exporter
return MeterProvider.noop();
}
MetricExporterConfiguration.configureExporter(
exporterName, config, serviceClassLoader, meterProviderBuilder);

SdkMeterProvider meterProvider = meterProviderBuilder.build();

// Make sure metrics shut down when JVM shuts down.
Runtime.getRuntime().addShutdownHook(new Thread(meterProvider::close));

return meterProvider;
}

private MeterProviderConfiguration() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ private static void configurePeriodicMetricReader(
MetricExporter exporter) {

Duration exportInterval = config.getDuration("otel.metric.export.interval");
if (exportInterval == null) {
exportInterval = config.getDuration("otel.imr.export.interval");
}
if (exportInterval == null) {
exportInterval = Duration.ofMinutes(1);
}
Expand Down
Loading

0 comments on commit 2fb3d63

Please sign in to comment.