|
40 | 40 | from opentelemetry.semconv.attributes.error_attributes import ERROR_TYPE
|
41 | 41 | from opentelemetry.semconv.attributes.http_attributes import (
|
42 | 42 | HTTP_REQUEST_METHOD,
|
| 43 | + HTTP_REQUEST_METHOD_ORIGINAL, |
43 | 44 | HTTP_RESPONSE_STATUS_CODE,
|
44 | 45 | )
|
45 | 46 | from opentelemetry.semconv.attributes.url_attributes import URL_FULL
|
@@ -503,6 +504,92 @@ async def request_handler(request):
|
503 | 504 | ]
|
504 | 505 | )
|
505 | 506 |
|
| 507 | + def test_nonstandard_http_method(self): |
| 508 | + trace_configs = [aiohttp_client.create_trace_config()] |
| 509 | + app = HttpServerMock("nonstandard_method") |
| 510 | + |
| 511 | + @app.route("/status/200", methods=["NONSTANDARD"]) |
| 512 | + def index(): |
| 513 | + return ("", 405, {}) |
| 514 | + |
| 515 | + url = "http://localhost:5000/status/200" |
| 516 | + |
| 517 | + with app.run("localhost", 5000): |
| 518 | + with self.subTest(url=url): |
| 519 | + |
| 520 | + async def do_request(url): |
| 521 | + async with aiohttp.ClientSession( |
| 522 | + trace_configs=trace_configs, |
| 523 | + ) as session: |
| 524 | + async with session.request("NONSTANDARD", url): |
| 525 | + pass |
| 526 | + |
| 527 | + loop = asyncio.get_event_loop() |
| 528 | + loop.run_until_complete(do_request(url)) |
| 529 | + |
| 530 | + self.assert_spans( |
| 531 | + [ |
| 532 | + ( |
| 533 | + "HTTP", |
| 534 | + (StatusCode.ERROR, None), |
| 535 | + { |
| 536 | + SpanAttributes.HTTP_METHOD: "_OTHER", |
| 537 | + SpanAttributes.HTTP_URL: url, |
| 538 | + SpanAttributes.HTTP_STATUS_CODE: int( |
| 539 | + HTTPStatus.METHOD_NOT_ALLOWED |
| 540 | + ), |
| 541 | + }, |
| 542 | + ) |
| 543 | + ] |
| 544 | + ) |
| 545 | + self.memory_exporter.clear() |
| 546 | + |
| 547 | + def test_nonstandard_http_method_new_semconv(self): |
| 548 | + trace_configs = [ |
| 549 | + aiohttp_client.create_trace_config( |
| 550 | + sem_conv_opt_in_mode=_HTTPStabilityMode.HTTP |
| 551 | + ) |
| 552 | + ] |
| 553 | + app = HttpServerMock("nonstandard_method") |
| 554 | + |
| 555 | + @app.route("/status/200", methods=["NONSTANDARD"]) |
| 556 | + def index(): |
| 557 | + return ("", 405, {}) |
| 558 | + |
| 559 | + url = "http://localhost:5000/status/200" |
| 560 | + |
| 561 | + with app.run("localhost", 5000): |
| 562 | + with self.subTest(url=url): |
| 563 | + |
| 564 | + async def do_request(url): |
| 565 | + async with aiohttp.ClientSession( |
| 566 | + trace_configs=trace_configs, |
| 567 | + ) as session: |
| 568 | + async with session.request("NONSTANDARD", url): |
| 569 | + pass |
| 570 | + |
| 571 | + loop = asyncio.get_event_loop() |
| 572 | + loop.run_until_complete(do_request(url)) |
| 573 | + |
| 574 | + self.assert_spans( |
| 575 | + [ |
| 576 | + ( |
| 577 | + "HTTP", |
| 578 | + (StatusCode.ERROR, None), |
| 579 | + { |
| 580 | + HTTP_REQUEST_METHOD: "_OTHER", |
| 581 | + URL_FULL: url, |
| 582 | + HTTP_RESPONSE_STATUS_CODE: int( |
| 583 | + HTTPStatus.METHOD_NOT_ALLOWED |
| 584 | + ), |
| 585 | + HTTP_REQUEST_METHOD_ORIGINAL: "NONSTANDARD", |
| 586 | + ERROR_TYPE: "405", |
| 587 | + }, |
| 588 | + ) |
| 589 | + ] |
| 590 | + ) |
| 591 | + self.memory_exporter.clear() |
| 592 | + |
506 | 593 | def test_credential_removal(self):
|
507 | 594 | trace_configs = [aiohttp_client.create_trace_config()]
|
508 | 595 |
|
|
0 commit comments