From c0e8bf98769c6b6655a83feb348e98c68a5af99a Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 26 Jan 2022 16:40:20 +0200 Subject: [PATCH] Add the AsyncSpanExporter interface. This will allow us to define asynchronous span exporters, if the span processor will be async as well. --- .../sdk/trace/export/__init__.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index d40bb4968c0..ea30d5361f4 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -75,6 +75,34 @@ def shutdown(self) -> None: """ +class AsyncSpanExporter: + """Interface for exporting spans asynchronously. + + Interface to be implemented by services that want to export spans recorded + in their own format. + + To export data this MUST be registered to the :class`opentelemetry.sdk.trace.Tracer` using a + `SimpleSpanProcessor` or a `BatchSpanProcessor`. + """ + + async def export( + self, spans: typing.Sequence[ReadableSpan] + ) -> "SpanExportResult": + """Exports a batch of telemetry data asynchronously. + + Args: + spans: The list of `opentelemetry.trace.Span` objects to be exported + + Returns: + The result of the export + """ + + async def shutdown(self) -> None: + """Shuts down the exporter asynchronously. + + Called when the SDK is shut down. + """ + class SimpleSpanProcessor(SpanProcessor): """Simple SpanProcessor implementation.