Skip to content

Commit f534a22

Browse files
committed
Merge branch 'potel-base' into ivana/potel/start-span
2 parents 8993799 + de1b0e3 commit f534a22

23 files changed

+280
-128
lines changed

.tool-versions

-1
This file was deleted.

CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Changelog
22

3+
## 2.8.0
4+
5+
### Various fixes & improvements
6+
7+
- `profiler_id` uses underscore (#3249) by @Zylphrex
8+
- Don't send full env to subprocess (#3251) by @kmichel-aiven
9+
- Stop using `Hub` in `HttpTransport` (#3247) by @szokeasaurusrex
10+
- Remove `ipdb` from test requirements (#3237) by @rominf
11+
- Avoid propagation of empty baggage (#2968) by @hartungstenio
12+
- Add entry point for `SentryPropagator` (#3086) by @mender
13+
- Bump checkouts/data-schemas from `8c13457` to `88273a9` (#3225) by @dependabot
14+
15+
## 2.7.1
16+
17+
### Various fixes & improvements
18+
19+
- fix(otel): Fix missing baggage (#3218) by @sentrivana
20+
- This is the config file of asdf-vm which we do not use. (#3215) by @antonpirker
21+
- Added option to disable middleware spans in Starlette (#3052) by @antonpirker
22+
- build: Update tornado version in setup.py to match code check. (#3206) by @aclemons
23+
324
## 2.7.0
425

526
- Add `origin` to spans and transactions (#3133) by @antonpirker

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
copyright = "2019-{}, Sentry Team and Contributors".format(datetime.now().year)
2929
author = "Sentry Team and Contributors"
3030

31-
release = "2.7.0"
31+
release = "2.8.0"
3232
version = ".".join(release.split(".")[:2]) # The short X.Y version.
3333

3434

requirements-testing.txt

-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ executing
1010
asttokens
1111
responses
1212
pysocks
13-
ipdb
1413
setuptools

sentry_sdk/consts.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ class SPANDATA:
379379
Example: "MainThread"
380380
"""
381381

382-
PROFILER_ID = "profiler.id"
382+
PROFILER_ID = "profiler_id"
383383
"""
384384
Label identifying the profiler id that the span occurred in. This should be a string.
385385
Example: "5249fbada8d5416482c2f6e47e337372"
@@ -529,4 +529,4 @@ def _get_default_options():
529529
del _get_default_options
530530

531531

532-
VERSION = "2.7.0"
532+
VERSION = "2.8.0"

sentry_sdk/integrations/opentelemetry/propagator.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,23 @@
1717
SpanContext,
1818
TraceFlags,
1919
)
20+
21+
from sentry_sdk._types import TYPE_CHECKING
2022
from sentry_sdk.integrations.opentelemetry.consts import (
2123
SENTRY_BAGGAGE_KEY,
2224
SENTRY_TRACE_KEY,
2325
)
2426
from sentry_sdk.integrations.opentelemetry.span_processor import (
2527
SentrySpanProcessor,
2628
)
27-
2829
from sentry_sdk.tracing import (
2930
BAGGAGE_HEADER_NAME,
3031
SENTRY_TRACE_HEADER_NAME,
3132
)
3233
from sentry_sdk.tracing_utils import Baggage, extract_sentrytrace_data
33-
from sentry_sdk._types import TYPE_CHECKING
3434

3535
if TYPE_CHECKING:
36-
from typing import Optional
37-
from typing import Set
36+
from typing import Optional, Set
3837

3938

4039
class SentryPropagator(TextMapPropagator):
@@ -107,7 +106,9 @@ def inject(self, carrier, context=None, setter=default_setter):
107106
if sentry_span.containing_transaction:
108107
baggage = sentry_span.containing_transaction.get_baggage()
109108
if baggage:
110-
setter.set(carrier, BAGGAGE_HEADER_NAME, baggage.serialize())
109+
baggage_data = baggage.serialize()
110+
if baggage_data:
111+
setter.set(carrier, BAGGAGE_HEADER_NAME, baggage_data)
111112

112113
@property
113114
def fields(self):

sentry_sdk/integrations/opentelemetry/span_processor.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import cast
44

55
from opentelemetry.context import get_value
6-
from opentelemetry.sdk.trace import SpanProcessor, Span as OTelSpan
6+
from opentelemetry.sdk.trace import SpanProcessor, ReadableSpan as OTelSpan
77
from opentelemetry.trace import (
88
format_span_id,
99
format_trace_id,
@@ -253,17 +253,14 @@ def _get_trace_data(self, otel_span, parent_context):
253253
)
254254
trace_data["parent_span_id"] = parent_span_id
255255

256-
if parent_context is not None:
257-
sentry_trace_data = get_value(SENTRY_TRACE_KEY, parent_context)
258-
sentry_trace_data = cast(
259-
"dict[str, Union[str, bool, None]]", sentry_trace_data
260-
)
261-
trace_data["parent_sampled"] = (
262-
sentry_trace_data["parent_sampled"] if sentry_trace_data else None
263-
)
256+
sentry_trace_data = get_value(SENTRY_TRACE_KEY, parent_context)
257+
sentry_trace_data = cast("dict[str, Union[str, bool, None]]", sentry_trace_data)
258+
trace_data["parent_sampled"] = (
259+
sentry_trace_data["parent_sampled"] if sentry_trace_data else None
260+
)
264261

265-
baggage = get_value(SENTRY_BAGGAGE_KEY, parent_context)
266-
trace_data["baggage"] = baggage
262+
baggage = get_value(SENTRY_BAGGAGE_KEY, parent_context)
263+
trace_data["baggage"] = baggage
267264

268265
return trace_data
269266

sentry_sdk/integrations/stdlib.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ def sentry_patched_popen_init(self, *a, **kw):
207207
):
208208
if env is None:
209209
env = _init_argument(
210-
a, kw, "env", 10, lambda x: dict(x or os.environ)
210+
a,
211+
kw,
212+
"env",
213+
10,
214+
lambda x: dict(x if x is not None else os.environ),
211215
)
212216
env["SUBPROCESS_" + k.upper().replace("-", "_")] = v
213217

sentry_sdk/tracing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class TransactionKwargs(SpanKwargs, total=False):
118118
ProfileContext = TypedDict(
119119
"ProfileContext",
120120
{
121-
"profiler.id": str,
121+
"profiler_id": str,
122122
},
123123
)
124124

@@ -698,7 +698,7 @@ def get_profile_context(self):
698698
return None
699699

700700
return {
701-
"profiler.id": profiler_id,
701+
"profiler_id": profiler_id,
702702
}
703703

704704

sentry_sdk/transport.py

+36-18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import urllib3
1313
import certifi
1414

15+
import sentry_sdk
1516
from sentry_sdk.consts import EndpointType
1617
from sentry_sdk.utils import Dsn, logger, capture_internal_exceptions
1718
from sentry_sdk.worker import BackgroundWorker
@@ -33,10 +34,7 @@
3334
from urllib3.poolmanager import PoolManager
3435
from urllib3.poolmanager import ProxyManager
3536

36-
from sentry_sdk._types import Event
37-
38-
DataCategory = Optional[str]
39-
37+
from sentry_sdk._types import Event, EventDataCategory
4038

4139
KEEP_ALIVE_SOCKET_OPTIONS = []
4240
for option in [
@@ -133,7 +131,7 @@ def kill(self):
133131
def record_lost_event(
134132
self,
135133
reason, # type: str
136-
data_category=None, # type: Optional[str]
134+
data_category=None, # type: Optional[EventDataCategory]
137135
item=None, # type: Optional[Item]
138136
):
139137
# type: (...) -> None
@@ -155,7 +153,7 @@ def __del__(self):
155153

156154

157155
def _parse_rate_limits(header, now=None):
158-
# type: (Any, Optional[datetime]) -> Iterable[Tuple[DataCategory, datetime]]
156+
# type: (Any, Optional[datetime]) -> Iterable[Tuple[Optional[EventDataCategory], datetime]]
159157
if now is None:
160158
now = datetime.now(timezone.utc)
161159

@@ -195,11 +193,11 @@ def __init__(
195193
self.options = options # type: Dict[str, Any]
196194
self._worker = BackgroundWorker(queue_size=options["transport_queue_size"])
197195
self._auth = self.parsed_dsn.to_auth("sentry.python/%s" % VERSION)
198-
self._disabled_until = {} # type: Dict[DataCategory, datetime]
196+
self._disabled_until = {} # type: Dict[Optional[EventDataCategory], datetime]
199197
self._retry = urllib3.util.Retry()
200198
self._discarded_events = defaultdict(
201199
int
202-
) # type: DefaultDict[Tuple[str, str], int]
200+
) # type: DefaultDict[Tuple[EventDataCategory, str], int]
203201
self._last_client_report_sent = time.time()
204202

205203
compresslevel = options.get("_experiments", {}).get(
@@ -218,14 +216,13 @@ def __init__(
218216
proxy_headers=options["proxy_headers"],
219217
)
220218

221-
from sentry_sdk import Hub
222-
223-
self.hub_cls = Hub
219+
# Backwards compatibility for deprecated `self.hub_class` attribute
220+
self._hub_cls = sentry_sdk.Hub
224221

225222
def record_lost_event(
226223
self,
227224
reason, # type: str
228-
data_category=None, # type: Optional[str]
225+
data_category=None, # type: Optional[EventDataCategory]
229226
item=None, # type: Optional[Item]
230227
):
231228
# type: (...) -> None
@@ -548,14 +545,11 @@ def capture_envelope(
548545
self, envelope # type: Envelope
549546
):
550547
# type: (...) -> None
551-
hub = self.hub_cls.current
552-
553548
def send_envelope_wrapper():
554549
# type: () -> None
555-
with hub:
556-
with capture_internal_exceptions():
557-
self._send_envelope(envelope)
558-
self._flush_client_reports()
550+
with capture_internal_exceptions():
551+
self._send_envelope(envelope)
552+
self._flush_client_reports()
559553

560554
if not self._worker.submit(send_envelope_wrapper):
561555
self.on_dropped_event("full_queue")
@@ -579,6 +573,30 @@ def kill(self):
579573
logger.debug("Killing HTTP transport")
580574
self._worker.kill()
581575

576+
@staticmethod
577+
def _warn_hub_cls():
578+
# type: () -> None
579+
"""Convenience method to warn users about the deprecation of the `hub_cls` attribute."""
580+
warnings.warn(
581+
"The `hub_cls` attribute is deprecated and will be removed in a future release.",
582+
DeprecationWarning,
583+
stacklevel=3,
584+
)
585+
586+
@property
587+
def hub_cls(self):
588+
# type: () -> type[sentry_sdk.Hub]
589+
"""DEPRECATED: This attribute is deprecated and will be removed in a future release."""
590+
HttpTransport._warn_hub_cls()
591+
return self._hub_cls
592+
593+
@hub_cls.setter
594+
def hub_cls(self, value):
595+
# type: (type[sentry_sdk.Hub]) -> None
596+
"""DEPRECATED: This attribute is deprecated and will be removed in a future release."""
597+
HttpTransport._warn_hub_cls()
598+
self._hub_cls = value
599+
582600

583601
class _FunctionTransport(Transport):
584602
"""

sentry_sdk/types.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
from typing import TYPE_CHECKING
1212

1313
if TYPE_CHECKING:
14-
from sentry_sdk._types import Event, Hint
14+
from sentry_sdk._types import Event, EventDataCategory, Hint
1515
else:
1616
from typing import Any
1717

1818
# The lines below allow the types to be imported from outside `if TYPE_CHECKING`
1919
# guards. The types in this module are only intended to be used for type hints.
2020
Event = Any
21+
EventDataCategory = Any
2122
Hint = Any
2223

23-
__all__ = ("Event", "Hint")
24+
__all__ = ("Event", "EventDataCategory", "Hint")

setup.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_file_text(file_name):
2121

2222
setup(
2323
name="sentry-sdk",
24-
version="2.7.0",
24+
version="2.8.0",
2525
author="Sentry Team and Contributors",
2626
author_email="[email protected]",
2727
url="https://github.com/getsentry/sentry-python",
@@ -132,6 +132,11 @@ def get_file_text(file_name):
132132
"starlite": ["starlite>=1.48"],
133133
"tornado": ["tornado>=6"],
134134
},
135+
entry_points={
136+
"opentelemetry_propagator": [
137+
"sentry=sentry_sdk.integrations.opentelemetry:SentryPropagator"
138+
]
139+
},
135140
classifiers=[
136141
"Development Status :: 5 - Production/Stable",
137142
"Environment :: Web Environment",

tests/conftest.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,18 @@ def append_envelope(envelope):
248248

249249

250250
@pytest.fixture
251-
def capture_client_reports(monkeypatch):
251+
def capture_record_lost_event_calls(monkeypatch):
252252
def inner():
253-
reports = []
254-
test_client = sentry_sdk.Hub.current.client
253+
calls = []
254+
test_client = sentry_sdk.get_client()
255255

256256
def record_lost_event(reason, data_category=None, item=None):
257-
if data_category is None:
258-
data_category = item.data_category
259-
return reports.append((reason, data_category))
257+
calls.append((reason, data_category, item))
260258

261259
monkeypatch.setattr(
262260
test_client.transport, "record_lost_event", record_lost_event
263261
)
264-
return reports
262+
return calls
265263

266264
return inner
267265

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import importlib
2+
import os
3+
from unittest.mock import patch
4+
5+
from opentelemetry import propagate
6+
from sentry_sdk.integrations.opentelemetry import SentryPropagator
7+
8+
9+
def test_propagator_loaded_if_mentioned_in_environment_variable():
10+
try:
11+
with patch.dict(os.environ, {"OTEL_PROPAGATORS": "sentry"}):
12+
importlib.reload(propagate)
13+
14+
assert len(propagate.propagators) == 1
15+
assert isinstance(propagate.propagators[0], SentryPropagator)
16+
finally:
17+
importlib.reload(propagate)

0 commit comments

Comments
 (0)