Skip to content

Commit

Permalink
Implement logging-otlp exporter providers
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg committed Nov 28, 2022
1 parent 7dd5c1c commit 4393d93
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 47 deletions.
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 @@ -41,6 +40,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");
}

// Visible for testing
Expand Down Expand Up @@ -69,12 +69,7 @@ static Map<String, SpanExporter> configureSpanExporters(
}

NamedSpiManager<SpanExporter> spiExportersManager =
SpiUtil.loadConfigurable(
ConfigurableSpanExporterProvider.class,
ConfigurableSpanExporterProvider::getName,
ConfigurableSpanExporterProvider::createExporter,
config,
serviceClassLoader);
spanExporterSpiManager(config, serviceClassLoader);

return exporterNames.stream()
.collect(
Expand All @@ -86,6 +81,17 @@ static Map<String, SpanExporter> configureSpanExporters(
config)));
}

// Visible for testing
static NamedSpiManager<SpanExporter> spanExporterSpiManager(
ConfigProperties config, ClassLoader serviceClassLoader) {
return SpiUtil.loadConfigurable(
ConfigurableSpanExporterProvider.class,
ConfigurableSpanExporterProvider::getName,
ConfigurableSpanExporterProvider::createExporter,
config,
serviceClassLoader);
}

// Visible for testing
static SpanExporter configureExporter(
String name,
Expand All @@ -99,12 +105,6 @@ static SpanExporter configureExporter(
return configureJaeger(config, meterProvider);
case "zipkin":
return configureZipkin(config);
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 @@ -86,11 +86,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 @@ -119,8 +124,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 @@ -140,11 +145,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

0 comments on commit 4393d93

Please sign in to comment.