From b8fc7c58898e370fc58bfe7ad965a87953391d32 Mon Sep 17 00:00:00 2001 From: Ben Roling Date: Fri, 21 Oct 2022 08:53:05 -0500 Subject: [PATCH] Add autoconfigure support for logging-otlp --- sdk-extensions/autoconfigure/README.md | 10 ++++++++++ sdk-extensions/autoconfigure/build.gradle.kts | 1 + .../LogRecordExporterConfiguration.java | 7 +++++++ .../autoconfigure/MetricExporterConfiguration.java | 12 ++++++++++++ .../sdk/autoconfigure/SpanExporterConfiguration.java | 7 +++++++ 5 files changed, 37 insertions(+) diff --git a/sdk-extensions/autoconfigure/README.md b/sdk-extensions/autoconfigure/README.md index 49fa7fd350d..e0cd8f079e0 100644 --- a/sdk-extensions/autoconfigure/README.md +++ b/sdk-extensions/autoconfigure/README.md @@ -159,6 +159,16 @@ The logging exporter prints the name of the span along with its attributes to st | otel.metrics.exporter=logging | OTEL_METRICS_EXPORTER=logging | Select the logging exporter for metrics | | otel.logs.exporter=logging | OTEL_LOGS_EXPORTER=logging | Select the logging exporter for logs | +### Logging OTLP JSON exporter + +The logging-otlp exporter writes the telemetry data to the JUL logger in OLTP JSON form. It's a more verbose output mainly used for testing and debugging. + +| System property | Environment variable | Description | +|------------------------------------|------------------------------------|----------------------------------------------------| +| otel.traces.exporter=logging-otlp | OTEL_TRACES_EXPORTER=logging-otlp | Select the logging OTLP JSON exporter for tracing | +| otel.metrics.exporter=logging-otlp | OTEL_METRICS_EXPORTER=logging-otlp | Select the logging OTLP JSON exporter for metrics | +| otel.logs.exporter=logging-otlp | OTEL_LOGS_EXPORTER=logging-otlp | Select the logging OTLP JSON exporter for logs | + ## Propagator The propagators determine which distributed tracing header formats are used, and which baggage propagation header formats are used. diff --git a/sdk-extensions/autoconfigure/build.gradle.kts b/sdk-extensions/autoconfigure/build.gradle.kts index 63c94b23b14..9e47fbcfec1 100644 --- a/sdk-extensions/autoconfigure/build.gradle.kts +++ b/sdk-extensions/autoconfigure/build.gradle.kts @@ -17,6 +17,7 @@ dependencies { compileOnly(project(":exporters:jaeger")) compileOnly(project(":exporters:logging")) + compileOnly(project(":exporters:logging-otlp")) compileOnly(project(":exporters:otlp:all")) compileOnly(project(":exporters:otlp:logs")) compileOnly(project(":exporters:otlp:common")) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java index 927b4eceb2f..b14ef1fdea1 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java @@ -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(); default: LogRecordExporter spiExporter = spiExportersManager.getByName(name); if (spiExporter == null) { diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java index ac8e6784b3f..8cc2b211b17 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java @@ -11,6 +11,7 @@ import io.opentelemetry.exporter.internal.retry.RetryUtil; import io.opentelemetry.exporter.logging.LoggingMetricExporter; +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder; import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; @@ -49,6 +50,9 @@ static MetricReader configureExporter( case "logging": metricExporter = configureLoggingExporter(); break; + case "logging-otlp": + metricExporter = configureLoggingOtlpExporter(); + break; default: MetricExporter spiExporter = configureSpiExporter(name, config, serviceClassLoader); if (spiExporter == null) { @@ -69,6 +73,14 @@ private static MetricExporter configureLoggingExporter() { return LoggingMetricExporter.create(); } + private static MetricExporter configureLoggingOtlpExporter() { + ClasspathUtil.checkClassExists( + "io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter", + "OTLP JSON Logging Metrics Exporter", + "opentelemetry-exporter-logging-otlp"); + return OtlpJsonLoggingMetricExporter.create(); + } + // Visible for testing. @Nullable static MetricExporter configureSpiExporter( diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java index a3d2c394783..294cc9ed2e2 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java @@ -15,6 +15,7 @@ import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder; import io.opentelemetry.exporter.logging.LoggingSpanExporter; +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; @@ -98,6 +99,12 @@ static SpanExporter configureExporter( "Logging Trace Exporter", "opentelemetry-exporter-logging"); return LoggingSpanExporter.create(); + case "logging-otlp": + ClasspathUtil.checkClassExists( + "io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter", + "OTLP JSON Logging Trace Exporter", + "opentelemetry-exporter-logging-otlp"); + return OtlpJsonLoggingSpanExporter.create(); default: SpanExporter spiExporter = spiExportersManager.getByName(name); if (spiExporter == null) {