Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove -alpha artifacts from runtime classpath of stable components #6944

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration-tests/graal-incubating/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,4 +42,63 @@ void incubatingApiIsLoadedViaReflection() {
assertThat(MeterProvider.noop().get("test").counterBuilder("test"))
.isInstanceOf(ExtendedLongCounterBuilder.class);
}

@Test
void incubatingLogSdk() {
Copy link
Member Author

@jack-berg jack-berg Dec 19, 2024

Choose a reason for hiding this comment

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

Not sure why, but these new graal nativeTest woked without any additional reflect-config.json entries, despite new reflective access in the SDK via Class.forName. 🤔

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();
}
}
7 changes: 6 additions & 1 deletion sdk-extensions/autoconfigure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -23,6 +23,11 @@ dependencies {

testing {
suites {
register<JvmTestSuite>("testIncubating") {
dependencies {
implementation(project(":api:incubator"))
}
}
register<JvmTestSuite>("testAutoConfigureOrder") {
targets {
all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -156,7 +154,6 @@ public SdkLoggerProviderBuilder apply(
@BeforeEach
void resetGlobal() {
GlobalOpenTelemetry.resetForTest();
GlobalEventLoggerProvider.resetForTest();
builder =
AutoConfiguredOpenTelemetrySdk.builder()
.addPropertiesSupplier(disableExportPropertySupplier());
Expand Down Expand Up @@ -456,18 +453,13 @@ void builder_setResultAsGlobalFalse() {
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());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Map<String, String>> disableExportPropertySupplier() {
Map<String, String> props = new HashMap<>();
props.put("otel.metrics.exporter", "none");
props.put("otel.traces.exporter", "none");
props.put("otel.logs.exporter", "none");
return () -> props;
}
}
20 changes: 19 additions & 1 deletion sdk/logs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -21,3 +21,21 @@ dependencies {
testImplementation("org.awaitility:awaitility")
testImplementation("com.google.guava:guava")
}

testing {
suites {
register<JvmTestSuite>("testIncubating") {
dependencies {
implementation(project(":sdk:testing"))
implementation(project(":api:incubator"))
implementation("com.google.guava:guava")
}
}
}
}

tasks {
check {
dependsOn(testing.suites)
}
}
Loading
Loading