Skip to content

Commit 5f4116a

Browse files
krnrYuri Lobanoff
authored andcommitted
{method} only if 404
1 parent b304292 commit 5f4116a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,15 @@ def get_default_span_name(request: web.Request) -> str:
247247
path = request.path.strip()
248248
try:
249249
resource = request.match_info.route.resource
250-
if resource:
251-
path = resource.canonical
252-
except AttributeError:
253-
pass
254-
return f"{request.method} {path}"
250+
assert resource
251+
path = resource.canonical
252+
except (AttributeError, AssertionError):
253+
path = ""
254+
255+
if path:
256+
return f"{request.method} {path}"
257+
else:
258+
return f"{request.method}"
255259

256260

257261
def _get_view_func(request: web.Request) -> str:

instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ async def test_status_code_instrumentation(
197197
"/object/234/action/baz",
198198
),
199199
),
200+
(
201+
"GET",
202+
(
203+
"/i/dont/exist",
204+
"/me-neither",
205+
),
206+
),
200207
],
201208
)
202209
async def test_url_params_instrumentation(

0 commit comments

Comments
 (0)