Opentelemetry exporters can be programmatically activated/deactivated using the SDK API of the chosen language.
In Python, for example, you can create an exporter and register/unregister it using the trace_provider
module:
from opentelemetry import trace
from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
# Create an exporter
exporter = OTLPSpanExporter()
# Create a tracer provider and register the exporter
trace_provider = TracerProvider()
trace_provider.add_span_processor(SimpleExportSpanProcessor(exporter))
# Disable the exporter
trace.set_tracer_provider(None)
Similarly, in Java, you can use the TracerSdkProvider
class and its addSpanProcessor()
and shutdown()
methods:
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.sdk.trace.export.SpanExporter.SpanExportingExceptionHandler;
// Create an exporter
SpanExporter exporter = OtlpGrpcSpanExporter.newBuilder().build();
// Create a tracer provider and register the exporter
SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
.addSpanProcessor(
SimpleSpanProcessor.newBuilder(exporter).build(),
SpanExportingExceptionHandler.logging())
.build();
// Disable the exporter
tracerProvider.shutdown();
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-26 04:44:16 +0000
Seen: 1 times
Last updated: May 26
How can a list be sorted alphabetically within a console application?
What is a more effective method for substituting a value in the query string of a specific URL?
What is the method to retrieve the JSON data from a column in SQL?
What is the accurate method for sinking to BigQuery by utilizing Dataflow Apache Beam?
How can set the Project Title in the Doxygen Configuration File?
How can I convert Double to Long in Java?
Can I add a default Parameter for a Method in Java like int calculate(int x, int y=2)?