Skip to content

Commit 0185d60

Browse files
author
Carlos Rodríguez
committed
fix excluded_urls in instrumentation-asgi
1 parent 59cc34e commit 0185d60

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
259259
get_custom_headers,
260260
normalise_request_header_name,
261261
normalise_response_header_name,
262+
parse_excluded_urls,
262263
remove_url_credentials,
263264
sanitize_method,
264265
)
@@ -619,6 +620,8 @@ def __init__(
619620
self.active_requests_counter = create_http_server_active_requests(
620621
self.meter
621622
)
623+
if excluded_urls is not None:
624+
excluded_urls = parse_excluded_urls(excluded_urls)
622625
self.excluded_urls = excluded_urls
623626
self.default_span_details = (
624627
default_span_details or get_default_span_details

instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,29 @@ async def test_no_metric_for_websockets(self):
16331633
await self.get_all_output()
16341634
self.assertIsNone(self.memory_metrics_reader.get_metrics_data())
16351635

1636+
async def test_excluded_urls(self):
1637+
self.scope["path"] = "/test_excluded_urls"
1638+
app = otel_asgi.OpenTelemetryMiddleware(
1639+
simple_asgi, excluded_urls="test_excluded_urls"
1640+
)
1641+
self.seed_app(app)
1642+
await self.send_default_request()
1643+
await self.get_all_output()
1644+
spans = self.memory_exporter.get_finished_spans()
1645+
self.assertEqual(len(spans), 0)
1646+
1647+
async def test_no_excluded_urls(self):
1648+
self.scope["path"] = "/test_excluded_urls"
1649+
app = otel_asgi.OpenTelemetryMiddleware(
1650+
simple_asgi, excluded_urls="test_excluded_urls"
1651+
)
1652+
self.seed_app(app)
1653+
self.scope["path"] = "/test_no_excluded_urls"
1654+
await self.send_default_request()
1655+
await self.get_all_output()
1656+
spans = self.memory_exporter.get_finished_spans()
1657+
self.assertGreater(len(spans), 0)
1658+
16361659

16371660
class TestAsgiAttributes(unittest.TestCase):
16381661
def setUp(self):

0 commit comments

Comments
 (0)