forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto-configure support for logging-otlp (open-telemetry#4879)
* Add autoconfigure support for logging-otlp * Add NotOnClasspath tests * Fix formatting * Declare logging-otlp as experimental, add unit test * Spotless Co-authored-by: Jack Berg <[email protected]>
- Loading branch information
Showing
8 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...onfigure/src/testLoggingOtlp/java/io/opentelemetry/sdk/autoconfigure/LoggingOtlpTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.autoconfigure; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.github.netmikey.logunit.api.LogCapturer; | ||
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter; | ||
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter; | ||
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter; | ||
import io.opentelemetry.sdk.OpenTelemetrySdk; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class LoggingOtlpTest { | ||
|
||
@RegisterExtension | ||
LogCapturer spansCapturer = | ||
LogCapturer.create().captureForType(OtlpJsonLoggingSpanExporter.class); | ||
|
||
@RegisterExtension | ||
LogCapturer metricsCapturer = | ||
LogCapturer.create().captureForType(OtlpJsonLoggingMetricExporter.class); | ||
|
||
@RegisterExtension | ||
LogCapturer logsCapturer = | ||
LogCapturer.create().captureForType(OtlpJsonLoggingLogRecordExporter.class); | ||
|
||
@Test | ||
void configures() { | ||
OpenTelemetrySdk sdk = | ||
AutoConfiguredOpenTelemetrySdk.builder() | ||
.setConfig( | ||
DefaultConfigProperties.createForTest( | ||
ImmutableMap.of( | ||
"otel.traces.exporter", "logging-otlp", | ||
"otel.metrics.exporter", "logging-otlp", | ||
"otel.logs.exporter", "logging-otlp"))) | ||
.setResultAsGlobal(false) | ||
.build() | ||
.getOpenTelemetrySdk(); | ||
|
||
sdk.getTracerProvider().get("tracer").spanBuilder("test").startSpan().end(); | ||
sdk.getMeterProvider().get("meter").counterBuilder("counter").build().add(10); | ||
sdk.getSdkLoggerProvider().get("logger").logRecordBuilder().setBody("message").emit(); | ||
|
||
sdk.getSdkLoggerProvider().forceFlush().join(10, TimeUnit.SECONDS); | ||
sdk.getSdkMeterProvider().forceFlush().join(10, TimeUnit.SECONDS); | ||
sdk.getSdkLoggerProvider().forceFlush().join(10, TimeUnit.SECONDS); | ||
|
||
await() | ||
.untilAsserted( | ||
() -> assertThat(spansCapturer.getEvents().size()).isGreaterThanOrEqualTo(1)); | ||
await() | ||
.untilAsserted( | ||
() -> assertThat(metricsCapturer.getEvents().size()).isGreaterThanOrEqualTo(1)); | ||
await() | ||
.untilAsserted(() -> assertThat(logsCapturer.getEvents().size()).isGreaterThanOrEqualTo(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters