open-telemetry / open-telemetry/opentelemetry-java
AttributesMap counts attribute overwrites as dropped attributes
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.5k
- Forks
- 1k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 58
Description
Describe the bug
AttributesMap.put() increments totalAddedValues even when it overwrites an existing key. SdkSpan.toSpanData() exposes that counter as SpanData.getTotalAttributeCount(), and the OTLP marshalers serialize getTotalAttributeCount() - getAttributes().size() as dropped_attributes_count, so every overwrite is reported as a drop.
Steps to reproduce
Span span = SdkTracerProvider.builder().build().get("t").spanBuilder("s").startSpan();
span.setAttribute("http.route", "/a");
span.setAttribute("http.route", "/b");
SpanData data = ((ReadableSpan) span).toSpanData();
What did you expect to see?
data.getTotalAttributeCount() == 1 and dropped_attributes_count=0 over OTLP. The spec only allows discarding attributes when a limit is exceeded and defines same-key sets as overwrites (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute-limits); the proto comment says 0 means nothing was dropped. opentelemetry-go (addOverCapAttrs) and opentelemetry-python (BoundedAttributes) do not count overwrites as drops.
What did you see instead?
data.getTotalAttributeCount() == 2 while data.getAttributes().size() == 1, so the exported span carries dropped_attributes_count=1. Cause: the increment in AttributesMap.put() (sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/AttributesMap.java line 123) runs before the existing-name check. Log records (SdkReadWriteLogRecord) and recordException events share this path. Related: #7142 fixed a different dropped-count inaccuracy in the same class.
What version and what artifacts are you using?
Artifacts: opentelemetry-sdk-common, opentelemetry-sdk-trace, opentelemetry-exporter-otlp
Version: main @ 509182e4b
How did you reference these artifacts? N/A
Environment
Compiler: Temurin 21
OS: N/A
Additional context
N/A
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/AttributesMap.java at the counter update and existing-name check. Trace how SdkSpan.toSpanData(), SdkReadWriteLogRecord, recordException events, and the OTLP marshalers use the count. Reproduce the overwrite example and verify that total attributes remains 1 and dropped_attributes_count is 0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100