diff --git a/gobblin-api/src/main/java/org/apache/gobblin/configuration/ConfigurationKeys.java b/gobblin-api/src/main/java/org/apache/gobblin/configuration/ConfigurationKeys.java index 637cdeba065..7b33f1d3031 100644 --- a/gobblin-api/src/main/java/org/apache/gobblin/configuration/ConfigurationKeys.java +++ b/gobblin-api/src/main/java/org/apache/gobblin/configuration/ConfigurationKeys.java @@ -911,6 +911,12 @@ public class ConfigurationKeys { public static final String METRICS_REPORTING_OPENTELEMETRY_PREFIX = "metrics.reporting.opentelemetry."; public static final String METRICS_REPORTING_OPENTELEMETRY_ENABLED = METRICS_REPORTING_OPENTELEMETRY_PREFIX + "enabled"; + public static final String METRICS_REPORTING_OPENTELEMETRY_LOGEXPORTER_ENABLED = METRICS_REPORTING_OPENTELEMETRY_PREFIX + "logexporter.enabled"; + + public static final Boolean DEFAULT_METRICS_REPORTING_OPENTELEMETRY_LOGEXPORTER_ENABLED = false; + + public static final String METRICS_REPORTING_OPENTELEMETRY_LOGEXPORTER_CLASSNAME = METRICS_REPORTING_OPENTELEMETRY_PREFIX + "logexporter.className"; + public static final String METRICS_REPORTING_OPENTELEMETRY_CONFIGS_PREFIX = METRICS_REPORTING_OPENTELEMETRY_PREFIX + "configs."; public static final Boolean DEFAULT_METRICS_REPORTING_OPENTELEMETRY_ENABLED = false; diff --git a/gobblin-metrics-libs/gobblin-metrics/src/main/java/org/apache/gobblin/metrics/OpenTelemetryMetrics.java b/gobblin-metrics-libs/gobblin-metrics/src/main/java/org/apache/gobblin/metrics/OpenTelemetryMetrics.java index 522568462b9..ce85b6ad895 100644 --- a/gobblin-metrics-libs/gobblin-metrics/src/main/java/org/apache/gobblin/metrics/OpenTelemetryMetrics.java +++ b/gobblin-metrics-libs/gobblin-metrics/src/main/java/org/apache/gobblin/metrics/OpenTelemetryMetrics.java @@ -17,6 +17,7 @@ package org.apache.gobblin.metrics; +import java.lang.reflect.Method; import java.time.Duration; import java.util.HashMap; import java.util.Map; @@ -59,6 +60,20 @@ private OpenTelemetryMetrics(State state) { @Override protected MetricExporter initializeMetricExporter(State state) { + // TODO: Refactor the method to use a factory pattern for instantiating MetricExporter. Each MetricExporter + // type would have its own factory class, ensuring proper instantiation and handling specific configs. + if (state.getPropAsBoolean(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_LOGEXPORTER_ENABLED, + ConfigurationKeys.DEFAULT_METRICS_REPORTING_OPENTELEMETRY_LOGEXPORTER_ENABLED)) { + try { + Class clazz = Class.forName(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_LOGEXPORTER_CLASSNAME); + Method instanceMethod = clazz.getMethod("instance"); + // Invoke the method to get the singleton instance + return metricExporter = (MetricExporter) instanceMethod.invoke(null); + } catch (Exception e) { + log.error("Error occurred while instantiating opentelemetry LogExporter class", e); + } + } + Preconditions.checkArgument(state.contains(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_ENDPOINT), "OpenTelemetry endpoint must be provided"); OtlpHttpMetricExporterBuilder httpExporterBuilder = OtlpHttpMetricExporter.builder();