diff --git a/CHANGELOG.md b/CHANGELOG.md index 71f13b05a67..d5dcce26b98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - opentelemetry-sdk: Fix invalid `type: ignore` that causes mypy to ignore the whole file ([#4618](https://github.com/open-telemetry/opentelemetry-python/pull/4618)) +- Add `span_exporter` property back to `BatchSpanProcessor` class + ([#4621](https://github.com/open-telemetry/opentelemetry-python/pull/4621)) ## Version 1.34.0/0.55b0 (2025-06-04) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index 3520c6a9f6a..9e7557b05af 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -177,6 +177,11 @@ def __init__( "Span", ) + # Added for backward compatibility. Not recommended to directly access/use underlying exporter. + @property + def span_exporter(self): + return self._batch_processor._exporter # pylint: disable=protected-access + def on_start( self, span: Span, parent_context: Context | None = None ) -> None: diff --git a/opentelemetry-sdk/tests/trace/export/test_export.py b/opentelemetry-sdk/tests/trace/export/test_export.py index e94c3e67680..1e08d4411c2 100644 --- a/opentelemetry-sdk/tests/trace/export/test_export.py +++ b/opentelemetry-sdk/tests/trace/export/test_export.py @@ -150,6 +150,11 @@ def test_simple_span_processor_not_sampled(self): # before the end of the test, otherwise the worker thread will continue # to run after the end of the test. class TestBatchSpanProcessor(unittest.TestCase): + def test_get_span_exporter(self): + exporter = MySpanExporter(destination=[]) + batch_span_processor = export.BatchSpanProcessor(exporter) + self.assertEqual(exporter, batch_span_processor.span_exporter) + @mock.patch.dict( "os.environ", {