Exclude send/receive spans (#698)

This commit is contained in:
Sterling Dreyer 2025-11-25 14:38:16 -08:00 committed by GitHub
parent 0af13aeab5
commit 6d8d71b9ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 14 deletions

View file

@ -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)

View file

@ -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"}

View file

@ -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")