trodo-python 3.0.2__tar.gz → 3.0.4__tar.gz

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.
Files changed (74) hide show
  1. {trodo_python-3.0.2 → trodo_python-3.0.4}/PKG-INFO +1 -1
  2. {trodo_python-3.0.2 → trodo_python-3.0.4}/pyproject.toml +1 -1
  3. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_sender.py +88 -0
  4. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/__init__.py +1 -1
  5. trodo_python-3.0.4/trodo/_version.py +1 -0
  6. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/delivery/sender.py +56 -14
  7. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo_python.egg-info/PKG-INFO +1 -1
  8. trodo_python-3.0.2/trodo/_version.py +0 -1
  9. {trodo_python-3.0.2 → trodo_python-3.0.4}/README.md +0 -0
  10. {trodo_python-3.0.2 → trodo_python-3.0.4}/setup.cfg +0 -0
  11. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_anon_distinct_id.py +0 -0
  12. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_auto_instrument_fixes.py +0 -0
  13. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_cross_process_session.py +0 -0
  14. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_datasets.py +0 -0
  15. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_end_run.py +0 -0
  16. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_end_run_order.py +0 -0
  17. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_error_enrichment.py +0 -0
  18. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_framework_deference.py +0 -0
  19. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_get_prompt_version_types.py +0 -0
  20. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_instrumentor_resolution.py +0 -0
  21. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_llm_usage_cost.py +0 -0
  22. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_long_runs.py +0 -0
  23. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_multi_agent_shape.py +0 -0
  24. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_processor_methods.py +0 -0
  25. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_prompt_fingerprint.py +0 -0
  26. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_prompt_trace.py +0 -0
  27. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_prompts.py +0 -0
  28. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_register_otel.py +0 -0
  29. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_start_run.py +0 -0
  30. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_user_traits.py +0 -0
  31. {trodo_python-3.0.2 → trodo_python-3.0.4}/tests/test_wrap_agent_unchanged.py +0 -0
  32. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/api/__init__.py +0 -0
  33. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/api/_retry.py +0 -0
  34. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/api/async_client.py +0 -0
  35. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/api/endpoints.py +0 -0
  36. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/api/http_client.py +0 -0
  37. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/api/management.py +0 -0
  38. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/auto/__init__.py +0 -0
  39. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/auto/auto_event_manager.py +0 -0
  40. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/client.py +0 -0
  41. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/delivery/__init__.py +0 -0
  42. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/managers/__init__.py +0 -0
  43. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/managers/dataset_manager.py +0 -0
  44. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/managers/group_manager.py +0 -0
  45. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/managers/people_manager.py +0 -0
  46. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/managers/prompt_manager.py +0 -0
  47. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/managers/user_manager.py +0 -0
  48. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/otel/__init__.py +0 -0
  49. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/otel/auto_instrument.py +0 -0
  50. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/otel/context.py +0 -0
  51. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/otel/helpers.py +0 -0
  52. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/otel/processor.py +0 -0
  53. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/otel/prompt_trace.py +0 -0
  54. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/otel/register.py +0 -0
  55. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/otel/transport.py +0 -0
  56. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/otel/wrap_agent.py +0 -0
  57. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/prompts/__init__.py +0 -0
  58. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/prompts/compile.py +0 -0
  59. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/prompts/template.py +0 -0
  60. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/prompts/types.py +0 -0
  61. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/queue/__init__.py +0 -0
  62. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/queue/batch_flusher.py +0 -0
  63. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/queue/event_queue.py +0 -0
  64. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/session/__init__.py +0 -0
  65. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/session/server_session.py +0 -0
  66. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/session/session_manager.py +0 -0
  67. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/types.py +0 -0
  68. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/user_context.py +0 -0
  69. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/util/__init__.py +0 -0
  70. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo/util/lru.py +0 -0
  71. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo_python.egg-info/SOURCES.txt +0 -0
  72. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo_python.egg-info/dependency_links.txt +0 -0
  73. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo_python.egg-info/requires.txt +0 -0
  74. {trodo_python-3.0.2 → trodo_python-3.0.4}/trodo_python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trodo-python
3
- Version: 3.0.2
3
+ Version: 3.0.4
4
4
  Summary: Trodo Analytics SDK for Python — server-side event tracking
5
5
  License: ISC
6
6
  Keywords: analytics,tracking,trodo,server-side
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "trodo-python"
7
- version = "3.0.2"
7
+ version = "3.0.4"
8
8
  description = "Trodo Analytics SDK for Python — server-side event tracking"
9
9
  readme = "README.md"
10
10
  license = { text = "ISC" }
@@ -333,3 +333,91 @@ def test_exit_says_loudly_what_was_not_delivered(capsys):
333
333
  err = capsys.readouterr().err
334
334
  assert "1 trace item(s), 2 units, were NOT delivered" in err
335
335
  assert "Trodo said: this team's backlog is full" in err
