Implement logging-otlp exporter providers (#4992)
This commit is contained in:
parent
0973a7c426
commit
e79aad8dcd
|
@ -14,6 +14,7 @@ dependencies {
|
|||
compileOnly(project(":sdk:logs"))
|
||||
|
||||
implementation(project(":exporters:otlp:common"))
|
||||
implementation(project(":sdk-extensions:autoconfigure-spi"))
|
||||
|
||||
implementation("com.fasterxml.jackson.core:jackson-core")
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.exporter.logging.otlp.internal;
|
||||
|
||||
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider;
|
||||
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
|
||||
|
||||
/**
|
||||
* {@link LogRecordExporter} SPI implementation for {@link OtlpJsonLoggingLogRecordExporter}.
|
||||
*
|
||||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
|
||||
* at any time.
|
||||
*/
|
||||
public class LoggingLogRecordExporterProvider implements ConfigurableLogRecordExporterProvider {
|
||||
@Override
|
||||
public LogRecordExporter createExporter(ConfigProperties config) {
|
||||
return OtlpJsonLoggingLogRecordExporter.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "logging-otlp";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.exporter.logging.otlp.internal;
|
||||
|
||||
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider;
|
||||
import io.opentelemetry.sdk.metrics.export.MetricExporter;
|
||||
|
||||
/**
|
||||
* {@link MetricExporter} SPI implementation for {@link OtlpJsonLoggingMetricExporter}.
|
||||
*
|
||||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
|
||||
* at any time.
|
||||
*/
|
||||
public class LoggingMetricExporterProvider implements ConfigurableMetricExporterProvider {
|
||||
@Override
|
||||
public MetricExporter createExporter(ConfigProperties config) {
|
||||
return OtlpJsonLoggingMetricExporter.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "logging-otlp";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.exporter.logging.otlp.internal;
|
||||
|
||||
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider;
|
||||
import io.opentelemetry.sdk.trace.export.SpanExporter;
|
||||
|
||||
/**
|
||||
* {@link SpanExporter} SPI implementation for {@link OtlpJsonLoggingSpanExporter}.
|
||||
*
|
||||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
|
||||
* at any time.
|
||||
*/
|
||||
public class LoggingSpanExporterProvider implements ConfigurableSpanExporterProvider {
|
||||
@Override
|
||||
public SpanExporter createExporter(ConfigProperties config) {
|
||||
return OtlpJsonLoggingSpanExporter.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "logging-otlp";
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
io.opentelemetry.exporter.logging.otlp.internal.LoggingLogRecordExporterProvider
|
|
@ -0,0 +1 @@
|
|||
io.opentelemetry.exporter.logging.otlp.internal.LoggingMetricExporterProvider
|
|
@ -0,0 +1 @@
|
|||
io.opentelemetry.exporter.logging.otlp.internal.LoggingSpanExporterProvider
|
|
@ -16,7 +16,6 @@ dependencies {
|
|||
implementation(project(":exporters:common"))
|
||||
|
||||
compileOnly(project(":exporters:jaeger"))
|
||||
compileOnly(project(":exporters:logging-otlp"))
|
||||
compileOnly(project(":exporters:otlp:all"))
|
||||
compileOnly(project(":exporters:otlp:logs"))
|
||||
compileOnly(project(":exporters:otlp:common"))
|
||||
|
|
|
@ -11,7 +11,6 @@ import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PR
|
|||
|
||||
import io.opentelemetry.api.metrics.MeterProvider;
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
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;
|
||||
|
@ -35,6 +34,7 @@ class LogRecordExporterConfiguration {
|
|||
static {
|
||||
EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>();
|
||||
EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging");
|
||||
EXPORTER_ARTIFACT_ID_BY_NAME.put("logging-otlp", "opentelemetry-exporter-logging-otlp");
|
||||
}
|
||||
|
||||
// Visible for test
|
||||
|
@ -60,12 +60,7 @@ class LogRecordExporterConfiguration {
|
|||
}
|
||||
|
||||
NamedSpiManager<LogRecordExporter> spiExportersManager =
|
||||
SpiUtil.loadConfigurable(
|
||||
ConfigurableLogRecordExporterProvider.class,
|
||||
ConfigurableLogRecordExporterProvider::getName,
|
||||
ConfigurableLogRecordExporterProvider::createExporter,
|
||||
config,
|
||||
serviceClassLoader);
|
||||
logRecordExporterSpiManager(config, serviceClassLoader);
|
||||
|
||||
Map<String, LogRecordExporter> exportersByName = new HashMap<>();
|
||||
for (String name : exporterNames) {
|
||||
|
@ -81,6 +76,17 @@ class LogRecordExporterConfiguration {
|
|||
return Collections.unmodifiableMap(exportersByName);
|
||||
}
|
||||
|
||||
// Visible for testing
|
||||
static NamedSpiManager<LogRecordExporter> logRecordExporterSpiManager(
|
||||
ConfigProperties config, ClassLoader serviceClassLoader) {
|
||||
return SpiUtil.loadConfigurable(
|
||||
ConfigurableLogRecordExporterProvider.class,
|
||||
ConfigurableLogRecordExporterProvider::getName,
|
||||
ConfigurableLogRecordExporterProvider::createExporter,
|
||||
config,
|
||||
serviceClassLoader);
|
||||
}
|
||||
|
||||
// Visible for testing
|
||||
@Nullable
|
||||
static LogRecordExporter configureExporter(
|
||||
|
@ -91,12 +97,6 @@ class LogRecordExporterConfiguration {
|
|||
switch (name) {
|
||||
case "otlp":
|
||||
return configureOtlpLogs(config, meterProvider);
|
||||
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) {
|
||||
|
|
|
@ -10,7 +10,6 @@ import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC;
|
|||
import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF;
|
||||
|
||||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
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;
|
||||
|
@ -37,6 +36,7 @@ final class MetricExporterConfiguration {
|
|||
static {
|
||||
EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>();
|
||||
EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging");
|
||||
EXPORTER_ARTIFACT_ID_BY_NAME.put("logging-otlp", "opentelemetry-exporter-logging-otlp");
|
||||
}
|
||||
|
||||
static MetricReader configureExporter(
|
||||
|
@ -54,9 +54,6 @@ final class MetricExporterConfiguration {
|
|||
case "otlp":
|
||||
metricExporter = configureOtlpMetrics(config);
|
||||
break;
|
||||
case "logging-otlp":
|
||||
metricExporter = configureLoggingOtlpExporter();
|
||||
break;
|
||||
default:
|
||||
MetricExporter spiExporter = configureSpiExporter(name, config, serviceClassLoader);
|
||||
if (spiExporter == null) {
|
||||
|
@ -78,14 +75,6 @@ final class MetricExporterConfiguration {
|
|||
return configurePeriodicMetricReader(config, metricExporter);
|
||||
}
|
||||
|
||||
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(
|
||||
|
|
|
@ -14,7 +14,6 @@ import io.opentelemetry.api.metrics.MeterProvider;
|
|||
import io.opentelemetry.exporter.internal.retry.RetryUtil;
|
||||
import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter;
|
||||
import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder;
|
||||
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;
|
||||
|
@ -39,6 +38,7 @@ final class SpanExporterConfiguration {
|
|||
static {
|
||||
EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>();
|
||||
EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging");
|
||||
EXPORTER_ARTIFACT_ID_BY_NAME.put("logging-otlp", "opentelemetry-exporter-logging-otlp");
|
||||
EXPORTER_ARTIFACT_ID_BY_NAME.put("zipkin", "opentelemetry-exporter-zipkin");
|
||||
}
|
||||
|
||||
|
@ -102,12 +102,6 @@ final class SpanExporterConfiguration {
|
|||
return configureOtlp(config, meterProvider);
|
||||
case "jaeger":
|
||||
return configureJaeger(config, meterProvider);
|
||||
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) {
|
||||
|
|
|
@ -87,11 +87,16 @@ class NotOnClasspathTest {
|
|||
assertThatThrownBy(
|
||||
() ->
|
||||
SpanExporterConfiguration.configureExporter(
|
||||
"logging-otlp", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop()))
|
||||
"logging-otlp",
|
||||
EMPTY,
|
||||
SpanExporterConfiguration.spanExporterSpiManager(
|
||||
DefaultConfigProperties.createForTest(Collections.emptyMap()),
|
||||
NotOnClasspathTest.class.getClassLoader()),
|
||||
MeterProvider.noop()))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasMessageContaining(
|
||||
"OTLP JSON Logging Trace Exporter enabled but opentelemetry-exporter-logging-otlp not found on "
|
||||
+ "classpath");
|
||||
"otel.traces.exporter set to \"logging-otlp\" but opentelemetry-exporter-logging-otlp not found on classpath."
|
||||
+ " Make sure to add it as a dependency.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -120,8 +125,8 @@ class NotOnClasspathTest {
|
|||
(a, unused) -> a))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasMessageContaining(
|
||||
"OTLP JSON Logging Metrics Exporter enabled but opentelemetry-exporter-logging-otlp not found on "
|
||||
+ "classpath");
|
||||
"otel.metrics.exporter set to \"logging-otlp\" but opentelemetry-exporter-logging-otlp not found on classpath."
|
||||
+ " Make sure to add it as a dependency.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -141,11 +146,16 @@ class NotOnClasspathTest {
|
|||
assertThatThrownBy(
|
||||
() ->
|
||||
LogRecordExporterConfiguration.configureExporter(
|
||||
"logging-otlp", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop()))
|
||||
"logging-otlp",
|
||||
EMPTY,
|
||||
LogRecordExporterConfiguration.logRecordExporterSpiManager(
|
||||
DefaultConfigProperties.createForTest(Collections.emptyMap()),
|
||||
NotOnClasspathTest.class.getClassLoader()),
|
||||
MeterProvider.noop()))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasMessageContaining(
|
||||
"OTLP JSON Logging Log Exporter enabled but opentelemetry-exporter-logging-otlp not found on "
|
||||
+ "classpath");
|
||||
"otel.logs.exporter set to \"logging-otlp\" but opentelemetry-exporter-logging-otlp not found on classpath."
|
||||
+ " Make sure to add it as a dependency.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue