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

[Telemetry-Otel] Added support for OtlpGrpcSpanExporter exporter #9666

Merged
merged 18 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added test for OtlpGrpcSpanExporterProvider
Signed-off-by: Shephali Mittal <shephalm@amazon.com>
  • Loading branch information
Shephali Mittal committed Sep 5, 2023
commit 8ac6b89d5c056464df791d7e1982a0fe4d757251
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
Expand Down Expand Up @@ -55,16 +56,16 @@ private static SpanExporter instantiateSpanExporter(Class<SpanExporter> spanExpo
// Check we ourselves are not being called by unprivileged code.
SpecialPermission.check();
return AccessController.doPrivileged((PrivilegedExceptionAction<SpanExporter>) () -> {
try {
String methodName = "create";
boolean createMethodWithSettingsParamExists = true;
try {
// Attempt to get the method with the specified name and parameter types
spanExporterProviderClass.getMethod(methodName, Settings.class);
} catch (NoSuchMethodException e) {
createMethodWithSettingsParamExists = false;
String methodName = "create";
boolean isCreateMethodContainsSettingsParam = false;
Shephalimittal marked this conversation as resolved.
Show resolved Hide resolved
for (Method m : spanExporterProviderClass.getMethods()) {
if (m.getName().equals(methodName) && m.getParameterCount() == 1 && m.getParameterTypes()[0] == Settings.class) {
isCreateMethodContainsSettingsParam = true;
break;
}
if (createMethodWithSettingsParamExists) {
}
try {
if (isCreateMethodContainsSettingsParam) {
return (SpanExporter) MethodHandles.publicLookup()
.findStatic(
spanExporterProviderClass,
Expand All @@ -79,7 +80,6 @@ private static SpanExporter instantiateSpanExporter(Class<SpanExporter> spanExpo
.asType(MethodType.methodType(SpanExporter.class))
.invokeExact();
}

} catch (Throwable e) {
if (e.getCause() instanceof NoSuchMethodException) {
throw new IllegalStateException("No create factory method exist in [" + spanExporterProviderClass.getName() + "]");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.telemetry.tracing.exporter;

import org.opensearch.common.settings.Settings;
import org.opensearch.telemetry.OTelTelemetrySettings;
import org.opensearch.test.OpenSearchTestCase;

public class OtlpGrpcSpanExporterProviderTests extends OpenSearchTestCase {
public void testSpanExporterInstantiatedProperly() {
Settings settings = Settings.builder()
.put(
OTelTelemetrySettings.OTEL_TRACER_SPAN_EXPORTER_CLASS_SETTING.getKey(),
"org.opensearch.telemetry.tracing.exporter.OtlpGrpcSpanExporterProvider"
)
.build();

assertTrue(OTelSpanExporterFactory.create(settings) instanceof OtlpGrpcSpanExporterProvider);
}
}