trodo-python 3.0.2__py3-none-any.whl → 3.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- trodo/__init__.py +1 -1
- trodo/_version.py +1 -1
- trodo/delivery/sender.py +56 -14
- {trodo_python-3.0.2.dist-info → trodo_python-3.0.4.dist-info}/METADATA +1 -1
- {trodo_python-3.0.2.dist-info → trodo_python-3.0.4.dist-info}/RECORD +7 -7
- {trodo_python-3.0.2.dist-info → trodo_python-3.0.4.dist-info}/WHEEL +0 -0
- {trodo_python-3.0.2.dist-info → trodo_python-3.0.4.dist-info}/top_level.txt +0 -0
trodo/__init__.py
CHANGED
|
@@ -180,7 +180,7 @@ def init(
|
|
|
180
180
|
are present, otherwise 'background'. Default.
|
|
181
181
|
``delivery_options``: flush_interval_s (1), flush_at (50), max_batch_bytes
|
|
182
182
|
(4 MB), max_queue_items (10,000), max_queue_bytes (64 MB), max_retry_s
|
|
183
|
-
(600), exit_flush_s (5).
|
|
183
|
+
(600), exit_flush_s (5), max_in_flight (3).
|
|
184
184
|
|
|
185
185
|
``disable_instrumentations`` turns OFF specific instrumentors by id
|
|
186
186
|
(e.g. ``['openai']`` when LangChain is your primary framework, to avoid
|
trodo/_version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
SDK_VERSION = "3.0.
|
|
1
|
+
SDK_VERSION = "3.0.4"
|
trodo/delivery/sender.py
CHANGED
|
@@ -5,8 +5,12 @@ retry and Retry-After — on the caller's thread before handing the agent's
|
|
|
5
5
|
result back: up to ~90 s added to one agent call when a team was over its
|
|
6
6
|
rate ceiling, the event loop frozen in an asyncio app, and then the trace was
|
|
7
7
|
dropped. Now a finished run (or a flush of spans) goes into this queue and
|
|
8
|
-
the agent returns at once.
|
|
9
|
-
``POST /api/sdk/batch`` every second or 50 items, gzipped
|
|
8
|
+
the agent returns at once. Daemon threads drain the queue to
|
|
9
|
+
``POST /api/sdk/batch`` every second or 50 items, gzipped, up to
|
|
10
|
+
``max_in_flight`` (3) requests at a time (3.0.3; one at a time before, which
|
|
11
|
+
let a script that exits after a burst deliver only ~150 runs in its 5 s exit
|
|
12
|
+
window). Feedback never travels while its run is in flight in another
|
|
13
|
+
request: the server refuses feedback for a run it has not stored yet.
|
|
10
14
|
|
|
11
15
|
The rules match what Langfuse, LangSmith, Braintrust, OpenTelemetry, Sentry
|
|
12
16
|
and PostHog have converged on (1 Oct 2026 survey):
|
|
@@ -23,7 +27,11 @@ and PostHog have converged on (1 Oct 2026 survey):
|
|
|
23
27
|
oversized item is dropped as ``too_large``; any other 4xx is a bad item:
|
|
24
28
|
dropped as ``rejected``, reported once.
|
|
25
29
|
- exit: ``atexit`` flushes (bounded by ``exit_flush_s``) and says on stderr
|
|
26
|
-
how many traces were still undelivered, and why, if any were.
|
|
30
|
+
how many traces were still undelivered, and why, if any were. Requests
|
|
31
|
+
sent while exiting (or in ``shutdown``) are marked ``exiting`` (3.0.4):
|
|
32
|
+
Trodo takes the whole batch into its backlog at once instead of storing
|
|
33
|
+
each trace while the request waits, so a short script hands over
|
|
34
|
+
hundreds of traces in its last seconds.
|
|
27
35
|
- the server holds over-rate items itself (202 ``queued``) and stores them
|
|
28
36
|
at the team's rate; the sender says so on stderr once per 10 minutes.
|
|
29
37
|
- ``immediate`` mode for platforms that freeze between requests (Lambda,
|
|
@@ -53,7 +61,7 @@ DEFAULTS = dict(
|
|
|
53
61
|
flush_interval_s=1.0, flush_at=50, max_batch_bytes=4 * 1024 * 1024,
|
|
54
62
|
max_queue_items=10_000, max_queue_bytes=64 * 1024 * 1024,
|
|
55
63
|
max_retry_s=600.0, max_retry_after_s=600.0, immediate_retry_s=15.0,
|
|
56
|
-
exit_flush_s=5.0, request_timeout_s=20.0,
|
|
64
|
+
exit_flush_s=5.0, request_timeout_s=20.0, max_in_flight=3,
|
|
57
65
|
)
|
|
58
66
|
_MIN_BACKOFF_S = 1.0
|
|
59
67
|
_MAX_BACKOFF_S = 60.0
|
|
@@ -133,7 +141,9 @@ class Sender:
|
|
|
133
141
|
self._unit_cap: Optional[int] = None # the team's ceiling, once a 429 names it
|
|
134
142
|
self._last_rate: Optional[Dict[str, Any]] = None
|
|
135
143
|
self._warned_paced_at = 0.0
|
|
136
|
-
self.
|
|
144
|
+
self._exiting = False # set by the exit flush and shutdown: the server holds the batch
|
|
145
|
+
self._threads: List[threading.Thread] = []
|
|
146
|
+
self._runs_in_flight: Dict[str, int] = {} # run_id -> requests carrying it
|
|
137
147
|
if self.mode == "background" and register_atexit:
|
|
138
148
|
atexit.register(self._atexit)
|
|
139
149
|
|
|
@@ -179,6 +189,7 @@ class Sender:
|
|
|
179
189
|
self._flush_requested = False
|
|
180
190
|
|
|
181
191
|
def shutdown(self, timeout_s: Optional[float] = None) -> None:
|
|
192
|
+
self._exiting = True
|
|
182
193
|
self.flush(self._o["exit_flush_s"] if timeout_s is None else timeout_s)
|
|
183
194
|
with self._lock:
|
|
184
195
|
self._stopped = True
|
|
@@ -203,9 +214,11 @@ class Sender:
|
|
|
203
214
|
# ── background thread ─────────────────────────────────────────────────────
|
|
204
215
|
|
|
205
216
|
def _ensure_thread_locked(self) -> None:
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
self.
|
|
217
|
+
self._threads = [t for t in self._threads if t.is_alive()]
|
|
218
|
+
while len(self._threads) < max(1, int(self._o["max_in_flight"])):
|
|
219
|
+
t = threading.Thread(target=self._run, name=f"trodo-sender-{len(self._threads) + 1}", daemon=True)
|
|
220
|
+
self._threads.append(t)
|
|
221
|
+
t.start()
|
|
209
222
|
|
|
210
223
|
def _run(self) -> None:
|
|
211
224
|
interval = self._o["flush_interval_s"]
|
|
@@ -229,12 +242,25 @@ class Sender:
|
|
|
229
242
|
break
|
|
230
243
|
self._wake.wait(timeout=interval - age)
|
|
231
244
|
batch = self._take_batch_locked()
|
|
245
|
+
if not batch:
|
|
246
|
+
# The head is feedback whose run is in flight: wait for it.
|
|
247
|
+
self._wake.wait(timeout=interval)
|
|
248
|
+
continue
|
|
249
|
+
runs = _run_ids(batch)
|
|
250
|
+
for r in runs:
|
|
251
|
+
self._runs_in_flight[r] = self._runs_in_flight.get(r, 0) + 1
|
|
232
252
|
self._in_flight += 1
|
|
233
253
|
try:
|
|
234
254
|
self._send_batch(batch)
|
|
235
255
|
finally:
|
|
236
256
|
with self._lock:
|
|
237
257
|
self._in_flight -= 1
|
|
258
|
+
for r in runs:
|
|
259
|
+
left = self._runs_in_flight.get(r, 1) - 1
|
|
260
|
+
if left > 0:
|
|
261
|
+
self._runs_in_flight[r] = left
|
|
262
|
+
else:
|
|
263
|
+
self._runs_in_flight.pop(r, None)
|
|
238
264
|
self._wake.notify_all()
|
|
239
265
|
|
|
240
266
|
def _take_batch_locked(self) -> List[_Queued]:
|
|
@@ -249,6 +275,9 @@ class Sender:
|
|
|
249
275
|
u = _units_of(nxt.item)
|
|
250
276
|
if out and cap and units + u > cap:
|
|
251
277
|
break
|
|
278
|
+
fb = nxt.item.get("run_id") if isinstance(nxt.item, dict) and "feedback" in nxt.item else None
|
|
279
|
+
if fb and fb in self._runs_in_flight:
|
|
280
|
+
break
|
|
252
281
|
out.append(self._queue.popleft())
|
|
253
282
|
nbytes += nxt.nbytes
|
|
254
283
|
units += u
|
|
@@ -315,8 +344,8 @@ class Sender:
|
|
|
315
344
|
first_error = first_error or f"HTTP {st}: {r.get('error', '')}"
|
|
316
345
|
if rejected:
|
|
317
346
|
self._drop(rejected, "rejected", f"{rejected} item(s) rejected by the server ({first_error})")
|
|
318
|
-
if queued:
|
|
319
|
-
self._warn_paced(body
|
|
347
|
+
if queued and isinstance(body.get("paced"), dict): # held for rate, not an exit hand-off
|
|
348
|
+
self._warn_paced(body["paced"])
|
|
320
349
|
ra = body.get("retry_after_ms")
|
|
321
350
|
if ra:
|
|
322
351
|
self._pause(float(ra) / 1000.0)
|
|
@@ -447,11 +476,13 @@ class Sender:
|
|
|
447
476
|
self._drop(n, "queue_full", f"the delivery queue is full ({self._o['max_queue_items']} items / {self._o['max_queue_bytes'] // 1048576} MB); the {n} oldest were dropped")
|
|
448
477
|
|
|
449
478
|
def _envelope(self, batch: List[_Queued]) -> Dict[str, Any]:
|
|
450
|
-
|
|
479
|
+
env: Dict[str, Any] = {"items": [q.item for q in batch]}
|
|
480
|
+
if self._exiting:
|
|
481
|
+
env["exiting"] = True
|
|
451
482
|
with self._lock:
|
|
452
|
-
if
|
|
453
|
-
|
|
454
|
-
|
|
483
|
+
if self._unreported["count"]:
|
|
484
|
+
env["dropped"] = {"count": self._unreported["count"], "by_reason": dict(self._unreported["by_reason"])}
|
|
485
|
+
return env
|
|
455
486
|
|
|
456
487
|
def _reported(self) -> None:
|
|
457
488
|
with self._lock:
|
|
@@ -538,6 +569,7 @@ class Sender:
|
|
|
538
569
|
self._sleep(wait)
|
|
539
570
|
|
|
540
571
|
def _atexit(self) -> None:
|
|
572
|
+
self._exiting = True
|
|
541
573
|
try:
|
|
542
574
|
self.flush(self._o["exit_flush_s"])
|
|
543
575
|
except Exception:
|
|
@@ -580,6 +612,16 @@ def _legacy_route(item: Item):
|
|
|
580
612
|
return endpoints.SPANS_APPEND, {"spans": item["spans"]}
|
|
581
613
|
|
|
582
614
|
|
|
615
|
+
def _run_ids(batch: List[_Queued]) -> List[str]:
|
|
616
|
+
"""The runs a request carries (the ``run`` items), so their feedback waits for them."""
|
|
617
|
+
out = []
|
|
618
|
+
for q in batch:
|
|
619
|
+
run = q.item.get("run") if isinstance(q.item, dict) else None
|
|
620
|
+
if isinstance(run, dict) and run.get("run_id"):
|
|
621
|
+
out.append(str(run["run_id"]))
|
|
622
|
+
return out
|
|
623
|
+
|
|
624
|
+
|
|
583
625
|
def _units_of(item: Any) -> int:
|
|
584
626
|
"""What an item costs against the rate ceiling: one per span, one for the run."""
|
|
585
627
|
if not isinstance(item, dict):
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
trodo/__init__.py,sha256=
|
|
2
|
-
trodo/_version.py,sha256=
|
|
1
|
+
trodo/__init__.py,sha256=b6NdLadR5zQ_wPNLhHXFGLJgoDNNeaI9iNpeSoG9sdw,27118
|
|
2
|
+
trodo/_version.py,sha256=y0TahmkeA2lcQvDmzzINYsMfnygwWPlG5FpphC5u4sc,22
|
|
3
3
|
trodo/client.py,sha256=eaZtHMtOI-VLgfoqM_KVWMuP_I5Ivs7VFnR0oU96Yqk,23743
|
|
4
4
|
trodo/types.py,sha256=eySgUvCXROG2TxtxgiU0MNr5iH0DEcduK8bmYtTKG44,3138
|
|
5
5
|
trodo/user_context.py,sha256=uHCI2WYoOI3cNwdIUEuZdX4VYSu14pzm348ksn6hn_c,8195
|
|
@@ -12,7 +12,7 @@ trodo/api/management.py,sha256=uwhr0ZI1pvguz5-itW1KcgRj0TXM2n4KDa-hGIaBdTA,4023
|
|
|
12
12
|
trodo/auto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
trodo/auto/auto_event_manager.py,sha256=cztuRsRkNoJE5R4NfSfTrTJTGl4jx2Yb-Ncy0aVAPo8,4247
|
|
14
14
|
trodo/delivery/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
trodo/delivery/sender.py,sha256=
|
|
15
|
+
trodo/delivery/sender.py,sha256=H57Yi7rZBq8mC85P0nAFR0Pk7ebjSG67ktoChNC0HEg,28304
|
|
16
16
|
trodo/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
17
|
trodo/managers/dataset_manager.py,sha256=HTFszK-wKmwjW-aw7xJWr5EKvDpJ_om496MLDr3gelg,13920
|
|
18
18
|
trodo/managers/group_manager.py,sha256=ki3Se3qEoSZfREX63oeDeBmEfZF-ISHLE8azEtLg0tM,3542
|
|
@@ -40,7 +40,7 @@ trodo/session/server_session.py,sha256=McsudEiq33XDq3nqxgzBcUvIjQxCMscwEuAPnYXrT
|
|
|
40
40
|
trodo/session/session_manager.py,sha256=7ht5LeeZX1HLLfPeNV_a8NkXGbHl3up0CRtCGr3EzjQ,2995
|
|
41
41
|
trodo/util/__init__.py,sha256=Z9c4rPPdKg06Kk3byKheDqksSgR4WNvS475oQ5sNljc,54
|
|
42
42
|
trodo/util/lru.py,sha256=QIsM7s6J_E9ZjiXatSyReZIEeGypTAcgrPWWy8YsRa4,2465
|
|
43
|
-
trodo_python-3.0.
|
|
44
|
-
trodo_python-3.0.
|
|
45
|
-
trodo_python-3.0.
|
|
46
|
-
trodo_python-3.0.
|
|
43
|
+
trodo_python-3.0.4.dist-info/METADATA,sha256=NKqJ4bcclLdVo-9rehbHYr2jdpzJWaiKK-VxUv8QR0s,25307
|
|
44
|
+
trodo_python-3.0.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
45
|
+
trodo_python-3.0.4.dist-info/top_level.txt,sha256=VCQu1CJWFmNsqTs1YxMcw4Mq35Tc3z3uI9RwHEXAayQ,6
|
|
46
|
+
trodo_python-3.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|