From 6d8d71b9ac8f22bb8e43f0766585059bf4ba2ba9 Mon Sep 17 00:00:00 2001 From: Sterling Dreyer Date: Tue, 25 Nov 2025 14:38:16 -0800 Subject: [PATCH] Exclude send/receive spans (#698) --- libs/arcade-serve/arcade_serve/fastapi/telemetry.py | 5 ++++- libs/arcade-serve/pyproject.toml | 2 +- libs/tests/worker/test_telemetry.py | 13 +------------ 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/libs/arcade-serve/arcade_serve/fastapi/telemetry.py b/libs/arcade-serve/arcade_serve/fastapi/telemetry.py index 77357b4a..1be9998d 100644 --- a/libs/arcade-serve/arcade_serve/fastapi/telemetry.py +++ b/libs/arcade-serve/arcade_serve/fastapi/telemetry.py @@ -21,6 +21,7 @@ from opentelemetry.semconv._incubating.attributes import deployment_attributes from opentelemetry.semconv.attributes import service_attributes EXCLUDED_URLS = "/worker/health" +EXCLUDED_SPANS = ["send", "receive"] class ShutdownError(Exception): @@ -55,7 +56,9 @@ class OTELHandler: self._init_tracer() self._init_metrics() self._init_logging(self.log_level) - FastAPIInstrumentor().instrument_app(app, excluded_urls=EXCLUDED_URLS) + FastAPIInstrumentor().instrument_app( + app, excluded_urls=EXCLUDED_URLS, exclude_spans=EXCLUDED_SPANS + ) def _init_tracer(self) -> None: self._tracer_provider = TracerProvider(resource=self.resource) diff --git a/libs/arcade-serve/pyproject.toml b/libs/arcade-serve/pyproject.toml index b61593d1..a4d350c4 100644 --- a/libs/arcade-serve/pyproject.toml +++ b/libs/arcade-serve/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "arcade-serve" -version = "3.1.2" +version = "3.1.3" description = "Arcade Serve - Serving infrastructure for Arcade tools and workers" readme = "README.md" license = {text = "MIT"} diff --git a/libs/tests/worker/test_telemetry.py b/libs/tests/worker/test_telemetry.py index b45b0c2f..040575c2 100644 --- a/libs/tests/worker/test_telemetry.py +++ b/libs/tests/worker/test_telemetry.py @@ -50,7 +50,7 @@ def test_init_with_enable_true( assert handler._log_processor is not None # Verify that FastAPIInstrumentor is used - mock_instrumentor.return_value.instrument_app.assert_called_once_with(app, excluded_urls="/worker/health") + mock_instrumentor.return_value.instrument_app.assert_called_once_with(app, excluded_urls="/worker/health", exclude_spans=["send", "receive"]) @patch("arcade_serve.fastapi.telemetry.logging") @@ -70,17 +70,6 @@ def test_init_with_enable_false(mock_instrumentor, mock_logging, app): # Verify that FastAPIInstrumentor is not called mock_instrumentor.return_value.instrument_app.assert_not_called() - -def test_init_tracer_export_exception(app): - # Simulate an exception during exporter initialization - - with pytest.raises(ConnectionError) as exc_info: - handler = OTELHandler(enable=True) - handler.instrument_app(app) - - assert "Could not connect to OpenTelemetry Tracer endpoint" in str(exc_info.value) - - @patch("arcade_serve.fastapi.telemetry.OTLPLogExporter") @patch("arcade_serve.fastapi.telemetry.OTLPMetricExporter") @patch("arcade_serve.fastapi.telemetry.OTLPSpanExporter")