Commit cb2a76a
[OPIK-7186] [SDK] feat: surface batch-flush data loss via FlushResult (#7513)
* [OPIK-7186] [SDK] feat: surface batch-flush data loss via FlushResult
The background sender silently dropped trace/span batches on terminal
failures (e.g. 403), while flush()/end() reported success. Add in-band,
non-blocking, non-throwing visibility:
- FlushResult returned by flush()/end() (flushed, drops, pending_replay,
per-drop details); flush() bool now reflects data loss.
- Opik.last_flush_result + Opik.get_upload_errors() (sender-wide history).
- DataLossTracker records terminal drops; FlushReporter assembles results.
- Drops recorded across processor (HTTP/serialization/unknown, 401),
queue overflow (generic on_evict hook), and shutdown-replay abandonment.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(sdk): address PR review — idempotent end(), flush() failure result, exact dropped_items
- end(): short-circuit when release() returns None so a repeated end() no
longer overwrites last_flush_result with a spurious not-flushed result
- flush(): on failure, record a failed FlushResult instead of leaving a stale
prior success in last_flush_result
- manager.release(): return None (not close()'s bool) on the flush=False path,
matching the "no drain outcome" contract
- DataLossTracker: keep exact running message/item totals so dropped_items no
longer undercounts once details are evicted from the bounded window
- revert recording unparseable-429s as terminal data loss (a 429 is transient,
not lost) — restores prior behavior
- docs: qualify end()/flush() for flush=False and attachment-upload scope
- test: build the flush-result client via __new__ to avoid real background
resources; add idempotent-end and stale-result coverage
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* docs(sdk): fix subject-verb agreement in drops_since docstring
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* feat(sdk): add Opik.get_data_loss() sender-wide data-loss history
last_flush_result is scoped to a single flush window, so drops that happened
before or between flushes were recorded but not retrievable in-band. Expose the
DataLossTracker's retained history via Opik.get_data_loss() (tracker ->
FlushReporter -> client). Storage stays a capped deque, so memory is bounded
regardless of run length.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* feat(sdk): return ErrorsReport with timestamps from Opik.get_errors_report()
Replace the bare-list get_data_loss() with get_errors_report() returning an
ErrorsReport instance: exact all-time dropped message/item totals, retained
per-drop details, a generated_at timestamp, and first/last_failure_at helpers
(each FailedMessageInfo already carries its own timestamp). Storage stays a
capped deque, so memory is bounded.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* refactor(sdk): drop ErrorsReport.has_data_loss
Callers can check total_dropped_messages directly; the convenience flag is
redundant.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* docs(sdk): document that ErrorsReport failures are capped
Make the bounded (drop-oldest, default 1000) nature of the report's per-drop
details explicit on ErrorsReport and Opik.get_errors_report(): totals stay
exact, but failures keeps only the most recent entries.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* refactor(sdk): drop the lock in DataLossTracker
Per review: the deque is thread-safe and an exact-to-the-message data-loss
tally isn't worth lock contention on the hot sending path. Counters are plain
ints now (best-effort under concurrent drops); reads snapshot the deque once.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* refactor(sdk): make FlushResult/ErrorsReport failures an immutable tuple
Address PR review: frozen dataclasses now expose failures as
Tuple[FailedMessageInfo, ...] so the value is truly immutable; clarify that
flush()'s bool does reflect upload completion (only the data-loss detail
excludes uploads); strengthen the eviction test to assert retained identities
and order.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 7df8e83 commit cb2a76a
16 files changed
Lines changed: 1006 additions & 33 deletions
File tree
- sdks/python
- src/opik
- api_objects
- message_processing
- processors
- tests/unit
- api_objects
- message_processing
- processors
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| |||
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
71 | 81 | | |
72 | 82 | | |
73 | 83 | | |
| |||
Lines changed: 42 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
| 66 | + | |
64 | 67 | | |
65 | 68 | | |
66 | 69 | | |
| |||
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
72 | 79 | | |
73 | 80 | | |
74 | | - | |
| 81 | + | |
75 | 82 | | |
76 | 83 | | |
77 | 84 | | |
78 | 85 | | |
79 | | - | |
| 86 | + | |
80 | 87 | | |
81 | 88 | | |
82 | 89 | | |
| |||
90 | 97 | | |
91 | 98 | | |
92 | 99 | | |
| 100 | + | |
93 | 101 | | |
94 | | - | |
| 102 | + | |
95 | 103 | | |
96 | 104 | | |
97 | 105 | | |
98 | 106 | | |
99 | 107 | | |
| 108 | + | |
| 109 | + | |
100 | 110 | | |
101 | | - | |
| 111 | + | |
102 | 112 | | |
103 | 113 | | |
104 | 114 | | |
105 | | - | |
| 115 | + | |
| 116 | + | |
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
| |||
156 | 167 | | |
157 | 168 | | |
158 | 169 | | |
| 170 | + | |
| 171 | + | |
159 | 172 | | |
160 | 173 | | |
161 | 174 | | |
| |||
166 | 179 | | |
167 | 180 | | |
168 | 181 | | |
| 182 | + | |
169 | 183 | | |
170 | 184 | | |
171 | 185 | | |
| |||
186 | 200 | | |
187 | 201 | | |
188 | 202 | | |
| 203 | + | |
189 | 204 | | |
190 | 205 | | |
191 | 206 | | |
| |||
236 | 251 | | |
237 | 252 | | |
238 | 253 | | |
239 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
240 | 259 | | |
241 | 260 | | |
242 | | - | |
| 261 | + | |
243 | 262 | | |
244 | | - | |
| 263 | + | |
245 | 264 | | |
246 | 265 | | |
247 | 266 | | |
| |||
326 | 345 | | |
327 | 346 | | |
328 | 347 | | |
329 | | - | |
| 348 | + | |
330 | 349 | | |
331 | 350 | | |
332 | 351 | | |
| |||
337 | 356 | | |
338 | 357 | | |
339 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
340 | 365 | | |
341 | 366 | | |
342 | 367 | | |
| |||
346 | 371 | | |
347 | 372 | | |
348 | 373 | | |
349 | | - | |
| 374 | + | |
350 | 375 | | |
351 | 376 | | |
352 | 377 | | |
| |||
355 | 380 | | |
356 | 381 | | |
357 | 382 | | |
358 | | - | |
| 383 | + | |
359 | 384 | | |
360 | 385 | | |
361 | | - | |
| 386 | + | |
362 | 387 | | |
363 | 388 | | |
364 | 389 | | |
| |||
367 | 392 | | |
368 | 393 | | |
369 | 394 | | |
370 | | - | |
| 395 | + | |
371 | 396 | | |
372 | 397 | | |
373 | 398 | | |
374 | 399 | | |
375 | 400 | | |
376 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
377 | 405 | | |
378 | 406 | | |
379 | 407 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
217 | 218 | | |
218 | 219 | | |
219 | 220 | | |
| 221 | + | |
| 222 | + | |
220 | 223 | | |
221 | 224 | | |
222 | 225 | | |
| |||
1927 | 1930 | | |
1928 | 1931 | | |
1929 | 1932 | | |
1930 | | - | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
1931 | 1936 | | |
1932 | | - | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
1933 | 1940 | | |
1934 | 1941 | | |
1935 | 1942 | | |
| |||
1957 | 1964 | | |
1958 | 1965 | | |
1959 | 1966 | | |
| 1967 | + | |
| 1968 | + | |
1960 | 1969 | | |
1961 | | - | |
| 1970 | + | |
| 1971 | + | |
1962 | 1972 | | |
1963 | 1973 | | |
| 1974 | + | |
1964 | 1975 | | |
1965 | 1976 | | |
1966 | | - | |
1967 | | - | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
1968 | 1983 | | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
1969 | 1996 | | |
1970 | 1997 | | |
1971 | 1998 | | |
1972 | 1999 | | |
1973 | 2000 | | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
1974 | 2009 | | |
1975 | 2010 | | |
1976 | 2011 | | |
1977 | 2012 | | |
1978 | | - | |
| 2013 | + | |
| 2014 | + | |
1979 | 2015 | | |
1980 | 2016 | | |
1981 | | - | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
1982 | 2063 | | |
1983 | 2064 | | |
1984 | 2065 | | |
| |||
0 commit comments