@@ -249,6 +249,30 @@ async def test_url_params_instrumentation(
249249 assert full_url == span .attributes [HTTP_URL ]
250250
251251
252+ @pytest .mark .asyncio
253+ async def test_span_name_handler_unknown_method (
254+ tracer ,
255+ server_fixture ,
256+ ):
257+ _ , memory_exporter = tracer
258+ server , _ = server_fixture
259+
260+ assert len (memory_exporter .get_finished_spans ()) == 0
261+
262+ async with aiohttp .ClientSession (
263+ base_url = f"http://{ server .host } :{ server .port } "
264+ ) as session :
265+ # PURGE is accepted by aiohttp but not recognized by sanitize_method.
266+ async with session .request ("PURGE" , "/test-path" ) as response :
267+ assert response .status == HTTPStatus .METHOD_NOT_ALLOWED
268+
269+ spans = memory_exporter .get_finished_spans ()
270+ assert len (spans ) == 1
271+
272+ assert "_OTHER" == spans [0 ].attributes [HTTP_METHOD ]
273+ assert "HTTP" == spans [0 ].name
274+
275+
252276@pytest .mark .asyncio
253277@pytest .mark .parametrize ("suppress" , [True ])
254278async def test_suppress_instrumentation (
@@ -563,11 +587,11 @@ async def test_semantic_conventions_metrics_old_default(
563587
564588 AioHttpServerInstrumentor ().instrument ()
565589 app = aiohttp .web .Application ()
566- app .router .add_get ("/test-path" , default_handler )
590+ app .router .add_get ("/test-path/{param} " , default_handler )
567591 server = await aiohttp_server (app )
568592 client_session = aiohttp .ClientSession ()
569593 try :
570- url = f"http://{ server .host } :{ server .port } /test-path?query=test"
594+ url = f"http://{ server .host } :{ server .port } /test-path/test-param ?query=test"
571595 async with client_session .get ( # pylint: disable=not-async-context-manager
572596 url , headers = {"User-Agent" : "test-agent" }
573597 ) as response :
@@ -587,11 +611,14 @@ async def test_semantic_conventions_metrics_old_default(
587611 assert span .attributes .get (HTTP_SCHEME ) == "http"
588612 assert span .attributes .get (NET_HOST_NAME ) == server .host
589613 assert span .attributes .get (NET_HOST_PORT ) == server .port
590- assert span .attributes .get (HTTP_TARGET ) == "/test-path?query=test"
614+ assert (
615+ span .attributes .get (HTTP_TARGET )
616+ == "/test-path/test-param?query=test"
617+ )
591618 assert span .attributes .get (HTTP_USER_AGENT ) == "test-agent"
592619 assert span .attributes .get (HTTP_FLAVOR ) == "1.1"
593620 assert span .attributes .get (HTTP_STATUS_CODE ) == 200
594- assert span .attributes .get (HTTP_ROUTE ) == "default_handler "
621+ assert span .attributes .get (HTTP_ROUTE ) == "/test-path/{param} "
595622 # New semconv span attributes NOT present
596623 assert HTTP_REQUEST_METHOD not in span .attributes
597624 assert URL_SCHEME not in span .attributes
@@ -636,11 +663,11 @@ async def test_semantic_conventions_metrics_new(
636663
637664 AioHttpServerInstrumentor ().instrument ()
638665 app = aiohttp .web .Application ()
639- app .router .add_get ("/test-path" , default_handler )
666+ app .router .add_get ("/test-path/{param} " , default_handler )
640667 server = await aiohttp_server (app )
641668 client_session = aiohttp .ClientSession ()
642669 try :
643- url = f"http://{ server .host } :{ server .port } /test-path?query=test"
670+ url = f"http://{ server .host } :{ server .port } /test-path/test-param ?query=test"
644671 async with client_session .get ( # pylint: disable=not-async-context-manager
645672 url , headers = {"User-Agent" : "test-agent" }
646673 ) as response :
@@ -660,12 +687,12 @@ async def test_semantic_conventions_metrics_new(
660687 assert span .attributes .get (URL_SCHEME ) == "http"
661688 assert span .attributes .get (SERVER_ADDRESS ) == server .host
662689 assert span .attributes .get (SERVER_PORT ) == server .port
663- assert span .attributes .get (URL_PATH ) == "/test-path"
690+ assert span .attributes .get (URL_PATH ) == "/test-path/test-param "
664691 assert span .attributes .get (URL_QUERY ) == "query=test"
665692 assert span .attributes .get (USER_AGENT_ORIGINAL ) == "test-agent"
666693 assert span .attributes .get (NETWORK_PROTOCOL_VERSION ) == "1.1"
667694 assert span .attributes .get (HTTP_RESPONSE_STATUS_CODE ) == 200
668- assert span .attributes .get (HTTP_ROUTE ) == "default_handler "
695+ assert span .attributes .get (HTTP_ROUTE ) == "/test-path/{param} "
669696 # Old semconv span attributes NOT present
670697 assert HTTP_METHOD not in span .attributes
671698 assert HTTP_SCHEME not in span .attributes
@@ -755,7 +782,7 @@ async def test_semantic_conventions_metrics_both(
755782 assert span .attributes .get (NETWORK_PROTOCOL_VERSION ) == "1.1"
756783 assert span .attributes .get (HTTP_STATUS_CODE ) == 200
757784 assert span .attributes .get (HTTP_RESPONSE_STATUS_CODE ) == 200
758- assert span .attributes .get (HTTP_ROUTE ) == "default_handler "
785+ assert span .attributes .get (HTTP_ROUTE ) == "/test-path "
759786
760787 metrics = test_base .get_sorted_metrics (SCOPE )
761788 assert len (metrics ) == 3 # Both duration metrics + active requests
0 commit comments