Skip to content

Commit

Permalink
Use OtlpJsonLoggingMetricExporter
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhant Deshmukh <[email protected]>
  • Loading branch information
deshsidd committed Aug 12, 2024
1 parent 1e3bb88 commit f37a5fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.telemetry.OTelTelemetrySettings;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -66,10 +67,12 @@ private static MetricExporter instantiateExporter(Class<MetricExporter> exporter
}
}
try {
return (MetricExporter) MethodHandles.publicLookup()
.findStatic(exporterProviderClass, methodName, MethodType.methodType(exporterProviderClass))
.asType(MethodType.methodType(MetricExporter.class))
.invokeExact();
MethodHandles.Lookup lookup = MethodHandles.publicLookup();
MethodType methodType = MethodType.methodType(MetricExporter.class);

// Look up the 'create' method with no parameters
MethodHandle handle = lookup.findStatic(exporterProviderClass, methodName, methodType);
return (MetricExporter) handle.invokeExact();
} catch (Throwable e) {
if (e.getCause() instanceof NoSuchMethodException) {
throw new IllegalStateException("No create factory method exist in [" + exporterProviderClass.getName() + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,4 @@ public void testMetricExporterNonMetricExporterClass() {
assertTrue(exception.getCause() instanceof NoSuchMethodError);

}

public void testMetricExporterGetDefaultMethod() {
Settings settings = Settings.builder()
.put(
OTelTelemetrySettings.OTEL_METRICS_EXPORTER_CLASS_SETTING.getKey(),
"io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter"
)
.build();

assertTrue(OTelMetricsExporterFactory.create(settings) instanceof OtlpGrpcMetricExporter);
}

}

0 comments on commit f37a5fa

Please sign in to comment.