Skip to content

Provide a public property to get SpanProcessor's SpanExporter #4616

Closed
@dimaqq

Description

@dimaqq

Is your feature request related to a problem?

#4580 has effectively removed a public field span_exporter from BatchSpanProcessor.

Let's leave aside the possible debate if this constitutes a breaking change in the public API.

I'm currently working around this like so:

    # opentelemetry-sdk < 1.34.0
    with contextlib.suppress(AttributeError):
        exporter = get_tracer_provider()._active_span_processor.span_exporter  # type: ignore

    # opentelemetry-sdk >= 1.34.0
    with contextlib.suppress(AttributeError):
        exporter = get_tracer_provider()._active_span_processor._batch_processor._exporter  # type: ignore

Source: canonical/operator#1791

Describe the solution you'd like

class BatchSpanProcessor(SpanProcessor):
    ...
    @property
    def span_exporter(self):
        return self._batch_processor._exporter

Arguably BatchProcessor should also have a public attribute or accessor, but I'm happy to leave that decision to the maintainers.

Describe alternatives you've considered

A high level API to find my custom Exporter starting from get_tracer_provider().
That would be a larger change.

Additional Context

No response

Would you like to implement a fix?

Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions