Skip to content

Commit

Permalink
Use OtlpJsonLoggingMetricExporter to export otlp metrics to log file
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhant Deshmukh <[email protected]>
  • Loading branch information
deshsidd committed Aug 8, 2024
1 parent 18fe3ac commit 3b02460
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions plugins/telemetry-otel/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
api "io.opentelemetry:opentelemetry-sdk-trace:${versions.opentelemetry}"
api "io.opentelemetry:opentelemetry-sdk-metrics:${versions.opentelemetry}"
api "io.opentelemetry:opentelemetry-exporter-logging:${versions.opentelemetry}"
api "io.opentelemetry:opentelemetry-exporter-logging-otlp:${versions.opentelemetry}"
api "io.opentelemetry.semconv:opentelemetry-semconv:${versions.opentelemetrysemconv}"
api "io.opentelemetry:opentelemetry-sdk-logs:${versions.opentelemetry}"
api "io.opentelemetry:opentelemetry-exporter-otlp:${versions.opentelemetry}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ appender.metrics.strategy.type = DefaultRolloverStrategy
appender.metrics.strategy.max = 4


logger.metrics_exporter.name = io.opentelemetry.exporter.logging.LoggingMetricExporter
logger.metrics_exporter.name = io.opentelemetry.exporter.logging.OtlpJsonLoggingMetricExporter
logger.metrics_exporter.level = INFO
logger.metrics_exporter.appenderRef.tracing.ref = metrics
logger.metrics_exporter.additivity = false
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.Arrays;
import java.util.List;

import io.opentelemetry.exporter.logging.LoggingMetricExporter;
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter;
import io.opentelemetry.exporter.logging.LoggingSpanExporter;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.sdk.trace.export.SpanExporter;
Expand Down Expand Up @@ -99,7 +99,7 @@ private OTelTelemetrySettings() {}
@SuppressWarnings({ "unchecked", "removal" })
public static final Setting<Class<MetricExporter>> OTEL_METRICS_EXPORTER_CLASS_SETTING = new Setting<>(
"telemetry.otel.metrics.exporter.class",
LoggingMetricExporter.class.getName(),
OtlpJsonLoggingMetricExporter.class.getName(),
className -> {
// Check we ourselves are not being called by unprivileged code.
SpecialPermission.check();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

package org.opensearch.telemetry.metrics.exporter;

import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter;
import org.opensearch.common.settings.Settings;
import org.opensearch.telemetry.OTelTelemetrySettings;
import org.opensearch.test.OpenSearchTestCase;

import io.opentelemetry.exporter.logging.LoggingMetricExporter;
import io.opentelemetry.exporter.logging.OtlpJsonLoggingMetricExporter;
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter;
import io.opentelemetry.sdk.metrics.export.MetricExporter;

Expand All @@ -21,18 +22,18 @@ public class OTelMetricsExporterFactoryTests extends OpenSearchTestCase {
public void testMetricsExporterDefault() {
Settings settings = Settings.builder().build();
MetricExporter metricExporter = OTelMetricsExporterFactory.create(settings);
assertTrue(metricExporter instanceof LoggingMetricExporter);
assertTrue(metricExporter instanceof OtlpJsonLoggingMetricExporter);
}

public void testMetricsExporterLogging() {
Settings settings = Settings.builder()
.put(
OTelTelemetrySettings.OTEL_METRICS_EXPORTER_CLASS_SETTING.getKey(),
"io.opentelemetry.exporter.logging.LoggingMetricExporter"
"io.opentelemetry.exporter.logging.OtlpJsonLoggingMetricExporter"
)
.build();
MetricExporter metricExporter = OTelMetricsExporterFactory.create(settings);
assertTrue(metricExporter instanceof LoggingMetricExporter);
assertTrue(metricExporter instanceof OtlpJsonLoggingMetricExporter);
}

public void testMetricExporterInvalid() {
Expand Down

0 comments on commit 3b02460

Please sign in to comment.