|
1 | 1 | import os |
2 | | -import datetime |
3 | 2 | import asyncio |
4 | 3 | from unittest import mock |
5 | 4 |
|
6 | 5 | import httpx |
7 | 6 | import pytest |
8 | | -from contextlib import contextmanager |
9 | 7 |
|
10 | 8 | import sentry_sdk |
11 | 9 | from sentry_sdk import capture_message, start_transaction |
@@ -604,31 +602,19 @@ def test_no_request_source_if_duration_too_short_legacy( |
604 | 602 | integrations=[HttpxIntegration()], |
605 | 603 | traces_sample_rate=1.0, |
606 | 604 | enable_http_request_source=True, |
607 | | - http_request_source_threshold_ms=100, |
| 605 | + # Threshold so high no real request will ever exceed it |
| 606 | + http_request_source_threshold_ms=9999999, |
608 | 607 | ) |
609 | 608 |
|
610 | 609 | events = capture_events() |
611 | 610 |
|
612 | 611 | url = "http://example.com/" |
613 | 612 |
|
614 | 613 | with start_transaction(name="test_transaction"): |
615 | | - |
616 | | - @contextmanager |
617 | | - def fake_start_span(*args, **kwargs): |
618 | | - with sentry_sdk.start_span(*args, **kwargs) as span: |
619 | | - pass |
620 | | - span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0) |
621 | | - span.timestamp = datetime.datetime(2024, 1, 1, microsecond=99999) |
622 | | - yield span |
623 | | - |
624 | | - with mock.patch( |
625 | | - "sentry_sdk.integrations.httpx.legacy_start_span", |
626 | | - fake_start_span, |
627 | | - ): |
628 | | - if asyncio.iscoroutinefunction(httpx_client.get): |
629 | | - asyncio.get_event_loop().run_until_complete(httpx_client.get(url)) |
630 | | - else: |
631 | | - httpx_client.get(url) |
| 614 | + if asyncio.iscoroutinefunction(httpx_client.get): |
| 615 | + asyncio.get_event_loop().run_until_complete(httpx_client.get(url)) |
| 616 | + else: |
| 617 | + httpx_client.get(url) |
632 | 618 |
|
633 | 619 | (event,) = events |
634 | 620 |
|
@@ -656,31 +642,19 @@ def test_request_source_if_duration_over_threshold_legacy( |
656 | 642 | integrations=[HttpxIntegration()], |
657 | 643 | traces_sample_rate=1.0, |
658 | 644 | enable_http_request_source=True, |
659 | | - http_request_source_threshold_ms=100, |
| 645 | + # Threshold is low so any request will exceed it |
| 646 | + http_request_source_threshold_ms=0, |
660 | 647 | ) |
661 | 648 |
|
662 | 649 | events = capture_events() |
663 | 650 |
|
664 | 651 | url = "http://example.com/" |
665 | 652 |
|
666 | 653 | with start_transaction(name="test_transaction"): |
667 | | - |
668 | | - @contextmanager |
669 | | - def fake_start_span(*args, **kwargs): |
670 | | - with sentry_sdk.start_span(*args, **kwargs) as span: |
671 | | - pass |
672 | | - span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0) |
673 | | - span.timestamp = datetime.datetime(2024, 1, 1, microsecond=100001) |
674 | | - yield span |
675 | | - |
676 | | - with mock.patch( |
677 | | - "sentry_sdk.integrations.httpx.legacy_start_span", |
678 | | - fake_start_span, |
679 | | - ): |
680 | | - if asyncio.iscoroutinefunction(httpx_client.get): |
681 | | - asyncio.get_event_loop().run_until_complete(httpx_client.get(url)) |
682 | | - else: |
683 | | - httpx_client.get(url) |
| 654 | + if asyncio.iscoroutinefunction(httpx_client.get): |
| 655 | + asyncio.get_event_loop().run_until_complete(httpx_client.get(url)) |
| 656 | + else: |
| 657 | + httpx_client.get(url) |
684 | 658 |
|
685 | 659 | (event,) = events |
686 | 660 |
|
|
0 commit comments