336
+
337
+
338
+ # ── Parallel requests (3.0.3) ─────────────────────────────────────────────────
339
+
340
+ class Timed:
341
+ """A slow /batch that records when each request started and ended."""
342
+
343
+ def __init__(self, delay_s: float) -> None:
344
+ self.delay_s = delay_s
345
+ self.calls: List[Dict[str, Any]] = []
346
+ self.lock = threading.Lock()
347
+
348
+ def post_raw(self, path, body, timeout=0, gzip_body=True):
349
+ start = time.time()
350
+ time.sleep(self.delay_s)
351
+ with self.lock:
352
+ self.calls.append({"start": start, "end": time.time(), "items": body["items"]})
353
+ return 200, None, {"results": [{"status": 200} for _ in body["items"]]}
354
+
355
+
356
+ def test_up_to_three_requests_are_in_flight_at_once():
357
+ s = Timed(0.3)
358
+ sender = Sender(s, **fast(flush_at=50))
359
+ for i in range(150):
360
+ sender.enqueue(run(f"r{i}"))
361
+ t0 = time.time()
362
+ sender.flush(timeout_s=3)
363
+ assert sender.stats()["sent"] == 150
364
+ assert len(s.calls) == 3
365
+ assert time.time() - t0 < 0.55 # one at a time would take 0.9 s
366
+ starts = sorted(c["start"] for c in s.calls)
367
+ assert starts[-1] - starts[0] < 0.1
368
+
369
+
370
+ def test_max_in_flight_1_sends_one_at_a_time():
371
+ s = Timed(0.1)
372
+ sender = Sender(s, **fast(flush_at=10, max_in_flight=1))
373
+ for i in range(30):
374
+ sender.enqueue(run(f"r{i}"))
375
+ sender.flush(timeout_s=3)
376
+ calls = sorted(s.calls, key=lambda c: c["start"])
377
+ assert all(b["start"] >= a["end"] for a, b in zip(calls, calls[1:]))
378
+
379
+
380
+ def test_feedback_waits_while_its_run_is_in_flight_in_another_request():
381
+ s = Timed(0.3)
382
+ sender = Sender(s, **fast(flush_at=1))
383
+ sender.enqueue(run("a"))
384
+ assert wait_for(lambda: sender.stats()["in_flight"] == 1)
385
+ sender.enqueue({"run_id": "a", "feedback": {"rating": 5}})
386
+ sender.enqueue(run("b")) # behind the feedback, also waits: order is kept
387
+ sender.flush(timeout_s=3)
388
+ assert sender.stats()["sent"] == 3
389
+ by = {("fb" if "feedback" in c["items"][0] else c["items"][0]["run"]["run_id"]): c for c in s.calls}
390
+ assert by["fb"]["start"] >= by["a"]["end"]
391
+
392
+
393
+
394
+ # ── Exit hand-off (3.0.4) ─────────────────────────────────────────────────────
395
+
396
+ def test_requests_at_exit_are_marked_exiting_and_others_are_not():
397
+ s = Server()
398
+ sender = Sender(s, **fast())
399
+ sender.enqueue(run("live"))
400
+ sender.flush(timeout_s=2)
401
+ sender.enqueue(run("late"))
402
+ sender._atexit()
403
+ assert "exiting" not in s.posts[0]["body"]
404
+ assert s.posts[1]["body"]["exiting"] is True
405
+ assert s.posts[1]["body"]["items"] == [run("late")]
406
+
407
+
408
+ def test_shutdown_marks_its_requests_exiting():
409
+ s = Server()
410
+ sender = Sender(s, **fast(flush_interval_s=60.0))
411
+ sender.enqueue(run("a"))
412
+ sender.shutdown()
413
+ assert s.posts[0]["body"]["exiting"] is True
414
+
415
+
416
+ def test_an_exit_hand_off_is_sent_and_not_called_rate_limiting(capsys):
417
+ handed = (200, None, {"results": [{"status": 202, "queued": True, "exit": True}]})
418
+ s = Server([handed])
419
+ sender = Sender(s, **fast())
420
+ sender.enqueue(run("a"))
421
+ sender._atexit()
422
+ assert sender.stats()["sent"] == 1
423
+ assert "rate limit" not in capsys.readouterr().err
@@ -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
@@ -0,0 +1 @@
1
+ SDK_VERSION = "3.0.4"
@@ -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. A daemon thread drains the queue to
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._thread: Optional[threading.Thread] = None
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
- if self._thread is None or not self._thread.is_alive():
207
- self._thread = threading.Thread(target=self._run, name="trodo-sender", daemon=True)
208
- self._thread.start()
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.get("paced") if isinstance(body.get("paced"), dict) else {})
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
- items = [q.item for q in batch]
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 not self._unreported["count"]:
453
- return {"items": items}
454
- return {"items": items, "dropped": {"count": self._unreported["count"], "by_reason": dict(self._unreported["by_reason"])}}
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trodo-python
3
- Version: 3.0.2
3
+ Version: 3.0.4
4
4
  Summary: Trodo Analytics SDK for Python — server-side event tracking
5
5
  License: ISC
6
6
  Keywords: analytics,tracking,trodo,server-side
@@ -1 +0,0 @@
1
- SDK_VERSION = "3.0.2"
File without changes
File without changes