-
Notifications
You must be signed in to change notification settings - Fork 1k
Add auto-configure support for logging-otlp #4879
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
Changes from 4 commits
918faf7
601e82a
0fa4d94
0cd2f4f
8b5a2dc
318f2d6
8b3c3e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import io.opentelemetry.api.metrics.MeterProvider; | ||
| import io.opentelemetry.exporter.internal.retry.RetryUtil; | ||
| import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter; | ||
| import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter; | ||
| import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; | ||
| import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder; | ||
| import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; | ||
|
|
@@ -91,6 +92,12 @@ static LogRecordExporter configureExporter( | |
| "Logging Log Exporter", | ||
| "opentelemetry-exporter-logging"); | ||
| return SystemOutLogRecordExporter.create(); | ||
| case "logging-otlp": | ||
| ClasspathUtil.checkClassExists( | ||
| "io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter", | ||
| "OTLP JSON Logging Log Exporter", | ||
| "opentelemetry-exporter-logging-otlp"); | ||
| return OtlpJsonLoggingLogRecordExporter.create(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about providing a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could give a shot if it's desired. Initially I was just following the code pattern used for the "logging" exporter.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been thinking this may be a good idea to do for all the exporters from a separation of concerns perspective. If each exporter artifact contains a What do you think @jkwatson? BTW, for the purposes of this PR I do think we should continue the current pattern. If we agree on implementing providers, we can open a separate issue to track that work.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this sounds great, and could help guide users into good practices when they are trying to extend autoconfigure with their own items (e.g. exporters)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
👍 |
||
| default: | ||
| LogRecordExporter spiExporter = spiExportersManager.getByName(name); | ||
| if (spiExporter == null) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * 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)); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.