Skip to content

Commit 1387d00

Browse files
Merge branch 'master' into fix/openai-choices-none
2 parents 2f14008 + 575edf9 commit 1387d00

42 files changed

Lines changed: 903 additions & 706 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

sentry_sdk/_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def enabled(option: str) -> bool:
5454
except Exception:
5555
pass
5656

57-
return value and str(value).lower() not in FALSE_VALUES
57+
return value and str(value).lower() not in FALSE_VALUES # type: ignore[return-value]
5858

5959
# When `threads` is passed in as a uwsgi option,
6060
# `enable-threads` is implied on.

sentry_sdk/_span_batcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ def _to_transport_format(item: "StreamedSpan") -> "Any":
168168
"start_timestamp": item._start_timestamp.timestamp(),
169169
}
170170

171-
if item._timestamp:
172-
res["end_timestamp"] = item._timestamp.timestamp()
171+
if item._end_timestamp:
172+
res["end_timestamp"] = item._end_timestamp.timestamp()
173173

174174
if item._parent_span_id:
175175
res["parent_span_id"] = item._parent_span_id

sentry_sdk/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ def capture_event(
864864
865865
:returns: An event ID. May be `None` if there is no DSN set or of if the SDK decided to discard the event for other reasons. In such situations setting `debug=True` on `init()` may help.
866866
"""
867-
hint: "Hint" = dict(hint or ())
867+
hint = dict(hint or ())
868868

869869
if not self._should_capture(event, hint, scope):
870870
return None
@@ -948,7 +948,7 @@ def _capture_telemetry(
948948
if ty == "log":
949949
before_send = get_before_send_log(self.options)
950950
elif ty == "metric":
951-
before_send = get_before_send_metric(self.options) # type: ignore
951+
before_send = get_before_send_metric(self.options)
952952

953953
if before_send is not None:
954954
telemetry = before_send(telemetry, {}) # type: ignore
@@ -960,9 +960,9 @@ def _capture_telemetry(
960960
if ty == "log":
961961
batcher = self.log_batcher
962962
elif ty == "metric":
963-
batcher = self.metrics_batcher # type: ignore
963+
batcher = self.metrics_batcher
964964
elif ty == "span":
965-
batcher = self.span_batcher # type: ignore
965+
batcher = self.span_batcher
966966

967967
if batcher is not None:
968968
batcher.add(telemetry) # type: ignore

sentry_sdk/crons/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def _create_check_in_event(
1818
monitor_config: "Optional[MonitorConfig]" = None,
1919
) -> "Event":
2020
options = sentry_sdk.get_client().options
21-
check_in_id: str = check_in_id or uuid.uuid4().hex
21+
check_in_id = check_in_id or uuid.uuid4().hex
2222

2323
check_in: "Event" = {
2424
"type": "check_in",

sentry_sdk/feature_flags.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sentry_sdk
33
from sentry_sdk._lru_cache import LRUCache
44
from sentry_sdk.tracing import Span
5+
from sentry_sdk.tracing_utils import has_span_streaming_enabled
56
from threading import Lock
67

78
from typing import TYPE_CHECKING, Any
@@ -58,9 +59,17 @@ def add_feature_flag(flag: str, result: bool) -> None:
5859
Records a flag and its value to be sent on subsequent error events.
5960
We recommend you do this on flag evaluations. Flags are buffered per Sentry scope.
6061
"""
62+
client = sentry_sdk.get_client()
63+
6164
flags = sentry_sdk.get_isolation_scope().flags
6265
flags.set(flag, result)
6366

64-
span = sentry_sdk.get_current_span()
65-
if span and isinstance(span, Span):
66-
span.set_flag(f"flag.evaluation.{flag}", result)
67+
if has_span_streaming_enabled(client.options):
68+
span = sentry_sdk.traces._get_current_streamed_span()
69+
if span and isinstance(span, sentry_sdk.traces.StreamedSpan):
70+
span.set_attribute(f"flag.evaluation.{flag}", result)
71+
72+
else:
73+
span = sentry_sdk.get_current_span()
74+
if span and isinstance(span, Span):
75+
span.set_flag(f"flag.evaluation.{flag}", result)

sentry_sdk/hub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def __init__(
146146
scope = get_isolation_scope().fork()
147147
current_scope = get_current_scope().fork()
148148
else:
149-
client = client_or_hub # type: ignore
149+
client = client_or_hub
150150
get_global_scope().set_client(client)
151151

152152
if scope is None: # so there is no Hub cloning going on

sentry_sdk/integrations/_wsgi_common.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
try:
1111
from django.http.request import RawPostDataException
12+
13+
_RAW_DATA_EXCEPTIONS = (RawPostDataException, ValueError)
1214
except ImportError:
1315
RawPostDataException = None
16+
_RAW_DATA_EXCEPTIONS = (ValueError,)
1417

1518
from typing import TYPE_CHECKING
1619

@@ -110,7 +113,7 @@ def extract_into_event(self, event: "Event") -> None:
110113
raw_data = None
111114
try:
112115
raw_data = self.raw_data()
113-
except (RawPostDataException, ValueError):
116+
except _RAW_DATA_EXCEPTIONS:
114117
# If DjangoRestFramework is used it already read the body for us
115118
# so reading it here will fail. We can ignore this.
116119
pass
@@ -175,7 +178,7 @@ def json(self) -> "Optional[Any]":
175178

176179
try:
177180
raw_data = self.raw_data()
178-
except (RawPostDataException, ValueError):
181+
except _RAW_DATA_EXCEPTIONS:
179182
# The body might have already been read, in which case this will
180183
# fail
181184
raw_data = None

sentry_sdk/integrations/aiohttp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ async def sentry_app_handle(
184184
**client_address_attributes,
185185
**header_attributes,
186186
},
187+
parent_span=None,
187188
)
188189
else:
189190
transaction = continue_trace(

sentry_sdk/integrations/asgi.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ async def _run_app(
263263

264264
attributes["sentry.op"] = f"{ty}.server"
265265
segment = sentry_sdk.traces.start_span(
266-
name=transaction_name, attributes=attributes
266+
name=transaction_name,
267+
attributes=attributes,
268+
parent_span=None,
267269
)
268270
else:
269271
sentry_sdk.traces.new_trace()
@@ -274,7 +276,9 @@ async def _run_app(
274276

275277
attributes["sentry.op"] = OP.HTTP_SERVER
276278
segment = sentry_sdk.traces.start_span(
277-
name=transaction_name, attributes=attributes
279+
name=transaction_name,
280+
attributes=attributes,
281+
parent_span=None,
278282
)
279283

280284
span_ctx = segment or nullcontext()

sentry_sdk/integrations/cloud_resource_context.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def _get_gcp_context(cls) -> "Dict[str, str]":
176176
"cloud.platform": CLOUD_PLATFORM.GCP_COMPUTE_ENGINE,
177177
}
178178

179+
gcp_metadata = cls.gcp_metadata
179180
try:
180181
if cls.gcp_metadata is None:
181182
r = cls.http.request(
@@ -187,30 +188,29 @@ def _get_gcp_context(cls) -> "Dict[str, str]":
187188
if r.status != 200:
188189
return ctx
189190

190-
cls.gcp_metadata = json.loads(r.data.decode("utf-8"))
191+
gcp_metadata = json.loads(r.data.decode("utf-8"))
192+
cls.gcp_metadata = gcp_metadata
191193

192194
try:
193-
ctx["cloud.account.id"] = cls.gcp_metadata["project"]["projectId"]
195+
ctx["cloud.account.id"] = gcp_metadata["project"]["projectId"]
194196
except Exception:
195197
pass
196198

197199
try:
198-
ctx["cloud.availability_zone"] = cls.gcp_metadata["instance"][
199-
"zone"
200-
].split("/")[-1]
200+
ctx["cloud.availability_zone"] = gcp_metadata["instance"]["zone"].split(
201+
"/"
202+
)[-1]
201203
except Exception:
202204
pass
203205

204206
try:
205207
# only populated in google cloud run
206-
ctx["cloud.region"] = cls.gcp_metadata["instance"]["region"].split("/")[
207-
-1
208-
]
208+
ctx["cloud.region"] = gcp_metadata["instance"]["region"].split("/")[-1]
209209
except Exception:
210210
pass
211211

212212
try:
213-
ctx["host.id"] = cls.gcp_metadata["instance"]["id"]
213+
ctx["host.id"] = gcp_metadata["instance"]["id"]
214214
except Exception:
215215
pass
216216

0 commit comments

Comments
 (0)