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

Implement logging-otlp exporter providers #4992

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions exporters/logging-otlp/build.gradle.kts
Expand Up @@ -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")

Expand Down
@@ -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
1 change: 0 additions & 1 deletion sdk-extensions/autoconfigure/build.gradle.kts
Expand Up @@ -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"))
Expand Down
Expand Up @@ -11,7 +11,6 @@

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;
Expand All @@ -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
Expand All @@ -60,12 +60,7 @@ static Map<String, LogRecordExporter> configureLogRecordExporters(
}

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) {
Expand All @@ -81,6 +76,17 @@ static Map<String, LogRecordExporter> configureLogRecordExporters(
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(
Expand All @@ -91,12 +97,6 @@ static LogRecordExporter configureExporter(
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) {
Expand Down
Expand Up @@ -10,7 +10,6 @@
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;
Expand All @@ -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(
Expand All @@ -54,9 +54,6 @@ static MetricReader configureExporter(
case "otlp":
metricExporter = configureOtlpMetrics(config);
break;
case "logging-otlp":
metricExporter = configureLoggingOtlpExporter();
break;
default:
MetricExporter spiExporter = configureSpiExporter(name, config, serviceClassLoader);
if (spiExporter == null) {
Expand All @@ -78,14 +75,6 @@ static MetricReader configureExporter(
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(
Expand Down
Expand Up @@ -14,7 +14,6 @@
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;
Expand All @@ -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");
}

Expand Down Expand Up @@ -102,12 +102,6 @@ static SpanExporter configureExporter(
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) {
Expand Down
Expand Up @@ -87,11 +87,16 @@ void loggingSpansOtlp() {
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
Expand Down Expand Up @@ -120,8 +125,8 @@ void loggingMetricsOtlp() {
(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
Expand All @@ -141,11 +146,16 @@ void loggingLogsOtlp() {
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
Expand Down