Skip to content

fix excluded_urls in instrumentation-asgi #3567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed

- `opentelemetry-instrumentation-asgi`: fix excluded_urls in instrumentation-asgi
([#3567](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3567))

## Version 1.34.0/0.55b0 (2025-06-04)

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,13 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS,
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST,
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE,
ExcludeList,
SanitizeValue,
_parse_url_query,
get_custom_headers,
normalise_request_header_name,
normalise_response_header_name,
parse_excluded_urls,
remove_url_credentials,
sanitize_method,
)
Expand Down Expand Up @@ -537,7 +539,7 @@ class OpenTelemetryMiddleware:
def __init__(
self,
app,
excluded_urls=None,
excluded_urls: ExcludeList | str | None = None,
default_span_details=None,
server_request_hook: ServerRequestHook = None,
client_request_hook: ClientRequestHook = None,
Expand Down Expand Up @@ -619,6 +621,8 @@ def __init__(
self.active_requests_counter = create_http_server_active_requests(
self.meter
)
if isinstance(excluded_urls, str):
excluded_urls = parse_excluded_urls(excluded_urls)
self.excluded_urls = excluded_urls
self.default_span_details = (
default_span_details or get_default_span_details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,29 @@ async def test_no_metric_for_websockets(self):
await self.get_all_output()
self.assertIsNone(self.memory_metrics_reader.get_metrics_data())

async def test_excluded_urls(self):
self.scope["path"] = "/test_excluded_urls"
app = otel_asgi.OpenTelemetryMiddleware(
simple_asgi, excluded_urls="test_excluded_urls"
)
self.seed_app(app)
await self.send_default_request()
await self.get_all_output()
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 0)

async def test_no_excluded_urls(self):
self.scope["path"] = "/test_excluded_urls"
app = otel_asgi.OpenTelemetryMiddleware(
simple_asgi, excluded_urls="test_excluded_urls"
)
self.seed_app(app)
self.scope["path"] = "/test_no_excluded_urls"
await self.send_default_request()
await self.get_all_output()
spans = self.memory_exporter.get_finished_spans()
self.assertGreater(len(spans), 0)


class TestAsgiAttributes(unittest.TestCase):
def setUp(self):
Expand Down