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 exporter providers #4950

Merged
merged 1 commit into from Nov 28, 2022
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
2 changes: 2 additions & 0 deletions exporters/logging/build.gradle.kts
Expand Up @@ -13,6 +13,8 @@ dependencies {
api(project(":sdk:metrics"))
api(project(":sdk:logs"))

implementation(project(":sdk-extensions:autoconfigure-spi"))

testImplementation(project(":sdk:testing"))
testImplementation(project(":sdk:logs-testing"))
}
@@ -0,0 +1,29 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.logging.internal;

import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter;
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 SystemOutLogRecordExporter}.
*
* <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 SystemOutLogRecordExporter.create();
}

@Override
public String getName() {
return "logging";
}
}
@@ -0,0 +1,29 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.logging.internal;

import io.opentelemetry.exporter.logging.LoggingMetricExporter;
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 LoggingMetricExporter}.
*
* <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 LoggingMetricExporter.create();
}

@Override
public String getName() {
return "logging";
}
}
@@ -0,0 +1,29 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.logging.internal;

import io.opentelemetry.exporter.logging.LoggingSpanExporter;
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 LoggingSpanExporter}.
*
* <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 LoggingSpanExporter.create();
}

@Override
public String getName() {
return "logging";
}
}
@@ -0,0 +1 @@
io.opentelemetry.exporter.logging.internal.LoggingLogRecordExporterProvider
@@ -0,0 +1 @@
io.opentelemetry.exporter.logging.internal.LoggingMetricExporterProvider
@@ -0,0 +1 @@
io.opentelemetry.exporter.logging.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"))
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.SystemOutLogRecordExporter;
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 @@ -30,6 +29,12 @@
class LogRecordExporterConfiguration {

private static final String EXPORTER_NONE = "none";
private static final Map<String, String> EXPORTER_ARTIFACT_ID_BY_NAME;

static {
EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>();
EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging");
}

// Visible for test
static Map<String, LogRecordExporter> configureLogRecordExporters(
Expand Down Expand Up @@ -85,15 +90,18 @@ static LogRecordExporter configureExporter(
switch (name) {
case "otlp":
return configureOtlpLogs(config, meterProvider);
case "logging":
ClasspathUtil.checkClassExists(
"io.opentelemetry.exporter.logging.SystemOutLogRecordExporter",
"Logging Log Exporter",
"opentelemetry-exporter-logging");
return SystemOutLogRecordExporter.create();
default:
LogRecordExporter spiExporter = spiExportersManager.getByName(name);
if (spiExporter == null) {
String artifactId = EXPORTER_ARTIFACT_ID_BY_NAME.get(name);
if (artifactId != null) {
throw new ConfigurationException(
"otel.logs.exporter set to \""
+ name
+ "\" but "
+ artifactId
+ " not found on classpath. Make sure to add it as a dependency.");
}
throw new ConfigurationException("Unrecognized value for otel.logs.exporter: " + name);
}
return spiExporter;
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.LoggingMetricExporter;
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 @@ -24,12 +23,20 @@
import io.opentelemetry.sdk.metrics.export.MetricReader;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import javax.annotation.Nullable;

final class MetricExporterConfiguration {

private static final Duration DEFAULT_EXPORT_INTERVAL = Duration.ofMinutes(1);
private static final Map<String, String> EXPORTER_ARTIFACT_ID_BY_NAME;

static {
EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>();
EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging");
}

static MetricReader configureExporter(
String name,
Expand All @@ -46,12 +53,18 @@ static MetricReader configureExporter(
case "otlp":
metricExporter = configureOtlpMetrics(config);
break;
case "logging":
metricExporter = configureLoggingExporter();
break;
default:
MetricExporter spiExporter = configureSpiExporter(name, config, serviceClassLoader);
if (spiExporter == null) {
String artifactId = EXPORTER_ARTIFACT_ID_BY_NAME.get(name);
if (artifactId != null) {
throw new ConfigurationException(
"otel.metrics.exporter set to \""
+ name
+ "\" but "
+ artifactId
+ " not found on classpath. Make sure to add it as a dependency.");
}
throw new ConfigurationException("Unrecognized value for otel.metrics.exporter: " + name);
}
metricExporter = spiExporter;
Expand All @@ -61,14 +74,6 @@ static MetricReader configureExporter(
return configurePeriodicMetricReader(config, metricExporter);
}

private static MetricExporter configureLoggingExporter() {
ClasspathUtil.checkClassExists(
"io.opentelemetry.exporter.logging.LoggingMetricExporter",
"Logging Metrics Exporter",
"opentelemetry-exporter-logging");
return LoggingMetricExporter.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.LoggingSpanExporter;
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 @@ -27,6 +26,7 @@
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
Expand All @@ -35,6 +35,12 @@
final class SpanExporterConfiguration {

private static final String EXPORTER_NONE = "none";
private static final Map<String, String> EXPORTER_ARTIFACT_ID_BY_NAME;

static {
EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>();
EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging");
}

// Visible for testing
static Map<String, SpanExporter> configureSpanExporters(
Expand Down Expand Up @@ -92,15 +98,18 @@ static SpanExporter configureExporter(
return configureJaeger(config, meterProvider);
case "zipkin":
return configureZipkin(config);
case "logging":
ClasspathUtil.checkClassExists(
"io.opentelemetry.exporter.logging.LoggingSpanExporter",
"Logging Trace Exporter",
"opentelemetry-exporter-logging");
return LoggingSpanExporter.create();
default:
SpanExporter spiExporter = spiExportersManager.getByName(name);
if (spiExporter == null) {
String artifactId = EXPORTER_ARTIFACT_ID_BY_NAME.get(name);
if (artifactId != null) {
throw new ConfigurationException(
"otel.traces.exporter set to \""
+ name
+ "\" but "
+ artifactId
+ " not found on classpath. Make sure to add it as a dependency.");
}
throw new ConfigurationException("Unrecognized value for otel.traces.exporter: " + name);
}
return spiExporter;
Expand Down
Expand Up @@ -77,8 +77,8 @@ void loggingSpans() {
"logging", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop()))
.isInstanceOf(ConfigurationException.class)
.hasMessageContaining(
"Logging Trace Exporter enabled but opentelemetry-exporter-logging not found on "
+ "classpath");
"otel.traces.exporter set to \"logging\" but opentelemetry-exporter-logging not found on classpath."
+ " Make sure to add it as a dependency.");
}

@Test
Expand All @@ -92,8 +92,8 @@ void loggingMetrics() {
(a, unused) -> a))
.isInstanceOf(ConfigurationException.class)
.hasMessageContaining(
"Logging Metrics Exporter enabled but opentelemetry-exporter-logging not found on "
+ "classpath");
"otel.metrics.exporter set to \"logging\" but opentelemetry-exporter-logging not found on classpath."
+ " Make sure to add it as a dependency.");
}

@Test
Expand All @@ -104,8 +104,8 @@ void loggingLogs() {
"logging", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop()))
.isInstanceOf(ConfigurationException.class)
.hasMessageContaining(
"Logging Log Exporter enabled but opentelemetry-exporter-logging not found on "
+ "classpath");
"otel.logs.exporter set to \"logging\" but opentelemetry-exporter-logging not found on classpath."
+ " Make sure to add it as a dependency.");
}

@Test
Expand Down