Skip to content

feat: add attribute value depth limit configuration - #702

Draft
pellared wants to merge 3 commits into
open-telemetry:mainfrom
pellared:depth-limit
Draft

feat: add attribute value depth limit configuration#702
pellared wants to merge 3 commits into
open-telemetry:mainfrom
pellared:depth-limit

Conversation

@pellared

@pellared pellared commented Jul 16, 2026

Copy link
Copy Markdown
Member

trentm pushed a commit to trentm/opentelemetry-specification that referenced this pull request Aug 7, 2026
…-telemetry#5186)

Towards
open-telemetry#4911

Per
open-telemetry#4006 (comment)

### Motivation

Bound (limit) the processing of nested attribute values.
It could also mitigate possible recursive processing of nested attribute
values if languages allow it.

The default of 64 is intentionally conservative. It matches the .NET
`System.Text.Json` default and is the lowest non-unlimited nesting/depth
default found in the parsers checked. Exact depth-counting semantics
differ between
libraries, so this table is used only as rationale for the default
value.

| Library / parser | Ecosystem | Default nesting/depth limit | Notes |
| --- | --- | ---: | --- |
| `System.Text.Json` | .NET | 64 | `MaxDepth` default value of `0` means
a maximum depth of 64. |
| `serde_json` | Rust | 128 | `Deserializer` initializes
`remaining_depth` to 128. |
| Gson `JsonReader` | Java | 255 | `DEFAULT_NESTING_LIMIT = 255`; docs
describe it as protection against recursive stack overflow. |
| Moshi `JsonReader` | JVM / Kotlin | 256 | Internal stack grows up to
256 levels, including the top-level document. |
| Jackson `StreamReadConstraints` | Java | 1000 | `DEFAULT_MAX_DEPTH =
1000`. |
| Go `encoding/json` | Go | 10000 | Internal scanner cap exists to
prevent stack overflow. |

### Changes

- Add `AttributeValueDepthLimit` to the common attribute limit rules
with a default of 64.
- Define depth counting explicitly: depth starts at 1 for the top-level
attribute value and increments when descending into array elements or
map values.
- Replace any nested array or map with an empty value to not go beyond
the limit.

The depth limiting algorithm matches what e.g. `System.Text.Json` would
expect if they have the same limit.

### Prototype

- open-telemetry/opentelemetry-java#8656
- open-telemetry/opentelemetry-go#8534

### Declarative config

- open-telemetry/opentelemetry-configuration#702

### Notes

- This PR does not add an environment variable for the new limit.
- This is updating a stable part of the specification. However, I
classify this as a bugfix as having unbounded processing is not desired
(https://cwe.mitre.org/data/definitions/789.html).

---------

Co-authored-by: Carlos Alberto Cortez <calberto.cortez@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant