Repository navigation
Commit 584230f
feat(traces): OTLP span encoding and client-side validity (#950)
* feat(traces): OTLP span encoding and client-side validity
Adds the OTLP JSON encoder for spans: AnyValue encoding per the traces spec
(int64 as strings, out-of-range ints and non-finite floats as strings, None
values and empty keys dropped, unpaired surrogates replaced with U+FFFD, a
bounded walk that terminates on cycles), the span record builder with the W3C
flags byte and OTel remoteness bits, the one-resource/one-scope envelope with
service.name always present, and the name and timestamp sanitizers. One bad
value otherwise gets the whole batch rejected. Not reachable from the client.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TkZAsCciW4PV8ZdcCHmAbA
* fix(traces): reject a float time whose nanosecond value overflows
A finite float like 1e308 becomes infinite once scaled to nanoseconds, so
round() raised instead of the value falling back to the derived time.
* test(traces): move the golden OTLP payload to a snapshot file
Keeps the ingestion-shape fixture in posthog/test/snapshots alongside the
other server payload snapshots instead of a 100-line inline dict.
* refactor(traces): name the OTLP sampled bit apart from the header flags
TRACE_FLAGS_SAMPLED was a hex string in _traceparent and an int here. The
module docstring now says which inputs the encoder trusts.
* fix(traces): count attributes the encoder budget cuts, and encode the resource once
When the node budget ran out, every remaining attribute vanished with a
debug log and no droppedAttributesCount, so an oversized first value
silently erased later keys. The cut is now counted on the span and on
each event. The resource is encoded once by the caller instead of on
every batch.
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 0affb06 commit 584230f
5 files changed
Lines changed: 1272 additions & 0 deletions
File tree
- posthog
- test
- snapshots
- tracing
- tracing
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
0 commit comments