Skip to content

Commit 7376a7f

Browse files
authored
Merge branch 'potel-base' into ivana/potel/custom-sampling-context-rq
2 parents 8a9da80 + aa9c5ca commit 7376a7f

File tree

5 files changed

+43
-80
lines changed

5 files changed

+43
-80
lines changed

sentry_sdk/_init_implementation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import warnings
2-
31
from typing import TYPE_CHECKING
42

53
import sentry_sdk

sentry_sdk/integrations/aiohttp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def _prepopulate_attributes(request):
390390
attributes["server.address"] = request.host
391391

392392
try:
393-
url = f"{request.scheme}://{request.host}{request.path}"
393+
url = f"{request.scheme}://{request.host}{request.path}" # noqa: E231
394394
if request.query_string:
395395
attributes["url.full"] = f"{url}?{request.query_string}"
396396
except Exception:

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,18 @@ def __eq__(self, other):
642642

643643
def __ne__(self, other):
644644
return not self.__eq__(other)
645+
646+
647+
@pytest.fixture(name="SortedBaggage")
648+
def sorted_baggage_matcher():
649+
class SortedBaggage:
650+
def __init__(self, baggage):
651+
self.baggage = baggage
652+
653+
def __eq__(self, other):
654+
return sorted(self.baggage.split(",")) == sorted(other.split(","))
655+
656+
def __ne__(self, other):
657+
return not self.__eq__(other)
658+
659+
return SortedBaggage

tests/test_api.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from unittest import mock
33

