Commit 7225b58
fix(otlp): accept flexible timestamp formats in JSON payloads (#1108)
## Summary
- Adds normalization layer to convert OTLP JSON timestamps to string
format before deserialization
- Supports string timestamps (proto3 JSON spec), integer timestamps
(common in some SDKs), and object timestamps `{"low": n, "high": m}`
(from buggy older JS SDKs)
- Fixes errors like `"invalid type: integer, expected a string"` seen
with serverless-self-monitoring
## Root Cause
The `opentelemetry-proto` crate's serde deserializer only accepts
string-encoded 64-bit timestamps (per proto3 JSON spec), but some
OpenTelemetry SDKs send timestamps as integers or objects.
**serverless-self-monitoring uses outdated SDK versions:**
| Handler | Package | Version |
|---------|---------|---------|
| node18/20/22 | `@opentelemetry/exporter-trace-otlp-http` | **0.36.1**
(~Feb 2023) |
| python310 | `opentelemetry-exporter-otlp-proto-http` | **1.15.0**
(~Feb 2023) |
The extension's integration tests use **0.54.2** (current), which
properly serializes timestamps as strings, so this issue wasn't caught.
**Known upstream issue:** [opentelemetry-rust
#1662](open-telemetry/opentelemetry-rust#1662)
- The Rust `opentelemetry-proto` crate's serde implementation doesn't
accept both string and integer formats for 64-bit integers, as the
proto3 JSON spec recommends.
**Related JS SDK issue:** [opentelemetry-js
#4216](open-telemetry/opentelemetry-js#4216) -
Older JS SDK versions sent timestamps as `{"low": n, "high": m}` objects
instead of strings.
## Solution
Instead of waiting for upstream fixes or requiring all senders to update
their SDKs, we normalize JSON timestamps before deserialization:
1. Parse JSON into `serde_json::Value`
2. Recursively find timestamp fields (`startTimeUnixNano`,
`endTimeUnixNano`, `timeUnixNano`, `observedTimeUnixNano`)
3. Convert integers → strings, objects `{"low": n, "high": m}` →
reconstructed string
4. Deserialize normalized JSON with `opentelemetry-proto`
## Test plan
- [x] Unit tests for timestamp normalization (string, integer, object
formats)
- [x] Unit tests for nested structure normalization
- [x] Full test suite passes (506 tests)
- [x] Clippy passes with `-D warnings`
- [ ] Integration tests with serverless-self-monitoring
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 0f77098 commit 7225b58
1 file changed
+133
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
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 | + | |
8 | 73 | | |
9 | 74 | | |
10 | 75 | | |
| |||
46 | 111 | | |
47 | 112 | | |
48 | 113 | | |
49 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
50 | 119 | | |
51 | 120 | | |
52 | 121 | | |
| |||
61 | 130 | | |
62 | 131 | | |
63 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
0 commit comments