diff --git a/integration-tests/graal-incubating/build.gradle.kts b/integration-tests/graal-incubating/build.gradle.kts index d050e01dee8..7ad93ffb947 100644 --- a/integration-tests/graal-incubating/build.gradle.kts +++ b/integration-tests/graal-incubating/build.gradle.kts @@ -18,6 +18,7 @@ sourceSets { dependencies { implementation(project(":sdk:all")) implementation(project(":sdk:trace-shaded-deps")) + implementation(project(":sdk:testing")) implementation(project(":exporters:otlp:all")) implementation(project(":api:incubator")) } diff --git a/integration-tests/graal-incubating/src/test/java/io/opentelemetry/integrationtests/graal/IncubatingApiTests.java b/integration-tests/graal-incubating/src/test/java/io/opentelemetry/integrationtests/graal/IncubatingApiTests.java index 8d705419452..06ddcd006e1 100644 --- a/integration-tests/graal-incubating/src/test/java/io/opentelemetry/integrationtests/graal/IncubatingApiTests.java +++ b/integration-tests/graal-incubating/src/test/java/io/opentelemetry/integrationtests/graal/IncubatingApiTests.java @@ -7,12 +7,31 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder; import io.opentelemetry.api.incubator.logs.ExtendedLogger; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleCounter; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleGauge; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleHistogram; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleUpDownCounter; +import io.opentelemetry.api.incubator.metrics.ExtendedLongCounter; import io.opentelemetry.api.incubator.metrics.ExtendedLongCounterBuilder; +import io.opentelemetry.api.incubator.metrics.ExtendedLongGauge; +import io.opentelemetry.api.incubator.metrics.ExtendedLongHistogram; +import io.opentelemetry.api.incubator.metrics.ExtendedLongUpDownCounter; +import io.opentelemetry.api.incubator.trace.ExtendedSpanBuilder; import io.opentelemetry.api.incubator.trace.ExtendedTracer; import io.opentelemetry.api.logs.LoggerProvider; +import io.opentelemetry.api.metrics.Meter; import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.api.trace.TracerProvider; +import io.opentelemetry.sdk.logs.SdkLoggerProvider; +import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor; +import io.opentelemetry.sdk.metrics.SdkMeterProvider; +import io.opentelemetry.sdk.testing.exporter.InMemoryLogRecordExporter; +import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; +import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import org.junit.jupiter.api.Test; class IncubatingApiTests { @@ -23,4 +42,63 @@ void incubatingApiIsLoadedViaReflection() { assertThat(MeterProvider.noop().get("test").counterBuilder("test")) .isInstanceOf(ExtendedLongCounterBuilder.class); } + + @Test + void incubatingLogSdk() { + InMemoryLogRecordExporter exporter = InMemoryLogRecordExporter.create(); + SdkLoggerProvider loggerProvider = + SdkLoggerProvider.builder() + .addLogRecordProcessor(SimpleLogRecordProcessor.create(exporter)) + .build(); + + ExtendedLogger logger = (ExtendedLogger) loggerProvider.get("logger"); + logger.isEnabled(); + ((ExtendedLogRecordBuilder) logger.logRecordBuilder()).setBody("message").emit(); + } + + @Test + void incubatingTraceSdk() { + InMemorySpanExporter exporter = InMemorySpanExporter.create(); + SdkTracerProvider tracerProvider = + SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(exporter)).build(); + + ExtendedTracer tracer = (ExtendedTracer) tracerProvider.get("tracer"); + tracer.isEnabled(); + ((ExtendedSpanBuilder) tracer.spanBuilder("span")).startAndRun(() -> {}); + } + + @Test + void incubatingMetricSdk() { + InMemoryMetricReader reader = InMemoryMetricReader.create(); + SdkMeterProvider meterProvider = + SdkMeterProvider.builder().registerMetricReader(reader).build(); + + Meter meter = meterProvider.get("meter"); + + ExtendedLongCounter longCounter = + (ExtendedLongCounter) meter.counterBuilder("longCounter").build(); + longCounter.isEnabled(); + ExtendedDoubleCounter doubleCounter = + (ExtendedDoubleCounter) meter.counterBuilder("doubleCounter").ofDoubles().build(); + doubleCounter.isEnabled(); + ExtendedLongUpDownCounter longUpDownCounter = + (ExtendedLongUpDownCounter) meter.upDownCounterBuilder("longUpDownCounter").build(); + longUpDownCounter.isEnabled(); + ExtendedDoubleUpDownCounter doubleUpDownCounter = + (ExtendedDoubleUpDownCounter) + meter.upDownCounterBuilder("doubleUpDownCounter").ofDoubles().build(); + doubleUpDownCounter.isEnabled(); + ExtendedDoubleHistogram doubleHistogram = + (ExtendedDoubleHistogram) meter.histogramBuilder("doubleHistogram").build(); + doubleHistogram.isEnabled(); + ExtendedLongHistogram longHistogram = + (ExtendedLongHistogram) meter.histogramBuilder("longHistogram").ofLongs().build(); + longHistogram.isEnabled(); + ExtendedDoubleGauge doubleGauge = + (ExtendedDoubleGauge) meter.gaugeBuilder("doubleGauge").build(); + doubleGauge.isEnabled(); + ExtendedLongGauge longGauge = + (ExtendedLongGauge) meter.gaugeBuilder("longGauge").ofLongs().build(); + longGauge.isEnabled(); + } } diff --git a/sdk-extensions/autoconfigure/build.gradle.kts b/sdk-extensions/autoconfigure/build.gradle.kts index fb73bdaa6b6..7f0077178e5 100644 --- a/sdk-extensions/autoconfigure/build.gradle.kts +++ b/sdk-extensions/autoconfigure/build.gradle.kts @@ -10,7 +10,7 @@ dependencies { api(project(":sdk:all")) api(project(":sdk-extensions:autoconfigure-spi")) - implementation(project(":api:incubator")) + compileOnly(project(":api:incubator")) annotationProcessor("com.google.auto.value:auto-value") @@ -23,6 +23,11 @@ dependencies { testing { suites { + register("testIncubating") { + dependencies { + implementation(project(":api:incubator")) + } + } register("testAutoConfigureOrder") { targets { all { diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index 1c293a002cd..f6ddd6c6f85 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -8,7 +8,6 @@ import static java.util.Objects.requireNonNull; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.api.incubator.events.GlobalEventLoggerProvider; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.sdk.OpenTelemetrySdk; @@ -26,7 +25,6 @@ import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; import io.opentelemetry.sdk.logs.export.LogRecordExporter; -import io.opentelemetry.sdk.logs.internal.SdkEventLoggerProvider; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; import io.opentelemetry.sdk.metrics.export.MetricExporter; @@ -65,6 +63,19 @@ */ public final class AutoConfiguredOpenTelemetrySdkBuilder implements AutoConfigurationCustomizer { + private static final boolean INCUBATOR_AVAILABLE; + + static { + boolean incubatorAvailable = false; + try { + Class.forName("io.opentelemetry.api.incubator.events.GlobalEventLoggerProvider"); + incubatorAvailable = true; + } catch (ClassNotFoundException e) { + // Not available + } + INCUBATOR_AVAILABLE = incubatorAvailable; + } + private static final Logger logger = Logger.getLogger(AutoConfiguredOpenTelemetrySdkBuilder.class.getName()); @@ -592,8 +603,9 @@ private void maybeSetAsGlobal(OpenTelemetrySdk openTelemetrySdk) { return; } GlobalOpenTelemetry.set(openTelemetrySdk); - GlobalEventLoggerProvider.set( - SdkEventLoggerProvider.create(openTelemetrySdk.getSdkLoggerProvider())); + if (INCUBATOR_AVAILABLE) { + IncubatingUtil.setGlobalEventLoggerProvider(openTelemetrySdk.getSdkLoggerProvider()); + } logger.log( Level.FINE, "Global OpenTelemetry set to {0} by autoconfiguration", openTelemetrySdk); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/IncubatingUtil.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/IncubatingUtil.java new file mode 100644 index 00000000000..f66e007cf34 --- /dev/null +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/IncubatingUtil.java @@ -0,0 +1,24 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.autoconfigure; + +import io.opentelemetry.api.incubator.events.GlobalEventLoggerProvider; +import io.opentelemetry.sdk.logs.SdkLoggerProvider; +import io.opentelemetry.sdk.logs.internal.SdkEventLoggerProvider; + +/** + * Utilities for interacting with {@code io.opentelemetry:opentelemetry-api-incubator}, which is not + * guaranteed to be present on the classpath. For all methods, callers MUST first separately + * reflectively confirm that the incubator is available on the classpath. + */ +final class IncubatingUtil { + + private IncubatingUtil() {} + + static void setGlobalEventLoggerProvider(SdkLoggerProvider sdkLoggerProvider) { + GlobalEventLoggerProvider.set(SdkEventLoggerProvider.create(sdkLoggerProvider)); + } +} diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java index f74b248c04d..b42c1936130 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java @@ -26,7 +26,6 @@ import io.github.netmikey.logunit.api.LogCapturer; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.incubator.events.GlobalEventLoggerProvider; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanId; import io.opentelemetry.api.trace.TraceId; @@ -49,7 +48,6 @@ import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; -import io.opentelemetry.sdk.logs.internal.SdkEventLoggerProvider; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; import io.opentelemetry.sdk.metrics.export.MetricReader; @@ -156,7 +154,6 @@ public SdkLoggerProviderBuilder apply( @BeforeEach void resetGlobal() { GlobalOpenTelemetry.resetForTest(); - GlobalEventLoggerProvider.resetForTest(); builder = AutoConfiguredOpenTelemetrySdk.builder() .addPropertiesSupplier(disableExportPropertySupplier()); @@ -456,7 +453,6 @@ void builder_setResultAsGlobalFalse() { OpenTelemetrySdk openTelemetry = builder.build().getOpenTelemetrySdk(); assertThat(GlobalOpenTelemetry.get()).extracting("delegate").isNotSameAs(openTelemetry); - assertThat(GlobalEventLoggerProvider.get()).isNotSameAs(openTelemetry.getSdkLoggerProvider()); } @Test @@ -464,10 +460,6 @@ void builder_setResultAsGlobalTrue() { OpenTelemetrySdk openTelemetry = builder.setResultAsGlobal().build().getOpenTelemetrySdk(); assertThat(GlobalOpenTelemetry.get()).extracting("delegate").isSameAs(openTelemetry); - assertThat(GlobalEventLoggerProvider.get()) - .isInstanceOf(SdkEventLoggerProvider.class) - .extracting("delegateLoggerProvider") - .isSameAs(openTelemetry.getSdkLoggerProvider()); } @Test diff --git a/sdk-extensions/autoconfigure/src/testIncubating/java/io/opentelemetry/sdk/autoconfigure/AutoconfigureGlobalEventLoggerProviderTest.java b/sdk-extensions/autoconfigure/src/testIncubating/java/io/opentelemetry/sdk/autoconfigure/AutoconfigureGlobalEventLoggerProviderTest.java new file mode 100644 index 00000000000..8ca85372ada --- /dev/null +++ b/sdk-extensions/autoconfigure/src/testIncubating/java/io/opentelemetry/sdk/autoconfigure/AutoconfigureGlobalEventLoggerProviderTest.java @@ -0,0 +1,62 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.autoconfigure; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.incubator.events.GlobalEventLoggerProvider; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.logs.internal.SdkEventLoggerProvider; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class AutoconfigureGlobalEventLoggerProviderTest { + + private AutoConfiguredOpenTelemetrySdkBuilder builder; + + @BeforeEach + void resetGlobal() { + GlobalOpenTelemetry.resetForTest(); + GlobalEventLoggerProvider.resetForTest(); + builder = + AutoConfiguredOpenTelemetrySdk.builder() + .addPropertiesSupplier(disableExportPropertySupplier()); + } + + @Test + void builder_setResultAsGlobalFalse() { + GlobalOpenTelemetry.set(OpenTelemetry.noop()); + + OpenTelemetrySdk openTelemetry = builder.build().getOpenTelemetrySdk(); + + assertThat(GlobalOpenTelemetry.get()).extracting("delegate").isNotSameAs(openTelemetry); + assertThat(GlobalEventLoggerProvider.get()).isNotSameAs(openTelemetry.getSdkLoggerProvider()); + } + + @Test + void builder_setResultAsGlobalTrue() { + OpenTelemetrySdk openTelemetry = builder.setResultAsGlobal().build().getOpenTelemetrySdk(); + + assertThat(GlobalOpenTelemetry.get()).extracting("delegate").isSameAs(openTelemetry); + assertThat(GlobalEventLoggerProvider.get()) + .isInstanceOf(SdkEventLoggerProvider.class) + .extracting("delegateLoggerProvider") + .isSameAs(openTelemetry.getSdkLoggerProvider()); + } + + private static Supplier> disableExportPropertySupplier() { + Map props = new HashMap<>(); + props.put("otel.metrics.exporter", "none"); + props.put("otel.traces.exporter", "none"); + props.put("otel.logs.exporter", "none"); + return () -> props; + } +} diff --git a/sdk/logs/build.gradle.kts b/sdk/logs/build.gradle.kts index 7c8c020d6a2..c0c740d3743 100644 --- a/sdk/logs/build.gradle.kts +++ b/sdk/logs/build.gradle.kts @@ -12,7 +12,7 @@ otelJava.moduleName.set("io.opentelemetry.sdk.logs") dependencies { api(project(":api:all")) api(project(":sdk:common")) - implementation(project(":api:incubator")) + compileOnly(project(":api:incubator")) annotationProcessor("com.google.auto.value:auto-value") @@ -21,3 +21,21 @@ dependencies { testImplementation("org.awaitility:awaitility") testImplementation("com.google.guava:guava") } + +testing { + suites { + register("testIncubating") { + dependencies { + implementation(project(":sdk:testing")) + implementation(project(":api:incubator")) + implementation("com.google.guava:guava") + } + } + } +} + +tasks { + check { + dependsOn(testing.suites) + } +} diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java new file mode 100644 index 00000000000..ba1d0e6cfd2 --- /dev/null +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java @@ -0,0 +1,85 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.logs; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder; +import io.opentelemetry.api.logs.Severity; +import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import java.time.Instant; +import java.util.concurrent.TimeUnit; + +/** SDK implementation of {@link ExtendedLogRecordBuilder}. */ +final class ExtendedSdkLogRecordBuilder extends SdkLogRecordBuilder + implements ExtendedLogRecordBuilder { + + ExtendedSdkLogRecordBuilder( + LoggerSharedState loggerSharedState, InstrumentationScopeInfo instrumentationScopeInfo) { + super(loggerSharedState, instrumentationScopeInfo); + } + + @Override + public ExtendedSdkLogRecordBuilder setTimestamp(long timestamp, TimeUnit unit) { + super.setTimestamp(timestamp, unit); + return this; + } + + @Override + public ExtendedSdkLogRecordBuilder setTimestamp(Instant instant) { + super.setTimestamp(instant); + return this; + } + + @Override + public ExtendedSdkLogRecordBuilder setObservedTimestamp(long timestamp, TimeUnit unit) { + super.setObservedTimestamp(timestamp, unit); + return this; + } + + @Override + public ExtendedSdkLogRecordBuilder setObservedTimestamp(Instant instant) { + super.setObservedTimestamp(instant); + return this; + } + + @Override + public ExtendedSdkLogRecordBuilder setContext(Context context) { + super.setContext(context); + return this; + } + + @Override + public ExtendedSdkLogRecordBuilder setSeverity(Severity severity) { + super.setSeverity(severity); + return this; + } + + @Override + public ExtendedSdkLogRecordBuilder setSeverityText(String severityText) { + super.setSeverityText(severityText); + return this; + } + + @Override + public ExtendedSdkLogRecordBuilder setBody(String body) { + super.setBody(body); + return this; + } + + @Override + public ExtendedSdkLogRecordBuilder setBody(Value value) { + super.setBody(value); + return this; + } + + @Override + public ExtendedSdkLogRecordBuilder setAttribute(AttributeKey key, T value) { + super.setAttribute(key, value); + return this; + } +} diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogger.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogger.java new file mode 100644 index 00000000000..67813bb933d --- /dev/null +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogger.java @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.logs; + +import io.opentelemetry.api.incubator.logs.ExtendedLogger; +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import io.opentelemetry.sdk.logs.internal.LoggerConfig; + +/** SDK implementation of {@link ExtendedLogger}. */ +final class ExtendedSdkLogger extends SdkLogger implements ExtendedLogger { + + private final boolean loggerEnabled; + + ExtendedSdkLogger( + LoggerSharedState loggerSharedState, + InstrumentationScopeInfo instrumentationScopeInfo, + LoggerConfig loggerConfig) { + super(loggerSharedState, instrumentationScopeInfo, loggerConfig); + this.loggerEnabled = loggerConfig.isEnabled(); + } + + @Override + public boolean isEnabled() { + return loggerEnabled; + } +} diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/IncubatingUtil.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/IncubatingUtil.java new file mode 100644 index 00000000000..fd7582644be --- /dev/null +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/IncubatingUtil.java @@ -0,0 +1,31 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.logs; + +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import io.opentelemetry.sdk.logs.internal.LoggerConfig; + +/** + * Utilities for interacting with {@code io.opentelemetry:opentelemetry-api-incubator}, which is not + * guaranteed to be present on the classpath. For all methods, callers MUST first separately + * reflectively confirm that the incubator is available on the classpath. + */ +final class IncubatingUtil { + + private IncubatingUtil() {} + + static SdkLogger createExtendedLogger( + LoggerSharedState sharedState, + InstrumentationScopeInfo instrumentationScopeInfo, + LoggerConfig tracerConfig) { + return new ExtendedSdkLogger(sharedState, instrumentationScopeInfo, tracerConfig); + } + + static SdkLogRecordBuilder createExtendedLogRecordBuilder( + LoggerSharedState loggerSharedState, InstrumentationScopeInfo instrumentationScopeInfo) { + return new ExtendedSdkLogRecordBuilder(loggerSharedState, instrumentationScopeInfo); + } +} diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java index ce77d076730..ce43bc8d2c6 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java @@ -7,7 +7,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder; import io.opentelemetry.api.logs.LogRecordBuilder; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.Span; @@ -19,7 +18,7 @@ import javax.annotation.Nullable; /** SDK implementation of {@link LogRecordBuilder}. */ -final class SdkLogRecordBuilder implements ExtendedLogRecordBuilder { +class SdkLogRecordBuilder implements LogRecordBuilder { private final LoggerSharedState loggerSharedState; private final LogLimits logLimits; diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogger.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogger.java index 72fb9f0b356..8ac51603073 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogger.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogger.java @@ -5,7 +5,6 @@ package io.opentelemetry.sdk.logs; -import io.opentelemetry.api.incubator.logs.ExtendedLogger; import io.opentelemetry.api.logs.LogRecordBuilder; import io.opentelemetry.api.logs.Logger; import io.opentelemetry.api.logs.LoggerProvider; @@ -13,9 +12,21 @@ import io.opentelemetry.sdk.logs.internal.LoggerConfig; /** SDK implementation of {@link Logger}. */ -final class SdkLogger implements ExtendedLogger { +class SdkLogger implements Logger { private static final Logger NOOP_LOGGER = LoggerProvider.noop().get("noop"); + private static final boolean INCUBATOR_AVAILABLE; + + static { + boolean incubatorAvailable = false; + try { + Class.forName("io.opentelemetry.api.incubator.logs.ExtendedDefaultLoggerProvider"); + incubatorAvailable = true; + } catch (ClassNotFoundException e) { + // Not available + } + INCUBATOR_AVAILABLE = incubatorAvailable; + } private final LoggerSharedState loggerSharedState; private final InstrumentationScopeInfo instrumentationScopeInfo; @@ -30,10 +41,22 @@ final class SdkLogger implements ExtendedLogger { this.loggerEnabled = loggerConfig.isEnabled(); } + static SdkLogger create( + LoggerSharedState sharedState, + InstrumentationScopeInfo instrumentationScopeInfo, + LoggerConfig loggerConfig) { + return INCUBATOR_AVAILABLE + ? IncubatingUtil.createExtendedLogger(sharedState, instrumentationScopeInfo, loggerConfig) + : new SdkLogger(sharedState, instrumentationScopeInfo, loggerConfig); + } + @Override public LogRecordBuilder logRecordBuilder() { if (loggerEnabled) { - return new SdkLogRecordBuilder(loggerSharedState, instrumentationScopeInfo); + return INCUBATOR_AVAILABLE + ? IncubatingUtil.createExtendedLogRecordBuilder( + loggerSharedState, instrumentationScopeInfo) + : new SdkLogRecordBuilder(loggerSharedState, instrumentationScopeInfo); } return NOOP_LOGGER.logRecordBuilder(); } @@ -42,9 +65,4 @@ public LogRecordBuilder logRecordBuilder() { InstrumentationScopeInfo getInstrumentationScopeInfo() { return instrumentationScopeInfo; } - - @Override - public boolean isEnabled() { - return loggerEnabled; - } } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java index 2d7b87e6b47..ea68a6c2a5c 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java @@ -60,7 +60,7 @@ public static SdkLoggerProviderBuilder builder() { this.loggerComponentRegistry = new ComponentRegistry<>( instrumentationScopeInfo -> - new SdkLogger( + SdkLogger.create( sharedState, instrumentationScopeInfo, getLoggerConfig(instrumentationScopeInfo))); diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/LoggerConfigTest.java b/sdk/logs/src/testIncubating/java/io/opentelemetry/sdk/logs/LoggerConfigTest.java similarity index 100% rename from sdk/logs/src/test/java/io/opentelemetry/sdk/logs/LoggerConfigTest.java rename to sdk/logs/src/testIncubating/java/io/opentelemetry/sdk/logs/LoggerConfigTest.java diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilderTest.java b/sdk/logs/src/testIncubating/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilderTest.java similarity index 100% rename from sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilderTest.java rename to sdk/logs/src/testIncubating/java/io/opentelemetry/sdk/logs/internal/SdkEventBuilderTest.java diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventLoggerProviderTest.java b/sdk/logs/src/testIncubating/java/io/opentelemetry/sdk/logs/internal/SdkEventLoggerProviderTest.java similarity index 100% rename from sdk/logs/src/test/java/io/opentelemetry/sdk/logs/internal/SdkEventLoggerProviderTest.java rename to sdk/logs/src/testIncubating/java/io/opentelemetry/sdk/logs/internal/SdkEventLoggerProviderTest.java diff --git a/sdk/metrics/build.gradle.kts b/sdk/metrics/build.gradle.kts index 0fffd03457e..a0b667943c8 100644 --- a/sdk/metrics/build.gradle.kts +++ b/sdk/metrics/build.gradle.kts @@ -15,7 +15,7 @@ otelJava.moduleName.set("io.opentelemetry.sdk.metrics") dependencies { api(project(":api:all")) api(project(":sdk:common")) - implementation(project(":api:incubator")) + compileOnly(project(":api:incubator")) compileOnly("org.codehaus.mojo:animal-sniffer-annotations") @@ -37,6 +37,13 @@ dependencyCheck { testing { suites { + register("testIncubating") { + dependencies { + implementation(project(":sdk:testing")) + implementation(project(":api:incubator")) + implementation("com.google.guava:guava") + } + } register("debugEnabledTest") { targets { all { diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleCounter.java new file mode 100644 index 00000000000..050429f8f52 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleCounter.java @@ -0,0 +1,51 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleCounter; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleCounterBuilder; +import io.opentelemetry.sdk.metrics.internal.descriptor.Advice; +import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; +import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; +import java.util.List; + +final class ExtendedSdkDoubleCounter extends SdkDoubleCounter implements ExtendedDoubleCounter { + + private ExtendedSdkDoubleCounter( + InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { + super(descriptor, sdkMeter, storage); + } + + @Override + public boolean isEnabled() { + return sdkMeter.isMeterEnabled() && storage.isEnabled(); + } + + static final class ExtendedSdkDoubleCounterBuilder extends SdkDoubleCounterBuilder + implements ExtendedDoubleCounterBuilder { + + ExtendedSdkDoubleCounterBuilder( + SdkMeter sdkMeter, + String name, + String description, + String unit, + Advice.AdviceBuilder adviceBuilder) { + super(sdkMeter, name, description, unit, adviceBuilder); + } + + @Override + public ExtendedSdkDoubleCounter build() { + return builder.buildSynchronousInstrument(ExtendedSdkDoubleCounter::new); + } + + @Override + public ExtendedDoubleCounterBuilder setAttributesAdvice(List> attributes) { + builder.setAdviceAttributes(attributes); + return this; + } + } +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleGauge.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleGauge.java new file mode 100644 index 00000000000..def79d8bb65 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleGauge.java @@ -0,0 +1,50 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleGauge; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleGaugeBuilder; +import io.opentelemetry.api.incubator.metrics.ExtendedLongGaugeBuilder; +import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; +import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; +import java.util.List; + +final class ExtendedSdkDoubleGauge extends SdkDoubleGauge implements ExtendedDoubleGauge { + + private ExtendedSdkDoubleGauge( + InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { + super(descriptor, sdkMeter, storage); + } + + @Override + public boolean isEnabled() { + return sdkMeter.isMeterEnabled() && storage.isEnabled(); + } + + static final class ExtendedSdkDoubleGaugeBuilder extends SdkDoubleGaugeBuilder + implements ExtendedDoubleGaugeBuilder { + ExtendedSdkDoubleGaugeBuilder(SdkMeter sdkMeter, String name) { + super(sdkMeter, name); + } + + @Override + public ExtendedSdkDoubleGauge build() { + return builder.buildSynchronousInstrument(ExtendedSdkDoubleGauge::new); + } + + @Override + public ExtendedDoubleGaugeBuilder setAttributesAdvice(List> attributes) { + builder.setAdviceAttributes(attributes); + return this; + } + + @Override + public ExtendedLongGaugeBuilder ofLongs() { + return builder.swapBuilder(ExtendedSdkLongGauge.ExtendedSdkLongGaugeBuilder::new); + } + } +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleHistogram.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleHistogram.java new file mode 100644 index 00000000000..76afb84214f --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleHistogram.java @@ -0,0 +1,52 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleHistogram; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleHistogramBuilder; +import io.opentelemetry.api.incubator.metrics.ExtendedLongHistogramBuilder; +import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; +import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; +import java.util.List; + +final class ExtendedSdkDoubleHistogram extends SdkDoubleHistogram + implements ExtendedDoubleHistogram { + + ExtendedSdkDoubleHistogram( + InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { + super(descriptor, sdkMeter, storage); + } + + @Override + public boolean isEnabled() { + return sdkMeter.isMeterEnabled() && storage.isEnabled(); + } + + static final class ExtendedSdkDoubleHistogramBuilder extends SdkDoubleHistogramBuilder + implements ExtendedDoubleHistogramBuilder { + + ExtendedSdkDoubleHistogramBuilder(SdkMeter sdkMeter, String name) { + super(sdkMeter, name); + } + + @Override + public ExtendedSdkDoubleHistogram build() { + return builder.buildSynchronousInstrument(ExtendedSdkDoubleHistogram::new); + } + + @Override + public ExtendedLongHistogramBuilder ofLongs() { + return builder.swapBuilder(ExtendedSdkLongHistogram.ExtendedSdkLongHistogramBuilder::new); + } + + @Override + public ExtendedDoubleHistogramBuilder setAttributesAdvice(List> attributes) { + builder.setAdviceAttributes(attributes); + return this; + } + } +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleUpDownCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleUpDownCounter.java new file mode 100644 index 00000000000..3e7ae4bdb11 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkDoubleUpDownCounter.java @@ -0,0 +1,53 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleUpDownCounter; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleUpDownCounterBuilder; +import io.opentelemetry.sdk.metrics.internal.descriptor.Advice; +import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; +import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; +import java.util.List; + +final class ExtendedSdkDoubleUpDownCounter extends SdkDoubleUpDownCounter + implements ExtendedDoubleUpDownCounter { + + private ExtendedSdkDoubleUpDownCounter( + InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { + super(descriptor, sdkMeter, storage); + } + + @Override + public boolean isEnabled() { + return sdkMeter.isMeterEnabled() && storage.isEnabled(); + } + + static final class ExtendedSdkDoubleUpDownCounterBuilder extends SdkDoubleUpDownCounterBuilder + implements ExtendedDoubleUpDownCounterBuilder { + + ExtendedSdkDoubleUpDownCounterBuilder( + SdkMeter sdkMeter, + String name, + String description, + String unit, + Advice.AdviceBuilder adviceBuilder) { + super(sdkMeter, name, description, unit, adviceBuilder); + } + + @Override + public ExtendedDoubleUpDownCounter build() { + return builder.buildSynchronousInstrument(ExtendedSdkDoubleUpDownCounter::new); + } + + @Override + public ExtendedDoubleUpDownCounterBuilder setAttributesAdvice( + List> attributes) { + builder.setAdviceAttributes(attributes); + return this; + } + } +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongCounter.java new file mode 100644 index 00000000000..f87e3407184 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongCounter.java @@ -0,0 +1,51 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleCounterBuilder; +import io.opentelemetry.api.incubator.metrics.ExtendedLongCounter; +import io.opentelemetry.api.incubator.metrics.ExtendedLongCounterBuilder; +import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; +import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; +import java.util.List; + +final class ExtendedSdkLongCounter extends SdkLongCounter implements ExtendedLongCounter { + + private ExtendedSdkLongCounter( + InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { + super(descriptor, sdkMeter, storage); + } + + @Override + public boolean isEnabled() { + return sdkMeter.isMeterEnabled() && storage.isEnabled(); + } + + static final class ExtendedSdkLongCounterBuilder extends SdkLongCounterBuilder + implements ExtendedLongCounterBuilder { + + ExtendedSdkLongCounterBuilder(SdkMeter sdkMeter, String name) { + super(sdkMeter, name); + } + + @Override + public ExtendedSdkLongCounter build() { + return builder.buildSynchronousInstrument(ExtendedSdkLongCounter::new); + } + + @Override + public ExtendedDoubleCounterBuilder ofDoubles() { + return builder.swapBuilder(ExtendedSdkDoubleCounter.ExtendedSdkDoubleCounterBuilder::new); + } + + @Override + public ExtendedLongCounterBuilder setAttributesAdvice(List> attributes) { + builder.setAdviceAttributes(attributes); + return this; + } + } +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongGauge.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongGauge.java new file mode 100644 index 00000000000..94845f4bef5 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongGauge.java @@ -0,0 +1,51 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.incubator.metrics.ExtendedLongGauge; +import io.opentelemetry.api.incubator.metrics.ExtendedLongGaugeBuilder; +import io.opentelemetry.sdk.metrics.internal.descriptor.Advice; +import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; +import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; +import java.util.List; + +final class ExtendedSdkLongGauge extends SdkLongGauge implements ExtendedLongGauge { + + private ExtendedSdkLongGauge( + InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { + super(descriptor, sdkMeter, storage); + } + + @Override + public boolean isEnabled() { + return sdkMeter.isMeterEnabled() && storage.isEnabled(); + } + + static final class ExtendedSdkLongGaugeBuilder extends SdkLongGaugeBuilder + implements ExtendedLongGaugeBuilder { + + ExtendedSdkLongGaugeBuilder( + SdkMeter sdkMeter, + String name, + String description, + String unit, + Advice.AdviceBuilder adviceBuilder) { + super(sdkMeter, name, description, unit, adviceBuilder); + } + + @Override + public ExtendedSdkLongGauge build() { + return builder.buildSynchronousInstrument(ExtendedSdkLongGauge::new); + } + + @Override + public ExtendedLongGaugeBuilder setAttributesAdvice(List> attributes) { + builder.setAdviceAttributes(attributes); + return this; + } + } +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongHistogram.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongHistogram.java new file mode 100644 index 00000000000..e10851efd54 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongHistogram.java @@ -0,0 +1,51 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.incubator.metrics.ExtendedLongHistogram; +import io.opentelemetry.api.incubator.metrics.ExtendedLongHistogramBuilder; +import io.opentelemetry.sdk.metrics.internal.descriptor.Advice; +import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; +import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; +import java.util.List; + +final class ExtendedSdkLongHistogram extends SdkLongHistogram implements ExtendedLongHistogram { + + private ExtendedSdkLongHistogram( + InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { + super(descriptor, sdkMeter, storage); + } + + @Override + public boolean isEnabled() { + return sdkMeter.isMeterEnabled() && storage.isEnabled(); + } + + static final class ExtendedSdkLongHistogramBuilder extends SdkLongHistogramBuilder + implements ExtendedLongHistogramBuilder { + + ExtendedSdkLongHistogramBuilder( + SdkMeter sdkMeter, + String name, + String description, + String unit, + Advice.AdviceBuilder adviceBuilder) { + super(sdkMeter, name, description, unit, adviceBuilder); + } + + @Override + public ExtendedSdkLongHistogram build() { + return builder.buildSynchronousInstrument(ExtendedSdkLongHistogram::new); + } + + @Override + public ExtendedLongHistogramBuilder setAttributesAdvice(List> attributes) { + builder.setAdviceAttributes(attributes); + return this; + } + } +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongUpDownCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongUpDownCounter.java new file mode 100644 index 00000000000..53be08fed63 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ExtendedSdkLongUpDownCounter.java @@ -0,0 +1,53 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleUpDownCounterBuilder; +import io.opentelemetry.api.incubator.metrics.ExtendedLongUpDownCounter; +import io.opentelemetry.api.incubator.metrics.ExtendedLongUpDownCounterBuilder; +import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; +import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; +import java.util.List; + +final class ExtendedSdkLongUpDownCounter extends SdkLongUpDownCounter + implements ExtendedLongUpDownCounter { + + private ExtendedSdkLongUpDownCounter( + InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { + super(descriptor, sdkMeter, storage); + } + + @Override + public boolean isEnabled() { + return sdkMeter.isMeterEnabled() && storage.isEnabled(); + } + + static final class ExtendedSdkLongUpDownCounterBuilder extends SdkLongUpDownCounterBuilder + implements ExtendedLongUpDownCounterBuilder { + + ExtendedSdkLongUpDownCounterBuilder(SdkMeter sdkMeter, String name) { + super(sdkMeter, name); + } + + @Override + public ExtendedLongUpDownCounter build() { + return builder.buildSynchronousInstrument(ExtendedSdkLongUpDownCounter::new); + } + + @Override + public ExtendedDoubleUpDownCounterBuilder ofDoubles() { + return builder.swapBuilder( + ExtendedSdkDoubleUpDownCounter.ExtendedSdkDoubleUpDownCounterBuilder::new); + } + + @Override + public ExtendedLongUpDownCounterBuilder setAttributesAdvice(List> attributes) { + builder.setAdviceAttributes(attributes); + return this; + } + } +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/IncubatingUtil.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/IncubatingUtil.java new file mode 100644 index 00000000000..03a88bb9382 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/IncubatingUtil.java @@ -0,0 +1,39 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics; + +import io.opentelemetry.api.metrics.DoubleGaugeBuilder; +import io.opentelemetry.api.metrics.DoubleHistogramBuilder; +import io.opentelemetry.api.metrics.LongCounterBuilder; +import io.opentelemetry.api.metrics.LongUpDownCounterBuilder; + +/** + * Utilities for interacting with {@code io.opentelemetry:opentelemetry-api-incubator}, which is not + * guaranteed to be present on the classpath. For all methods, callers MUST first separately + * reflectively confirm that the incubator is available on the classpath. + */ +final class IncubatingUtil { + + private IncubatingUtil() {} + + static LongCounterBuilder createExtendedLongCounterBuilder(SdkMeter sdkMeter, String name) { + return new ExtendedSdkLongCounter.ExtendedSdkLongCounterBuilder(sdkMeter, name); + } + + static LongUpDownCounterBuilder createExtendedLongUpDownCounterBuilder( + SdkMeter sdkMeter, String name) { + return new ExtendedSdkLongUpDownCounter.ExtendedSdkLongUpDownCounterBuilder(sdkMeter, name); + } + + static DoubleHistogramBuilder createExtendedDoubleHistogramBuilder( + SdkMeter sdkMeter, String name) { + return new ExtendedSdkDoubleHistogram.ExtendedSdkDoubleHistogramBuilder(sdkMeter, name); + } + + static DoubleGaugeBuilder createExtendedDoubleGaugeBuilder(SdkMeter sdkMeter, String name) { + return new ExtendedSdkDoubleGauge.ExtendedSdkDoubleGaugeBuilder(sdkMeter, name); + } +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java index de645016076..7fd6e435556 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleCounter.java @@ -5,10 +5,8 @@ package io.opentelemetry.sdk.metrics; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.metrics.ExtendedDoubleCounter; -import io.opentelemetry.api.incubator.metrics.ExtendedDoubleCounterBuilder; +import io.opentelemetry.api.metrics.DoubleCounter; import io.opentelemetry.api.metrics.DoubleCounterBuilder; import io.opentelemetry.api.metrics.ObservableDoubleCounter; import io.opentelemetry.api.metrics.ObservableDoubleMeasurement; @@ -17,19 +15,18 @@ import io.opentelemetry.sdk.metrics.internal.descriptor.Advice; import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; -import java.util.List; import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; -final class SdkDoubleCounter extends AbstractInstrument implements ExtendedDoubleCounter { +class SdkDoubleCounter extends AbstractInstrument implements DoubleCounter { private static final Logger logger = Logger.getLogger(SdkDoubleCounter.class.getName()); private final ThrottlingLogger throttlingLogger = new ThrottlingLogger(logger); - private final SdkMeter sdkMeter; - private final WriteableMetricStorage storage; + final SdkMeter sdkMeter; + final WriteableMetricStorage storage; - private SdkDoubleCounter( + SdkDoubleCounter( InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { super(descriptor); this.sdkMeter = sdkMeter; @@ -59,14 +56,9 @@ public void add(double increment) { add(increment, Attributes.empty()); } - @Override - public boolean isEnabled() { - return sdkMeter.isMeterEnabled() && storage.isEnabled(); - } + static class SdkDoubleCounterBuilder implements DoubleCounterBuilder { - static final class SdkDoubleCounterBuilder implements ExtendedDoubleCounterBuilder { - - private final InstrumentBuilder builder; + final InstrumentBuilder builder; SdkDoubleCounterBuilder( SdkMeter sdkMeter, @@ -109,12 +101,6 @@ public ObservableDoubleMeasurement buildObserver() { return builder.buildObservableMeasurement(InstrumentType.OBSERVABLE_COUNTER); } - @Override - public ExtendedDoubleCounterBuilder setAttributesAdvice(List> attributes) { - builder.setAdviceAttributes(attributes); - return this; - } - @Override public String toString() { return builder.toStringHelper(getClass().getSimpleName()); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java index 03b3f43838d..97076603bb5 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleGauge.java @@ -5,10 +5,8 @@ package io.opentelemetry.sdk.metrics; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.metrics.ExtendedDoubleGauge; -import io.opentelemetry.api.incubator.metrics.ExtendedDoubleGaugeBuilder; +import io.opentelemetry.api.metrics.DoubleGauge; import io.opentelemetry.api.metrics.DoubleGaugeBuilder; import io.opentelemetry.api.metrics.LongGaugeBuilder; import io.opentelemetry.api.metrics.ObservableDoubleGauge; @@ -16,15 +14,14 @@ import io.opentelemetry.context.Context; import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; -import java.util.List; import java.util.function.Consumer; -final class SdkDoubleGauge extends AbstractInstrument implements ExtendedDoubleGauge { +class SdkDoubleGauge extends AbstractInstrument implements DoubleGauge { - private final SdkMeter sdkMeter; - private final WriteableMetricStorage storage; + final SdkMeter sdkMeter; + final WriteableMetricStorage storage; - private SdkDoubleGauge( + SdkDoubleGauge( InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { super(descriptor); this.sdkMeter = sdkMeter; @@ -46,16 +43,10 @@ public void set(double increment) { set(increment, Attributes.empty()); } - @Override - public boolean isEnabled() { - return sdkMeter.isMeterEnabled() && storage.isEnabled(); - } - - static final class SdkDoubleGaugeBuilder implements ExtendedDoubleGaugeBuilder { - private final InstrumentBuilder builder; + static class SdkDoubleGaugeBuilder implements DoubleGaugeBuilder { + final InstrumentBuilder builder; SdkDoubleGaugeBuilder(SdkMeter sdkMeter, String name) { - builder = new InstrumentBuilder(name, InstrumentType.GAUGE, InstrumentValueType.DOUBLE, sdkMeter); } @@ -77,12 +68,6 @@ public SdkDoubleGauge build() { return builder.buildSynchronousInstrument(SdkDoubleGauge::new); } - @Override - public ExtendedDoubleGaugeBuilder setAttributesAdvice(List> attributes) { - builder.setAdviceAttributes(attributes); - return this; - } - @Override public LongGaugeBuilder ofLongs() { return builder.swapBuilder(SdkLongGauge.SdkLongGaugeBuilder::new); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java index d155a7d7975..de4473ace2e 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleHistogram.java @@ -5,10 +5,8 @@ package io.opentelemetry.sdk.metrics; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.metrics.ExtendedDoubleHistogram; -import io.opentelemetry.api.incubator.metrics.ExtendedDoubleHistogramBuilder; +import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.DoubleHistogramBuilder; import io.opentelemetry.api.metrics.LongHistogramBuilder; import io.opentelemetry.context.Context; @@ -21,14 +19,14 @@ import java.util.logging.Level; import java.util.logging.Logger; -final class SdkDoubleHistogram extends AbstractInstrument implements ExtendedDoubleHistogram { +class SdkDoubleHistogram extends AbstractInstrument implements DoubleHistogram { private static final Logger logger = Logger.getLogger(SdkDoubleHistogram.class.getName()); private final ThrottlingLogger throttlingLogger = new ThrottlingLogger(logger); - private final SdkMeter sdkMeter; - private final WriteableMetricStorage storage; + final SdkMeter sdkMeter; + final WriteableMetricStorage storage; - private SdkDoubleHistogram( + SdkDoubleHistogram( InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { super(descriptor); this.sdkMeter = sdkMeter; @@ -58,14 +56,9 @@ public void record(double value) { record(value, Attributes.empty()); } - @Override - public boolean isEnabled() { - return sdkMeter.isMeterEnabled() && storage.isEnabled(); - } + static class SdkDoubleHistogramBuilder implements DoubleHistogramBuilder { - static final class SdkDoubleHistogramBuilder implements ExtendedDoubleHistogramBuilder { - - private final InstrumentBuilder builder; + final InstrumentBuilder builder; SdkDoubleHistogramBuilder(SdkMeter sdkMeter, String name) { builder = @@ -108,12 +101,6 @@ public DoubleHistogramBuilder setExplicitBucketBoundariesAdvice(List buc return this; } - @Override - public ExtendedDoubleHistogramBuilder setAttributesAdvice(List> attributes) { - builder.setAdviceAttributes(attributes); - return this; - } - @Override public String toString() { return builder.toStringHelper(getClass().getSimpleName()); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java index fe21e295c98..4231f58fdc0 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkDoubleUpDownCounter.java @@ -5,10 +5,7 @@ package io.opentelemetry.sdk.metrics; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.metrics.ExtendedDoubleUpDownCounter; -import io.opentelemetry.api.incubator.metrics.ExtendedDoubleUpDownCounterBuilder; import io.opentelemetry.api.metrics.DoubleUpDownCounter; import io.opentelemetry.api.metrics.DoubleUpDownCounterBuilder; import io.opentelemetry.api.metrics.ObservableDoubleMeasurement; @@ -17,16 +14,14 @@ import io.opentelemetry.sdk.metrics.internal.descriptor.Advice; import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; -import java.util.List; import java.util.function.Consumer; -final class SdkDoubleUpDownCounter extends AbstractInstrument - implements ExtendedDoubleUpDownCounter { +class SdkDoubleUpDownCounter extends AbstractInstrument implements DoubleUpDownCounter { - private final SdkMeter sdkMeter; - private final WriteableMetricStorage storage; + final SdkMeter sdkMeter; + final WriteableMetricStorage storage; - private SdkDoubleUpDownCounter( + SdkDoubleUpDownCounter( InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { super(descriptor); this.sdkMeter = sdkMeter; @@ -48,14 +43,9 @@ public void add(double increment) { add(increment, Attributes.empty()); } - @Override - public boolean isEnabled() { - return sdkMeter.isMeterEnabled() && storage.isEnabled(); - } + static class SdkDoubleUpDownCounterBuilder implements DoubleUpDownCounterBuilder { - static final class SdkDoubleUpDownCounterBuilder implements ExtendedDoubleUpDownCounterBuilder { - - private final InstrumentBuilder builder; + final InstrumentBuilder builder; SdkDoubleUpDownCounterBuilder( SdkMeter sdkMeter, @@ -100,13 +90,6 @@ public ObservableDoubleMeasurement buildObserver() { return builder.buildObservableMeasurement(InstrumentType.OBSERVABLE_UP_DOWN_COUNTER); } - @Override - public ExtendedDoubleUpDownCounterBuilder setAttributesAdvice( - List> attributes) { - builder.setAdviceAttributes(attributes); - return this; - } - @Override public String toString() { return builder.toStringHelper(getClass().getSimpleName()); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java index df2f9b4e660..0de901060f5 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongCounter.java @@ -5,11 +5,9 @@ package io.opentelemetry.sdk.metrics; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.metrics.ExtendedLongCounter; -import io.opentelemetry.api.incubator.metrics.ExtendedLongCounterBuilder; import io.opentelemetry.api.metrics.DoubleCounterBuilder; +import io.opentelemetry.api.metrics.LongCounter; import io.opentelemetry.api.metrics.LongCounterBuilder; import io.opentelemetry.api.metrics.ObservableLongCounter; import io.opentelemetry.api.metrics.ObservableLongMeasurement; @@ -17,20 +15,19 @@ import io.opentelemetry.sdk.internal.ThrottlingLogger; import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; -import java.util.List; import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; -final class SdkLongCounter extends AbstractInstrument implements ExtendedLongCounter { +class SdkLongCounter extends AbstractInstrument implements LongCounter { private static final Logger logger = Logger.getLogger(SdkLongCounter.class.getName()); private final ThrottlingLogger throttlingLogger = new ThrottlingLogger(logger); - private final SdkMeter sdkMeter; - private final WriteableMetricStorage storage; + final SdkMeter sdkMeter; + final WriteableMetricStorage storage; - private SdkLongCounter( + SdkLongCounter( InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { super(descriptor); this.sdkMeter = sdkMeter; @@ -60,14 +57,9 @@ public void add(long increment) { add(increment, Attributes.empty()); } - @Override - public boolean isEnabled() { - return sdkMeter.isMeterEnabled() && storage.isEnabled(); - } + static class SdkLongCounterBuilder implements LongCounterBuilder { - static final class SdkLongCounterBuilder implements ExtendedLongCounterBuilder { - - private final InstrumentBuilder builder; + final InstrumentBuilder builder; SdkLongCounterBuilder(SdkMeter sdkMeter, String name) { this.builder = @@ -106,12 +98,6 @@ public ObservableLongMeasurement buildObserver() { return builder.buildObservableMeasurement(InstrumentType.OBSERVABLE_COUNTER); } - @Override - public ExtendedLongCounterBuilder setAttributesAdvice(List> attributes) { - builder.setAdviceAttributes(attributes); - return this; - } - @Override public String toString() { return builder.toStringHelper(getClass().getSimpleName()); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java index 499c4a4443a..5c6aafbb9ef 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongGauge.java @@ -5,10 +5,8 @@ package io.opentelemetry.sdk.metrics; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.metrics.ExtendedLongGauge; -import io.opentelemetry.api.incubator.metrics.ExtendedLongGaugeBuilder; +import io.opentelemetry.api.metrics.LongGauge; import io.opentelemetry.api.metrics.LongGaugeBuilder; import io.opentelemetry.api.metrics.ObservableLongGauge; import io.opentelemetry.api.metrics.ObservableLongMeasurement; @@ -16,16 +14,14 @@ import io.opentelemetry.sdk.metrics.internal.descriptor.Advice; import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; -import java.util.List; import java.util.function.Consumer; -final class SdkLongGauge extends AbstractInstrument implements ExtendedLongGauge { +class SdkLongGauge extends AbstractInstrument implements LongGauge { - private final SdkMeter sdkMeter; - private final WriteableMetricStorage storage; + final SdkMeter sdkMeter; + final WriteableMetricStorage storage; - private SdkLongGauge( - InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { + SdkLongGauge(InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { super(descriptor); this.sdkMeter = sdkMeter; this.storage = storage; @@ -46,14 +42,9 @@ public void set(long increment) { set(increment, Attributes.empty()); } - @Override - public boolean isEnabled() { - return sdkMeter.isMeterEnabled() && storage.isEnabled(); - } + static class SdkLongGaugeBuilder implements LongGaugeBuilder { - static final class SdkLongGaugeBuilder implements ExtendedLongGaugeBuilder { - - private final InstrumentBuilder builder; + final InstrumentBuilder builder; SdkLongGaugeBuilder( SdkMeter sdkMeter, @@ -61,7 +52,6 @@ static final class SdkLongGaugeBuilder implements ExtendedLongGaugeBuilder { String description, String unit, Advice.AdviceBuilder adviceBuilder) { - builder = new InstrumentBuilder(name, InstrumentType.GAUGE, InstrumentValueType.LONG, sdkMeter) .setDescription(description) @@ -86,12 +76,6 @@ public SdkLongGauge build() { return builder.buildSynchronousInstrument(SdkLongGauge::new); } - @Override - public ExtendedLongGaugeBuilder setAttributesAdvice(List> attributes) { - builder.setAdviceAttributes(attributes); - return this; - } - @Override public ObservableLongGauge buildWithCallback(Consumer callback) { return builder.buildLongAsynchronousInstrument(InstrumentType.OBSERVABLE_GAUGE, callback); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java index 5e96bfb2e61..b777ad34e59 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongHistogram.java @@ -5,10 +5,8 @@ package io.opentelemetry.sdk.metrics; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.metrics.ExtendedLongHistogram; -import io.opentelemetry.api.incubator.metrics.ExtendedLongHistogramBuilder; +import io.opentelemetry.api.metrics.LongHistogram; import io.opentelemetry.api.metrics.LongHistogramBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.sdk.internal.ThrottlingLogger; @@ -22,14 +20,14 @@ import java.util.logging.Logger; import java.util.stream.Collectors; -final class SdkLongHistogram extends AbstractInstrument implements ExtendedLongHistogram { +class SdkLongHistogram extends AbstractInstrument implements LongHistogram { private static final Logger logger = Logger.getLogger(SdkLongHistogram.class.getName()); private final ThrottlingLogger throttlingLogger = new ThrottlingLogger(logger); - private final SdkMeter sdkMeter; - private final WriteableMetricStorage storage; + final SdkMeter sdkMeter; + final WriteableMetricStorage storage; - private SdkLongHistogram( + SdkLongHistogram( InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { super(descriptor); this.sdkMeter = sdkMeter; @@ -59,14 +57,9 @@ public void record(long value) { record(value, Attributes.empty()); } - @Override - public boolean isEnabled() { - return sdkMeter.isMeterEnabled() && storage.isEnabled(); - } + static class SdkLongHistogramBuilder implements LongHistogramBuilder { - static final class SdkLongHistogramBuilder implements ExtendedLongHistogramBuilder { - - private final InstrumentBuilder builder; + final InstrumentBuilder builder; SdkLongHistogramBuilder( SdkMeter sdkMeter, @@ -113,12 +106,6 @@ public LongHistogramBuilder setExplicitBucketBoundariesAdvice(List bucketB return this; } - @Override - public ExtendedLongHistogramBuilder setAttributesAdvice(List> attributes) { - builder.setAdviceAttributes(attributes); - return this; - } - @Override public String toString() { return builder.toStringHelper(getClass().getSimpleName()); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java index daf1e2f97a8..dece771f4b6 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkLongUpDownCounter.java @@ -5,10 +5,7 @@ package io.opentelemetry.sdk.metrics; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.metrics.ExtendedLongUpDownCounter; -import io.opentelemetry.api.incubator.metrics.ExtendedLongUpDownCounterBuilder; import io.opentelemetry.api.metrics.DoubleUpDownCounterBuilder; import io.opentelemetry.api.metrics.LongUpDownCounter; import io.opentelemetry.api.metrics.LongUpDownCounterBuilder; @@ -17,15 +14,14 @@ import io.opentelemetry.context.Context; import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage; -import java.util.List; import java.util.function.Consumer; -final class SdkLongUpDownCounter extends AbstractInstrument implements ExtendedLongUpDownCounter { +class SdkLongUpDownCounter extends AbstractInstrument implements LongUpDownCounter { - private final SdkMeter sdkMeter; - private final WriteableMetricStorage storage; + final SdkMeter sdkMeter; + final WriteableMetricStorage storage; - private SdkLongUpDownCounter( + SdkLongUpDownCounter( InstrumentDescriptor descriptor, SdkMeter sdkMeter, WriteableMetricStorage storage) { super(descriptor); this.sdkMeter = sdkMeter; @@ -47,14 +43,9 @@ public void add(long increment) { add(increment, Attributes.empty()); } - @Override - public boolean isEnabled() { - return sdkMeter.isMeterEnabled() && storage.isEnabled(); - } + static class SdkLongUpDownCounterBuilder implements LongUpDownCounterBuilder { - static final class SdkLongUpDownCounterBuilder implements ExtendedLongUpDownCounterBuilder { - - private final InstrumentBuilder builder; + final InstrumentBuilder builder; SdkLongUpDownCounterBuilder(SdkMeter sdkMeter, String name) { this.builder = @@ -96,12 +87,6 @@ public ObservableLongMeasurement buildObserver() { return builder.buildObservableMeasurement(InstrumentType.OBSERVABLE_UP_DOWN_COUNTER); } - @Override - public ExtendedLongUpDownCounterBuilder setAttributesAdvice(List> attributes) { - builder.setAdviceAttributes(attributes); - return this; - } - @Override public String toString() { return builder.toStringHelper(getClass().getSimpleName()); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeter.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeter.java index fe278cba4d6..c0f1476077a 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeter.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeter.java @@ -49,6 +49,18 @@ final class SdkMeter implements Meter { private static final Logger logger = Logger.getLogger(SdkMeter.class.getName()); + private static final boolean INCUBATOR_AVAILABLE; + + static { + boolean incubatorAvailable = false; + try { + Class.forName("io.opentelemetry.api.incubator.metrics.ExtendedDefaultMeterProvider"); + incubatorAvailable = true; + } catch (ClassNotFoundException e) { + // Not available + } + INCUBATOR_AVAILABLE = incubatorAvailable; + } /** * Instrument names MUST conform to the following syntax. @@ -145,30 +157,42 @@ void resetForTest() { @Override public LongCounterBuilder counterBuilder(String name) { - return checkValidInstrumentName(name) - ? new SdkLongCounter.SdkLongCounterBuilder(this, name) - : NOOP_METER.counterBuilder(NOOP_INSTRUMENT_NAME); + if (!checkValidInstrumentName(name)) { + return NOOP_METER.counterBuilder(NOOP_INSTRUMENT_NAME); + } + return INCUBATOR_AVAILABLE + ? IncubatingUtil.createExtendedLongCounterBuilder(this, name) + : new SdkLongCounter.SdkLongCounterBuilder(this, name); } @Override public LongUpDownCounterBuilder upDownCounterBuilder(String name) { - return checkValidInstrumentName(name) - ? new SdkLongUpDownCounter.SdkLongUpDownCounterBuilder(this, name) - : NOOP_METER.upDownCounterBuilder(NOOP_INSTRUMENT_NAME); + if (!checkValidInstrumentName(name)) { + return NOOP_METER.upDownCounterBuilder(NOOP_INSTRUMENT_NAME); + } + return INCUBATOR_AVAILABLE + ? IncubatingUtil.createExtendedLongUpDownCounterBuilder(this, name) + : new SdkLongUpDownCounter.SdkLongUpDownCounterBuilder(this, name); } @Override public DoubleHistogramBuilder histogramBuilder(String name) { - return checkValidInstrumentName(name) - ? new SdkDoubleHistogram.SdkDoubleHistogramBuilder(this, name) - : NOOP_METER.histogramBuilder(NOOP_INSTRUMENT_NAME); + if (!checkValidInstrumentName(name)) { + return NOOP_METER.histogramBuilder(NOOP_INSTRUMENT_NAME); + } + return INCUBATOR_AVAILABLE + ? IncubatingUtil.createExtendedDoubleHistogramBuilder(this, name) + : new SdkDoubleHistogram.SdkDoubleHistogramBuilder(this, name); } @Override public DoubleGaugeBuilder gaugeBuilder(String name) { - return checkValidInstrumentName(name) - ? new SdkDoubleGauge.SdkDoubleGaugeBuilder(this, name) - : NOOP_METER.gaugeBuilder(NOOP_INSTRUMENT_NAME); + if (!checkValidInstrumentName(name)) { + return NOOP_METER.gaugeBuilder(NOOP_INSTRUMENT_NAME); + } + return INCUBATOR_AVAILABLE + ? IncubatingUtil.createExtendedDoubleGaugeBuilder(this, name) + : new SdkDoubleGauge.SdkDoubleGaugeBuilder(this, name); } @Override diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/AttributesAdviceTest.java b/sdk/metrics/src/testIncubating/java/io/opentelemetry/sdk/metrics/AttributesAdviceTest.java similarity index 100% rename from sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/AttributesAdviceTest.java rename to sdk/metrics/src/testIncubating/java/io/opentelemetry/sdk/metrics/AttributesAdviceTest.java diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/MeterConfigTest.java b/sdk/metrics/src/testIncubating/java/io/opentelemetry/sdk/metrics/MeterConfigTest.java similarity index 100% rename from sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/MeterConfigTest.java rename to sdk/metrics/src/testIncubating/java/io/opentelemetry/sdk/metrics/MeterConfigTest.java diff --git a/sdk/trace/build.gradle.kts b/sdk/trace/build.gradle.kts index 2dc5c769508..35d30c8513b 100644 --- a/sdk/trace/build.gradle.kts +++ b/sdk/trace/build.gradle.kts @@ -22,8 +22,7 @@ dependencies { api(project(":api:all")) api(project(":sdk:common")) - implementation(project(":api:incubator")) - + compileOnly(project(":api:incubator")) compileOnly(project(":sdk:trace-shaded-deps")) annotationProcessor("com.google.auto.value:auto-value") @@ -65,6 +64,23 @@ dependencies { jmh("org.testcontainers:testcontainers") // testContainer for OTLP collector } +testing { + suites { + register("testIncubating") { + dependencies { + implementation(project(":sdk:testing")) + implementation(project(":api:incubator")) + } + } + } +} + +tasks { + check { + dependsOn(testing.suites) + } +} + tasks { withType().configureEach { // We catch NoClassDefFoundError to fallback to non-jctools queues. diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ExtendedSdkSpanBuilder.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ExtendedSdkSpanBuilder.java new file mode 100644 index 00000000000..b68030202ce --- /dev/null +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ExtendedSdkSpanBuilder.java @@ -0,0 +1,159 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.trace; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.incubator.propagation.ExtendedContextPropagators; +import io.opentelemetry.api.incubator.trace.ExtendedSpanBuilder; +import io.opentelemetry.api.incubator.trace.SpanCallable; +import io.opentelemetry.api.incubator.trace.SpanRunnable; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanContext; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.api.trace.StatusCode; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.Scope; +import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; + +/** {@link ExtendedSdkSpanBuilder} is SDK implementation of {@link ExtendedSpanBuilder}. */ +final class ExtendedSdkSpanBuilder extends SdkSpanBuilder implements ExtendedSpanBuilder { + + ExtendedSdkSpanBuilder( + String spanName, + InstrumentationScopeInfo instrumentationScopeInfo, + TracerSharedState tracerSharedState, + SpanLimits spanLimits) { + super(spanName, instrumentationScopeInfo, tracerSharedState, spanLimits); + } + + @Override + public ExtendedSpanBuilder setParent(Context context) { + super.setParent(context); + return this; + } + + @Override + public ExtendedSpanBuilder setNoParent() { + super.setNoParent(); + return this; + } + + @Override + public ExtendedSpanBuilder setSpanKind(SpanKind spanKind) { + super.setSpanKind(spanKind); + return this; + } + + @Override + public ExtendedSpanBuilder addLink(SpanContext spanContext) { + super.addLink(spanContext); + return this; + } + + @Override + public ExtendedSpanBuilder addLink(SpanContext spanContext, Attributes attributes) { + super.addLink(spanContext, attributes); + return this; + } + + @Override + public ExtendedSpanBuilder setAttribute(String key, String value) { + super.setAttribute(key, value); + return this; + } + + @Override + public ExtendedSpanBuilder setAttribute(String key, long value) { + super.setAttribute(key, value); + return this; + } + + @Override + public ExtendedSpanBuilder setAttribute(String key, double value) { + super.setAttribute(key, value); + return this; + } + + @Override + public ExtendedSpanBuilder setAttribute(String key, boolean value) { + super.setAttribute(key, value); + return this; + } + + @Override + public ExtendedSpanBuilder setAttribute(AttributeKey key, T value) { + super.setAttribute(key, value); + return this; + } + + @Override + public ExtendedSpanBuilder setStartTimestamp(long startTimestamp, TimeUnit unit) { + super.setStartTimestamp(startTimestamp, unit); + return this; + } + + @Override + public ExtendedSpanBuilder setParentFrom( + ContextPropagators propagators, Map carrier) { + super.setParent( + ExtendedContextPropagators.extractTextMapPropagationContext(carrier, propagators)); + return this; + } + + @Override + public T startAndCall(SpanCallable spanCallable) throws E { + return startAndCall(spanCallable, ExtendedSdkSpanBuilder::setSpanError); + } + + @Override + public T startAndCall( + SpanCallable spanCallable, BiConsumer handleException) throws E { + Span span = startSpan(); + + //noinspection unused + try (Scope unused = span.makeCurrent()) { + return spanCallable.callInSpan(); + } catch (Throwable e) { + handleException.accept(span, e); + throw e; + } finally { + span.end(); + } + } + + @Override + public void startAndRun(SpanRunnable runnable) throws E { + startAndRun(runnable, ExtendedSdkSpanBuilder::setSpanError); + } + + @SuppressWarnings("NullAway") + @Override + public void startAndRun( + SpanRunnable runnable, BiConsumer handleException) throws E { + startAndCall( + () -> { + runnable.runInSpan(); + return null; + }, + handleException); + } + + /** + * Marks a span as error. This is the default exception handler. + * + * @param span the span + * @param exception the exception that caused the error + */ + private static void setSpanError(Span span, Throwable exception) { + span.setStatus(StatusCode.ERROR); + span.recordException(exception); + } +} diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ExtendedSdkTracer.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ExtendedSdkTracer.java new file mode 100644 index 00000000000..7e339fd9a19 --- /dev/null +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ExtendedSdkTracer.java @@ -0,0 +1,30 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.trace; + +import io.opentelemetry.api.incubator.trace.ExtendedTracer; +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import io.opentelemetry.sdk.trace.internal.TracerConfig; + +/** {@link ExtendedSdkTracer} is SDK implementation of {@link ExtendedTracer}. */ +final class ExtendedSdkTracer extends SdkTracer implements ExtendedTracer { + // TODO: add dedicated API for updating scope config. + @SuppressWarnings("FieldCanBeFinal") // For now, allow updating reflectively. + private boolean tracerEnabled; + + ExtendedSdkTracer( + TracerSharedState sharedState, + InstrumentationScopeInfo instrumentationScopeInfo, + TracerConfig tracerConfig) { + super(sharedState, instrumentationScopeInfo, tracerConfig); + this.tracerEnabled = tracerConfig.isEnabled(); + } + + @Override + public boolean isEnabled() { + return tracerEnabled; + } +} diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/IncubatingUtil.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/IncubatingUtil.java new file mode 100644 index 00000000000..c7ab15e9c2e --- /dev/null +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/IncubatingUtil.java @@ -0,0 +1,35 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.trace; + +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import io.opentelemetry.sdk.trace.internal.TracerConfig; + +/** + * Utilities for interacting with {@code io.opentelemetry:opentelemetry-api-incubator}, which is not + * guaranteed to be present on the classpath. For all methods, callers MUST first separately + * reflectively confirm that the incubator is available on the classpath. + */ +final class IncubatingUtil { + + private IncubatingUtil() {} + + static SdkTracer createExtendedTracer( + TracerSharedState sharedState, + InstrumentationScopeInfo instrumentationScopeInfo, + TracerConfig tracerConfig) { + return new ExtendedSdkTracer(sharedState, instrumentationScopeInfo, tracerConfig); + } + + static SdkSpanBuilder createExtendedSpanBuilder( + String spanName, + InstrumentationScopeInfo instrumentationScopeInfo, + TracerSharedState tracerSharedState, + SpanLimits spanLimits) { + return new ExtendedSdkSpanBuilder( + spanName, instrumentationScopeInfo, tracerSharedState, spanLimits); + } +} diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpanBuilder.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpanBuilder.java index d637caa60da..b12107c7d43 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpanBuilder.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpanBuilder.java @@ -12,21 +12,14 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.propagation.ExtendedContextPropagators; -import io.opentelemetry.api.incubator.trace.ExtendedSpanBuilder; -import io.opentelemetry.api.incubator.trace.SpanCallable; -import io.opentelemetry.api.incubator.trace.SpanRunnable; import io.opentelemetry.api.internal.ImmutableSpanContext; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanBuilder; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.api.trace.TraceFlags; import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.context.Context; -import io.opentelemetry.context.Scope; -import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.internal.AttributeUtil; import io.opentelemetry.sdk.internal.AttributesMap; @@ -36,13 +29,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.concurrent.TimeUnit; -import java.util.function.BiConsumer; import javax.annotation.Nullable; /** {@link SdkSpanBuilder} is SDK implementation of {@link SpanBuilder}. */ -final class SdkSpanBuilder implements ExtendedSpanBuilder { +class SdkSpanBuilder implements SpanBuilder { private final String spanName; private final InstrumentationScopeInfo instrumentationScopeInfo; @@ -68,7 +59,7 @@ final class SdkSpanBuilder implements ExtendedSpanBuilder { } @Override - public ExtendedSpanBuilder setParent(Context context) { + public SpanBuilder setParent(Context context) { if (context == null) { return this; } @@ -77,13 +68,13 @@ public ExtendedSpanBuilder setParent(Context context) { } @Override - public ExtendedSpanBuilder setNoParent() { + public SpanBuilder setNoParent() { this.parent = Context.root(); return this; } @Override - public ExtendedSpanBuilder setSpanKind(SpanKind spanKind) { + public SpanBuilder setSpanKind(SpanKind spanKind) { if (spanKind == null) { return this; } @@ -92,7 +83,7 @@ public ExtendedSpanBuilder setSpanKind(SpanKind spanKind) { } @Override - public ExtendedSpanBuilder addLink(SpanContext spanContext) { + public SpanBuilder addLink(SpanContext spanContext) { if (spanContext == null || !spanContext.isValid()) { return this; } @@ -101,7 +92,7 @@ public ExtendedSpanBuilder addLink(SpanContext spanContext) { } @Override - public ExtendedSpanBuilder addLink(SpanContext spanContext, Attributes attributes) { + public SpanBuilder addLink(SpanContext spanContext, Attributes attributes) { if (spanContext == null || !spanContext.isValid()) { return this; } @@ -135,27 +126,27 @@ private void addLink(LinkData link) { } @Override - public ExtendedSpanBuilder setAttribute(String key, String value) { + public SpanBuilder setAttribute(String key, String value) { return setAttribute(stringKey(key), value); } @Override - public ExtendedSpanBuilder setAttribute(String key, long value) { + public SpanBuilder setAttribute(String key, long value) { return setAttribute(longKey(key), value); } @Override - public ExtendedSpanBuilder setAttribute(String key, double value) { + public SpanBuilder setAttribute(String key, double value) { return setAttribute(doubleKey(key), value); } @Override - public ExtendedSpanBuilder setAttribute(String key, boolean value) { + public SpanBuilder setAttribute(String key, boolean value) { return setAttribute(booleanKey(key), value); } @Override - public ExtendedSpanBuilder setAttribute(AttributeKey key, T value) { + public SpanBuilder setAttribute(AttributeKey key, T value) { if (key == null || key.getKey().isEmpty() || value == null) { return this; } @@ -164,7 +155,7 @@ public ExtendedSpanBuilder setAttribute(AttributeKey key, T value) { } @Override - public ExtendedSpanBuilder setStartTimestamp(long startTimestamp, TimeUnit unit) { + public SpanBuilder setStartTimestamp(long startTimestamp, TimeUnit unit) { if (startTimestamp < 0 || unit == null) { return this; } @@ -172,13 +163,6 @@ public ExtendedSpanBuilder setStartTimestamp(long startTimestamp, TimeUnit unit) return this; } - @Override - public ExtendedSpanBuilder setParentFrom( - ContextPropagators propagators, Map carrier) { - setParent(ExtendedContextPropagators.extractTextMapPropagationContext(carrier, propagators)); - return this; - } - @Override @SuppressWarnings({"unchecked", "rawtypes"}) public Span startSpan() { @@ -250,44 +234,6 @@ public Span startSpan() { startEpochNanos); } - @Override - public T startAndCall(SpanCallable spanCallable) throws E { - return startAndCall(spanCallable, SdkSpanBuilder::setSpanError); - } - - @Override - public T startAndCall( - SpanCallable spanCallable, BiConsumer handleException) throws E { - Span span = startSpan(); - - //noinspection unused - try (Scope unused = span.makeCurrent()) { - return spanCallable.callInSpan(); - } catch (Throwable e) { - handleException.accept(span, e); - throw e; - } finally { - span.end(); - } - } - - @Override - public void startAndRun(SpanRunnable runnable) throws E { - startAndRun(runnable, SdkSpanBuilder::setSpanError); - } - - @SuppressWarnings("NullAway") - @Override - public void startAndRun( - SpanRunnable runnable, BiConsumer handleException) throws E { - startAndCall( - () -> { - runnable.runInSpan(); - return null; - }, - handleException); - } - private AttributesMap attributes() { AttributesMap attributes = this.attributes; if (attributes == null) { @@ -309,15 +255,4 @@ static boolean isRecording(SamplingDecision decision) { static boolean isSampled(SamplingDecision decision) { return SamplingDecision.RECORD_AND_SAMPLE.equals(decision); } - - /** - * Marks a span as error. This is the default exception handler. - * - * @param span the span - * @param exception the exception that caused the error - */ - private static void setSpanError(Span span, Throwable exception) { - span.setStatus(StatusCode.ERROR); - span.recordException(exception); - } } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracer.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracer.java index 7b74c035e82..42210e56b28 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracer.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracer.java @@ -5,7 +5,6 @@ package io.opentelemetry.sdk.trace; -import io.opentelemetry.api.incubator.trace.ExtendedTracer; import io.opentelemetry.api.trace.SpanBuilder; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.api.trace.TracerProvider; @@ -13,9 +12,21 @@ import io.opentelemetry.sdk.trace.internal.TracerConfig; /** {@link SdkTracer} is SDK implementation of {@link Tracer}. */ -final class SdkTracer implements ExtendedTracer { +class SdkTracer implements Tracer { static final String FALLBACK_SPAN_NAME = ""; private static final Tracer NOOP_TRACER = TracerProvider.noop().get("noop"); + private static final boolean INCUBATOR_AVAILABLE; + + static { + boolean incubatorAvailable = false; + try { + Class.forName("io.opentelemetry.api.incubator.trace.ExtendedDefaultTracerProvider"); + incubatorAvailable = true; + } catch (ClassNotFoundException e) { + // Not available + } + INCUBATOR_AVAILABLE = incubatorAvailable; + } private final TracerSharedState sharedState; private final InstrumentationScopeInfo instrumentationScopeInfo; @@ -33,6 +44,15 @@ final class SdkTracer implements ExtendedTracer { this.tracerEnabled = tracerConfig.isEnabled(); } + static SdkTracer create( + TracerSharedState sharedState, + InstrumentationScopeInfo instrumentationScopeInfo, + TracerConfig tracerConfig) { + return INCUBATOR_AVAILABLE + ? IncubatingUtil.createExtendedTracer(sharedState, instrumentationScopeInfo, tracerConfig) + : new SdkTracer(sharedState, instrumentationScopeInfo, tracerConfig); + } + @Override public SpanBuilder spanBuilder(String spanName) { if (!tracerEnabled) { @@ -45,17 +65,15 @@ public SpanBuilder spanBuilder(String spanName) { Tracer tracer = TracerProvider.noop().get(instrumentationScopeInfo.getName()); return tracer.spanBuilder(spanName); } - return new SdkSpanBuilder( - spanName, instrumentationScopeInfo, sharedState, sharedState.getSpanLimits()); + return INCUBATOR_AVAILABLE + ? IncubatingUtil.createExtendedSpanBuilder( + spanName, instrumentationScopeInfo, sharedState, sharedState.getSpanLimits()) + : new SdkSpanBuilder( + spanName, instrumentationScopeInfo, sharedState, sharedState.getSpanLimits()); } // Visible for testing InstrumentationScopeInfo getInstrumentationScopeInfo() { return instrumentationScopeInfo; } - - @Override - public boolean isEnabled() { - return tracerEnabled; - } } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProvider.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProvider.java index 036e812c5ab..14ccc37c41f 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProvider.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProvider.java @@ -56,7 +56,7 @@ public static SdkTracerProviderBuilder builder() { this.tracerSdkComponentRegistry = new ComponentRegistry<>( instrumentationScopeInfo -> - new SdkTracer( + SdkTracer.create( sharedState, instrumentationScopeInfo, getTracerConfig(instrumentationScopeInfo))); diff --git a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/TracerConfigTest.java b/sdk/trace/src/testIncubating/java/io/opentelemetry/sdk/trace/TracerConfigTest.java similarity index 99% rename from sdk/trace/src/test/java/io/opentelemetry/sdk/trace/TracerConfigTest.java rename to sdk/trace/src/testIncubating/java/io/opentelemetry/sdk/trace/TracerConfigTest.java index 4421185aeea..e7aefbb5152 100644 --- a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/TracerConfigTest.java +++ b/sdk/trace/src/testIncubating/java/io/opentelemetry/sdk/trace/TracerConfigTest.java @@ -11,6 +11,7 @@ import static io.opentelemetry.sdk.trace.internal.TracerConfig.defaultConfig; import static io.opentelemetry.sdk.trace.internal.TracerConfig.disabled; import static io.opentelemetry.sdk.trace.internal.TracerConfig.enabled; +import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.incubator.trace.ExtendedTracer;