fix: apply attribute limits to log record and span processor attributes, including nested values #1343
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1343"
general
weight: 0.35
aranhave
Attribute limits for log records and spans
Author @williazz · Reviewers: code owners · Status: ready for review · Date: 2026-12-04 · Resolves #1336
Baseline is
mainat f299ff7c; the proposal is head 633132aa. Tests ran on 2026-12-03. This replaces the earlier Summary/Testing description.Background
!Today on main f299ff7c: five attribute writers each pass a count-limit stage and a length-limit stage before export. The log record builder evicts the oldest attribute and truncates only top-level strings and one level of arrays. Log record processors bypass both limits. The span builder and samplers evict the oldest and skip the length limit. Span.setAttribute counts updates as new attributes and truncates only top-level strings. Event and exception attributes evict the oldest.
Five writers set attributes, each against
LogLimitsorSpanLimits(count 128, length unlimited by default):1.
LogRecordBuilder.setAttributestores into anAttributesDictionarybuilt with both limits.2. A log record processor, such as
SessionLogRecordProcessor, callsReadableLogRecord.setAttribute, which writes straight into a dictionary.3.
SpanBuilder.setAttributeand sampler attributes go into anAttributesDictionarybuilt with the count limit only.4.
Span.setAttribute, including calls fromSpanProcessor.onStart, runsSpanSdk.setAttribute.5. Event and exception attributes go into a per-event
AttributesDictionary.AttributesDictionaryevicts the oldest key when full and truncates top-level strings and one level of arrays.Problem statement
Every writer breaks the common attribute limits somewhere, as the pink cells above show. The spec says:
and binds spans to them: "Span attributes MUST adhere to the common rules of attribute limits."
Concretely,
SessionLogRecordProcessoraddssession.idto a provider built withmaxAttributeCount: 0; a nested string or a deprecated.stringArraypasses any length limit; and a span past its count limit drops its first attributes, which usually carry the most context. The cause is that each writer enforces limits by its own code path.A solution must:
1. Apply count and length limits to attributes from every writer, including processors.
2. Truncate strings at any depth, and in
.stringArray.3. Discard the new attribute past the count limit, keeping existing ones.
4. Keep the public API, and decode records the persistence exporter wrote with the previous release.
Out of scope
AttributePerLinkCountLimitis unused on main; a separate issue.logLimits:onUserLogRecordProcessorandVitalsLogRecordProcessor. Redundant after this lands; removed in a follow-up (#1332, #1333).Proposal
!Proposed in #1343: the same five writers and stages. Every count stage, marked CHANGED, discards a new attribute once the limit is reached, and Span.setAttribute counts distinct keys. Every length stage except event and exception attributes, marked CHANGED, truncates strings recursively through arrays, maps and the deprecated stringArray.
What changes
| Writer | Today | Proposed |
| --- | --- | --- |
| Log record builder | evicts oldest; shallow truncation | discards new; recursive |
| Log record processor | no limits | discards new; recursive |
| Span builder, sampler | evicts oldest; no length limit | discards new; recursive |
|
Span.setAttribute| counts updates; top-level strings | counts distinct keys; recursive || Event, exception | evicts oldest | discards new |
How truncation works
One internal
AttributeValue.truncated(toLength:)recurses through.arrayand.setand truncates each.stringArraystring, keeping the case.LogLimits,SpanSdk,SpanBuilderSdkandAttributesDictionaryall call it. With a limit of 3,.array([.array(["abcdef"])])becomes.array([.array(["abc"])]).How the count limit discards
ReadableLogRecordnow carries theLogLimitsit was built with and applies them insetAttribute, so processor writes obey them, and the builder writes through the same rule.AttributesDictionary.updateValuereturns early for a new key once full.recordExceptionadds the exception's own attributes first, so they keep their slots.Ship it
One PR, six commits.
logLimitsstays out ofCodable, so records persisted by the previous release still decode.swift test --enable-all-traits: 1397 tests, 0 failures on Linux (main: 1386); macOS and the iOS 27 simulator pass on Revyl; all upstream checks pass.Risks
log-limitsdemo scenario setsession.idbefore the sampling decision; they now set the decision first, assertions unchanged.make integ-tests-ioshas not run on the reordered scenario.setAttributescalls. Dictionary order decides which keys survive, as with eviction..stringArrayin the SDK.Alternate solutions
Do nothing
Processor attributes stay unbounded, and every processor needs its own
logLimits:parameter, as #1332 and #1333 added.Limit inside each processor
What #1332 and #1333 do. It leaves third-party processors and spans uncovered.
Convert
.stringArrayto.arraywhen truncatingAvoids the warning but changes the value callers read back.
Glossary
AttributesDictionary: the SDK's bounded attribute map behind spans, span builders and events.maxAttributeCountorattributeCountLimit, the most top-level attributes a record or span keeps.maxAttributeLengthorattributeValueLengthLimit, the most characters a string value keeps.LogRecordProcessororSpanProcessorthat sees each record or span before export.