File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed
Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change 1- import json
21import threading
3- import math
42from collections import defaultdict
53from datetime import datetime , timezone
64from typing import TYPE_CHECKING
@@ -118,7 +116,9 @@ def _flush(self) -> None:
118116
119117 # Max per envelope is 1000, so if we happen to have more than
120118 # 1000 spans in one bucket, we'll need to separate them.
121- for i in range (math .ceil (len (spans ) / self .MAX_ENVELOPE_SIZE )):
119+ for start in range (0 , len (spans ), self .MAX_ENVELOPE_SIZE ):
120+ end = min (start + self .MAX_ENVELOPE_SIZE , len (spans ))
121+
122122 envelope = Envelope (
123123 headers = {
124124 "sent_at" : format_timestamp (datetime .now (timezone .utc )),
@@ -131,16 +131,13 @@ def _flush(self) -> None:
131131 type = "span" ,
132132 content_type = "application/vnd.sentry.items.span.v2+json" ,
133133 headers = {
134- "item_count" : len ( spans ) ,
134+ "item_count" : end - start ,
135135 },
136136 payload = PayloadRef (
137137 json = {
138138 "items" : [
139- self ._to_transport_format (span )
140- for span in spans [
141- i * self .MAX_ENVELOPE_SIZE : (i + 1 )
142- * self .MAX_ENVELOPE_SIZE
143- ]
139+ self ._to_transport_format (spans [j ])
140+ for j in range (start , end )
144141 ]
145142 }
146143 ),
You can’t perform that action at this time.
0 commit comments