Skip to content

Commit 9c24bd9

Browse files
committed
Merge branch 'master' into ep/pydantic-ai-support-base64-images-in-url-46s
2 parents 6347fc7 + adcd90c commit 9c24bd9

24 files changed

Lines changed: 2494 additions & 1383 deletions

.github/workflows/ai-integration-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
token: ${{ secrets.GITHUB_TOKEN }}
3535

3636
- name: Run Python SDK Tests
37-
uses: getsentry/testing-ai-sdk-integrations@121da677853244cedfe11e95184b2b431af102eb
37+
uses: getsentry/testing-ai-sdk-integrations@285c012e522f241581534dfc89bd99ec3b1da4f6
3838
env:
3939
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4040
with:

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches:
66
- master
77
- release/**
8-
- potel-base
98

109
pull_request:
1110

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ on:
1515
push:
1616
branches:
1717
- master
18-
- potel-base
1918
pull_request:
2019
schedule:
2120
- cron: '18 18 * * 3'

.github/workflows/enforce-license-compliance.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
- master
77
- main
88
- release/*
9-
- potel-base
109
pull_request:
1110

1211
# Cancel in progress workflows on pull_requests.

scripts/build_aws_lambda_layer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LayerBuilder:
1818
def __init__(
1919
self,
2020
base_dir: str,
21-
out_zip_filename: "Optional[str]"=None,
21+
out_zip_filename: "Optional[str]" = None,
2222
) -> None:
2323
self.base_dir = base_dir
2424
self.python_site_packages = os.path.join(self.base_dir, PYTHON_SITE_PACKAGES)

scripts/populate_tox/package_dependencies.jsonl

Lines changed: 17 additions & 16 deletions
Large diffs are not rendered by default.

scripts/populate_tox/populate_tox.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
See scripts/populate_tox/README.md for more info.
55
"""
66

7+
import re
78
import functools
89
import hashlib
910
import json
@@ -872,7 +873,10 @@ def get_last_updated() -> Optional[datetime]:
872873

873874

874875
def _normalize_name(package: str) -> str:
875-
return package.lower().replace("-", "_")
876+
# From https://peps.python.org/pep-0503/#normalized-names
877+
# but normalizing to underscores instead of hyphens since tox-formatted packages
878+
# use underscores.
879+
return re.sub(r"[-_.]+", "_", package).lower()
876880

877881

878882
def _extract_wheel_info_to_cache(wheel: dict):

scripts/populate_tox/releases.jsonl

Lines changed: 44 additions & 43 deletions
Large diffs are not rendered by default.

sentry_sdk/_span_batcher.py

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515

1616

1717
class SpanBatcher(Batcher["StreamedSpan"]):
18-
# TODO[span-first]: size-based flushes
19-
# TODO[span-first]: adjust flush/drop defaults
18+
# MAX_BEFORE_FLUSH should be lower than MAX_BEFORE_DROP, so that there is
19+
# a bit of a buffer for spans that appear between setting the flush event
20+
# and actually flushing the buffer.
21+
#
22+
# The max limits are all per trace.
23+
MAX_ENVELOPE_SIZE = 1000 # spans
2024
MAX_BEFORE_FLUSH = 1000
21-
MAX_BEFORE_DROP = 5000
25+
MAX_BEFORE_DROP = 2000
26+
MAX_BYTES_BEFORE_FLUSH = 5 * 1024 * 1024 # 5 MB
2227
FLUSH_WAIT_TIME = 5.0
2328

2429
TYPE = "span"
@@ -35,6 +40,7 @@ def __init__(
3540
# envelope.
3641
# trace_id -> span buffer
3742
self._span_buffer: dict[str, list["StreamedSpan"]] = defaultdict(list)
43+
self._running_size: dict[str, int] = defaultdict(lambda: 0)
3844
self._capture_func = capture_func
3945
self._record_lost_func = record_lost_func
4046
self._running = True
@@ -45,16 +51,12 @@ def __init__(
4551
self._flusher: "Optional[threading.Thread]" = None
4652
self._flusher_pid: "Optional[int]" = None
4753

48-
def get_size(self) -> int:
49-
# caller is responsible for locking before checking this
50-
return sum(len(buffer) for buffer in self._span_buffer.values())
51-
5254
def add(self, span: "StreamedSpan") -> None:
5355
if not self._ensure_thread() or self._flusher is None:
5456
return None
5557

5658
with self._lock:
57-
size = self.get_size()
59+
size = len(self._span_buffer[span.trace_id])
5860
if size >= self.MAX_BEFORE_DROP:
5961
self._record_lost_func(
6062
reason="queue_overflow",
@@ -64,18 +66,40 @@ def add(self, span: "StreamedSpan") -> None:
6466
return None
6567

6668
self._span_buffer[span.trace_id].append(span)
69+
self._running_size[span.trace_id] += self._estimate_size(span)
70+
6771
if size + 1 >= self.MAX_BEFORE_FLUSH:
6872
self._flush_event.set()
73+
return
74+
75+
if self._running_size[span.trace_id] >= self.MAX_BYTES_BEFORE_FLUSH:
76+
self._flush_event.set()
77+
return
78+
79+
@staticmethod
80+
def _estimate_size(item: "StreamedSpan") -> int:
81+
# Rough estimate of serialized span size that's quick to compute.
82+
# 210 is the rough size of the payload without attributes, and we
83+
# estimate additional 70 bytes on top of that per attribute.
84+
return 210 + 70 * len(item._attributes)
6985

7086
@staticmethod
7187
def _to_transport_format(item: "StreamedSpan") -> "Any":
7288
# TODO[span-first]
7389
res: "dict[str, Any]" = {
90+
"trace_id": item.trace_id,
7491
"span_id": item.span_id,
7592
"name": item._name,
7693
"status": item._status,
94+
"start_timestamp": item._start_timestamp.timestamp(),
7795
}
7896

97+
if item._timestamp:
98+
res["end_timestamp"] = item._timestamp.timestamp()
99+
100+
if item._parent_span_id:
101+
res["parent_span_id"] = item._parent_span_id
102+
79103
if item._attributes:
80104
res["attributes"] = {
81105
k: serialize_attribute(v) for (k, v) in item._attributes.items()
@@ -86,7 +110,7 @@ def _to_transport_format(item: "StreamedSpan") -> "Any":
86110
def _flush(self) -> None:
87111
with self._lock:
88112
if len(self._span_buffer) == 0:
89-
return None
113+
return
90114

91115
envelopes = []
92116
for trace_id, spans in self._span_buffer.items():
@@ -95,34 +119,40 @@ def _flush(self) -> None:
95119
# dsc = spans[0].dynamic_sampling_context()
96120
dsc = None
97121

98-
envelope = Envelope(
99-
headers={
100-
"sent_at": format_timestamp(datetime.now(timezone.utc)),
101-
"trace": dsc,
102-
}
103-
)
104-
105-
envelope.add_item(
106-
Item(
107-
type="span",
108-
content_type="application/vnd.sentry.items.span.v2+json",
122+
# Max per envelope is 1000, so if we happen to have more than
123+
# 1000 spans in one bucket, we'll need to separate them.
124+
for start in range(0, len(spans), self.MAX_ENVELOPE_SIZE):
125+
end = min(start + self.MAX_ENVELOPE_SIZE, len(spans))
126+
127+
envelope = Envelope(
109128
headers={
110-
"item_count": len(spans),
111-
},
112-
payload=PayloadRef(
113-
json={
114-
"items": [
115-
self._to_transport_format(span)
116-
for span in spans
117-
]
118-
}
119-
),
129+
"sent_at": format_timestamp(datetime.now(timezone.utc)),
130+
"trace": dsc,
131+
}
132+
)
133+
134+
envelope.add_item(
135+
Item(
136+
type=self.TYPE,
137+
content_type=self.CONTENT_TYPE,
138+
headers={
139+
"item_count": end - start,
140+
},
141+
payload=PayloadRef(
142+
json={
143+
"items": [
144+
self._to_transport_format(spans[j])
145+
for j in range(start, end)
146+
]
147+
}
148+
),
149+
)
120150
)
121-
)
122151

123-
envelopes.append(envelope)
152+
envelopes.append(envelope)
124153

125154
self._span_buffer.clear()
155+
self._running_size.clear()
126156

127157
for envelope in envelopes:
128158
self._capture_func(envelope)

sentry_sdk/_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ class SDKInfo(TypedDict):
351351
"max_runtime": int,
352352
"failure_issue_threshold": int,
353353
"recovery_threshold": int,
354+
"owner": str,
354355
},
355356
total=False,
356357
)

0 commit comments

Comments
 (0)