diff --git a/tracing/ops_tracing/_backend.py b/tracing/ops_tracing/_backend.py index bc39f048d..70d4efc65 100644 --- a/tracing/ops_tracing/_backend.py +++ b/tracing/ops_tracing/_backend.py @@ -74,13 +74,23 @@ def _create_provider(resource: Resource, charm_dir: pathlib.Path) -> TracerProvi def get_exporter() -> BufferingSpanExporter | None: """Get our export from OpenTelemetry SDK.""" + exporter = None + + # opentelemetry-sdk < 1.34.0 try: exporter = get_tracer_provider()._active_span_processor.span_exporter # type: ignore except AttributeError: - # The global tracer provider was not configured by us and has a wrong processor. - return None + pass + + # opentelemetry-sdk >= 1.34.0 + try: + exporter = get_tracer_provider()._active_span_processor._batch_processor._exporter # type: ignore + except AttributeError: + pass + if not exporter or not isinstance(exporter, BufferingSpanExporter): return None + return exporter diff --git a/tracing/pyproject.toml b/tracing/pyproject.toml index cb4b46ad8..84adf638b 100644 --- a/tracing/pyproject.toml +++ b/tracing/pyproject.toml @@ -104,6 +104,8 @@ ignore = [ "D213", # we don't add a blank line after Args: in a function docstring "D413", + # Use contextlib.suppress() instead of try/except: pass + "SIM105", ] [tool.ruff.lint.per-file-ignores]