forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Telemetry exporter config (opensearch-project#8624)
* Makes exporter configurable Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Makes exporter configurable Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Makes exporter configurable Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Makes exporter configurable Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Makes exporter configurable Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Add logs for successful instantiation Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Move settings to OtelTelemetrySettings Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Move settings to OtelTelemetrySettings Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Move settings to OtelTelemetrySettings Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Add test cases Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Fix test cases Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Empty-Commit Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Empty-Commit Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Fix test cases Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * refactor Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * refactor Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * refactor Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> --------- Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> Signed-off-by: Gagan Juneja <gagandeepjuneja@gmail.com> Co-authored-by: Gagan Juneja <gjjuneja@amazon.com> Signed-off-by: sahil buddharaju <sahilbud@amazon.com>
- Loading branch information
1 parent
bcfb779
commit 7c8dcf2
Showing
10 changed files
with
315 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetrySettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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; | ||
|
||
import io.opentelemetry.exporter.logging.LoggingSpanExporter; | ||
import io.opentelemetry.sdk.trace.export.SpanExporter; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedActionException; | ||
import java.security.PrivilegedExceptionAction; | ||
import org.opensearch.SpecialPermission; | ||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.telemetry.tracing.exporter.OTelSpanExporterFactory; | ||
|
||
/** | ||
* OTel specific telemetry settings. | ||
*/ | ||
public final class OTelTelemetrySettings { | ||
|
||
/** | ||
* Base Constructor. | ||
*/ | ||
private OTelTelemetrySettings() {} | ||
|
||
/** | ||
* span exporter batch size | ||
*/ | ||
public static final Setting<Integer> TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( | ||
"telemetry.otel.tracer.exporter.batch_size", | ||
512, | ||
1, | ||
Setting.Property.NodeScope, | ||
Setting.Property.Final | ||
); | ||
/** | ||
* span exporter max queue size | ||
*/ | ||
public static final Setting<Integer> TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING = Setting.intSetting( | ||
"telemetry.otel.tracer.exporter.max_queue_size", | ||
2048, | ||
1, | ||
Setting.Property.NodeScope, | ||
Setting.Property.Final | ||
); | ||
/** | ||
* span exporter delay in seconds | ||
*/ | ||
public static final Setting<TimeValue> TRACER_EXPORTER_DELAY_SETTING = Setting.timeSetting( | ||
"telemetry.otel.tracer.exporter.delay", | ||
TimeValue.timeValueSeconds(2), | ||
Setting.Property.NodeScope, | ||
Setting.Property.Final | ||
); | ||
|
||
/** | ||
* Span Exporter type setting. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public static final Setting<Class<SpanExporter>> OTEL_TRACER_SPAN_EXPORTER_CLASS_SETTING = new Setting<>( | ||
"telemetry.otel.tracer.span.exporter.class", | ||
LoggingSpanExporter.class.getName(), | ||
className -> { | ||
// Check we ourselves are not being called by unprivileged code. | ||
SpecialPermission.check(); | ||
|
||
try { | ||
return AccessController.doPrivileged((PrivilegedExceptionAction<Class<SpanExporter>>) () -> { | ||
final ClassLoader loader = OTelSpanExporterFactory.class.getClassLoader(); | ||
return (Class<SpanExporter>) loader.loadClass(className); | ||
}); | ||
} catch (PrivilegedActionException ex) { | ||
throw new IllegalStateException("Unable to load span exporter class:" + className, ex.getCause()); | ||
} | ||
}, | ||
Setting.Property.NodeScope, | ||
Setting.Property.Final | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...otel/src/main/java/org/opensearch/telemetry/tracing/exporter/OTelSpanExporterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* 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 io.opentelemetry.sdk.trace.export.SpanExporter; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.MethodType; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedActionException; | ||
import java.security.PrivilegedExceptionAction; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.SpecialPermission; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.telemetry.OTelTelemetrySettings; | ||
|
||
/** | ||
* Factory class to create the {@link SpanExporter} instance. | ||
*/ | ||
public class OTelSpanExporterFactory { | ||
|
||
private static final Logger logger = LogManager.getLogger(OTelSpanExporterFactory.class); | ||
|
||
/** | ||
* Base constructor. | ||
*/ | ||
private OTelSpanExporterFactory() { | ||
|
||
} | ||
|
||
/** | ||
* Creates the {@link SpanExporter} instances based on the OTEL_TRACER_SPAN_EXPORTER_CLASS_SETTING value. | ||
* As of now, it expects the SpanExporter implementations to have a create factory method to instantiate the | ||
* SpanExporter. | ||
* @param settings settings. | ||
* @return SpanExporter instance. | ||
*/ | ||
public static SpanExporter create(Settings settings) { | ||
Class<SpanExporter> spanExporterProviderClass = OTelTelemetrySettings.OTEL_TRACER_SPAN_EXPORTER_CLASS_SETTING.get(settings); | ||
SpanExporter spanExporter = instantiateSpanExporter(spanExporterProviderClass); | ||
logger.info("Successfully instantiated the SpanExporter class {}", spanExporterProviderClass); | ||
return spanExporter; | ||
} | ||
|
||
private static SpanExporter instantiateSpanExporter(Class<SpanExporter> spanExporterProviderClass) { | ||
try { | ||
// Check we ourselves are not being called by unprivileged code. | ||
SpecialPermission.check(); | ||
return AccessController.doPrivileged((PrivilegedExceptionAction<SpanExporter>) () -> { | ||
try { | ||
return (SpanExporter) MethodHandles.publicLookup() | ||
.findStatic(spanExporterProviderClass, "create", MethodType.methodType(spanExporterProviderClass)) | ||
.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() + "]"); | ||
} else { | ||
throw new IllegalStateException( | ||
"SpanExporter instantiation failed for class [" + spanExporterProviderClass.getName() + "]", | ||
e.getCause() | ||
); | ||
} | ||
} | ||
}); | ||
} catch (PrivilegedActionException ex) { | ||
throw new IllegalStateException( | ||
"SpanExporter instantiation failed for class [" + spanExporterProviderClass.getName() + "]", | ||
ex.getCause() | ||
); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
.../telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* This package contains classes needed for telemetry. | ||
*/ | ||
package org.opensearch.telemetry.tracing.exporter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...metry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/DummySpanExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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 io.opentelemetry.sdk.common.CompletableResultCode; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.opentelemetry.sdk.trace.export.SpanExporter; | ||
import java.util.Collection; | ||
|
||
public class DummySpanExporter implements SpanExporter { | ||
@Override | ||
public CompletableResultCode export(Collection<SpanData> spans) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public CompletableResultCode flush() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public CompletableResultCode shutdown() { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.