4-
import sentry_sdk
54
from sentry_sdk import (
65
capture_exception,
76
continue_trace,
@@ -10,7 +9,7 @@
109
get_current_span,
1110
get_traceparent,
1211
is_initialized,
13-
start_transaction,
12+
start_span,
1413
set_tags,
1514
get_global_scope,
1615
get_current_scope,
@@ -44,23 +43,23 @@ def test_get_current_span_current_scope(sentry_init):
4443

4544

4645
@pytest.mark.forked
47-
def test_get_current_span_current_scope_with_transaction(sentry_init):
46+
def test_get_current_span_current_scope_with_span(sentry_init):
4847
sentry_init()
4948

5049
assert get_current_span() is None
5150

52-
with start_transaction() as new_transaction:
53-
assert get_current_span() == new_transaction
51+
with start_span() as new_span:
52+
assert get_current_span() == new_span
5453

5554

5655
@pytest.mark.forked
5756
def test_traceparent_with_tracing_enabled(sentry_init):
5857
sentry_init(traces_sample_rate=1.0)
5958

60-
with start_transaction() as transaction:
59+
with start_span() as span:
6160
expected_traceparent = "%s-%s-1" % (
62-
transaction.trace_id,
63-
transaction.span_id,
61+
span.trace_id,
62+
span.span_id,
6463
)
6564
assert get_traceparent() == expected_traceparent
6665

@@ -78,51 +77,51 @@ def test_traceparent_with_tracing_disabled(sentry_init):
7877

7978

8079
@pytest.mark.forked
81-
def test_baggage_with_tracing_disabled(sentry_init):
80+
def test_baggage_with_tracing_disabled(sentry_init, SortedBaggage):
8281
sentry_init(release="1.0.0", environment="dev")
8382
propagation_context = get_isolation_scope()._propagation_context
8483
expected_baggage = (
8584
"sentry-trace_id={},sentry-environment=dev,sentry-release=1.0.0".format(
8685
propagation_context.trace_id
8786
)
8887
)
89-
assert get_baggage() == expected_baggage
88+
assert get_baggage() == SortedBaggage(expected_baggage)
9089

9190

9291
@pytest.mark.forked
93-
def test_baggage_with_tracing_enabled(sentry_init):
92+
def test_baggage_with_tracing_enabled(sentry_init, SortedBaggage):
9493
sentry_init(traces_sample_rate=1.0, release="1.0.0", environment="dev")
95-
with start_transaction() as transaction:
94+
with start_span() as span:
9695
expected_baggage = "sentry-trace_id={},sentry-environment=dev,sentry-release=1.0.0,sentry-sample_rate=1.0,sentry-sampled={}".format(
97-
transaction.trace_id, "true" if transaction.sampled else "false"
96+
span.trace_id, "true" if span.sampled else "false"
9897
)
99-
assert get_baggage() == expected_baggage
98+
assert get_baggage() == SortedBaggage(expected_baggage)
10099

101100

102101
@pytest.mark.forked
103102
def test_continue_trace(sentry_init):
104-
sentry_init()
103+
sentry_init(traces_sample_rate=1.0)
105104

106105
trace_id = "471a43a4192642f0b136d5159a501701"
107106
parent_span_id = "6e8f22c393e68f19"
108107
parent_sampled = 1
109-
transaction = continue_trace(
108+
109+
with continue_trace(
110110
{
111111
"sentry-trace": "{}-{}-{}".format(trace_id, parent_span_id, parent_sampled),
112112
"baggage": "sentry-trace_id=566e3688a61d4bc888951642d6f14a19",
113113
},
114-
name="some name",
115-
)
116-
with start_transaction(transaction):
117-
assert transaction.name == "some name"
118-
119-
propagation_context = get_isolation_scope()._propagation_context
120-
assert propagation_context.trace_id == transaction.trace_id == trace_id
121-
assert propagation_context.parent_span_id == parent_span_id
122-
assert propagation_context.parent_sampled == parent_sampled
123-
assert propagation_context.dynamic_sampling_context == {
124-
"trace_id": "566e3688a61d4bc888951642d6f14a19"
125-
}
114+
):
115+
with start_span(name="some name") as span:
116+
assert span.name == "some name"
117+
118+
propagation_context = get_isolation_scope()._propagation_context
119+
assert propagation_context.trace_id == span.trace_id == trace_id
120+
assert propagation_context.parent_span_id == parent_span_id
121+
assert propagation_context.parent_sampled == parent_sampled
122+
assert propagation_context.dynamic_sampling_context == {
123+
"trace_id": "566e3688a61d4bc888951642d6f14a19"
124+
}
126125

127126

128127
@pytest.mark.forked

tests/test_utils.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -60,55 +60,6 @@ def _normalize_distribution_name(name):
6060
return re.sub(r"[-_.]+", "-", name).lower()
6161

6262

63-
@pytest.mark.parametrize(
64-
("input_str", "expected_output"),
65-
(
66-
(
67-
"2021-01-01T00:00:00.000000Z",
68-
datetime(2021, 1, 1, tzinfo=timezone.utc),
69-
), # UTC time
70-
(
71-
"2021-01-01T00:00:00.000000",
72-
datetime(2021, 1, 1).astimezone(timezone.utc),
73-
), # No TZ -- assume local but convert to UTC
74-
(
75-
"2021-01-01T00:00:00Z",
76-
datetime(2021, 1, 1, tzinfo=timezone.utc),
77-
), # UTC - No milliseconds
78-
(
79-
"2021-01-01T00:00:00.000000+00:00",
80-
datetime(2021, 1, 1, tzinfo=timezone.utc),
81-
),
82-
(
83-
"2021-01-01T00:00:00.000000-00:00",
84-
datetime(2021, 1, 1, tzinfo=timezone.utc),
85-
),
86-
(
87-
"2021-01-01T00:00:00.000000+0000",
88-
datetime(2021, 1, 1, tzinfo=timezone.utc),
89-
),
90-
(
91-
"2021-01-01T00:00:00.000000-0000",
92-
datetime(2021, 1, 1, tzinfo=timezone.utc),
93-
),
94-
(
95-
"2020-12-31T00:00:00.000000+02:00",
96-
datetime(2020, 12, 31, tzinfo=timezone(timedelta(hours=2))),
97-
), # UTC+2 time
98-
(
99-
"2020-12-31T00:00:00.000000-0200",
100-
datetime(2020, 12, 31, tzinfo=timezone(timedelta(hours=-2))),
101-
), # UTC-2 time
102-
(
103-
"2020-12-31T00:00:00-0200",
104-
datetime(2020, 12, 31, tzinfo=timezone(timedelta(hours=-2))),
105-
), # UTC-2 time - no milliseconds
106-
),
107-
)
108-
def test_datetime_from_isoformat(input_str, expected_output):
109-
assert datetime_from_isoformat(input_str) == expected_output, input_str
110-
111-
11263
@pytest.mark.parametrize(
11364
"env_var_value,strict,expected",
11465
[

0 commit comments

Comments
 (0)