Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Exemplar keeps stale span context when a reservoir cell is overwritten outside a span

Open Beginner friendly
#8,869 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
observability

Research direction

Start in sdk/metrics/.../internal/exemplar/ReservoirCell.java at offerMeasurement(), especially lines 73-76. Reproduce with always-on exemplars by recording inside a sampled span and then outside one in the same bucket, then collect. Done when the overwritten exemplar's span context belongs to the new measurement and is invalid for the outside-span recording.

Written by the indexing model from the issue text.

Description

Describe the bug
When an exemplar reservoir cell is overwritten within one collection cycle by a measurement recorded outside a span, the exported exemplar has the new value, time and attributes but keeps the trace/span id of the previous measurement.

Steps to reproduce

  1. Build an SdkMeterProvider with setExemplarFilter(ExemplarFilter.alwaysOn()) (or otel.metrics.exemplar.filter=always_on).
  2. On a histogram with default buckets, call record(1.0) inside a sampled span, then record(2.0) with no active span (same bucket).
  3. Collect.

What did you expect to see?
An exemplar with value=2.0 and an invalid span context. The spec defines an exemplar as one recorded measurement, with the trace/span id of the span active when it was recorded.

What did you see instead?
value=2.0 with the span id of the first measurement. ReservoirCell.offerMeasurement() (sdk/metrics/.../internal/exemplar/ReservoirCell.java lines 73-76) always overwrites value, time and attributes, but updates spanContext only when the new span context is valid.

What version and what artifacts are you using?
Artifacts: opentelemetry-sdk-metrics
Version: main @ ce32c1205
How did you reference these artifacts? Local build

Environment
Compiler: Temurin 21
OS: N/A

Additional context
Not visible with the default trace_based filter, since every measurement it lets through has a sampled span.

Spec: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#exemplar

Dominant language
Java
Stars
2.5k
Forks
1k
Avg merge
2d 19h
Merged PRs (30d)
64

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from open-telemetry/opentelemetry-java

All issues in open-telemetry/opentelemetry-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.