Skip to content

Commit

Permalink
[GOBBLIN-2161] Support for configuring openTelemetry metric exporter …
Browse files Browse the repository at this point in the history
…as logExporter (#4061)

* Support for configuring openTelemetry metric exporter as logExporter

* Added a TODO to use factory pattern
  • Loading branch information
khandelwal-prateek authored Sep 30, 2024
1 parent 4fa6c51 commit 2bc5638
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2bc5638

Please sign in to comment.