Skip to content

sdk/metrics: dynamically created delta and cumulative async instruments use reader's previous collection timestamp instead of instrument creation time on first collection #8980

Open

Description

@dashpole

Per the Start timestamps specification, on the first collection interval for an instrument, delta aggregations and cumulative asynchronous series measured in that first interval should use the creation time of the instrument as their start timestamp.

In #8180, DeltaSynchronousMetricStorage.collect() (DeltaSynchronousMetricStorage.java#L298-L302), DeltaAsynchronousMetricStorage.doCollect() (AsynchronousMetricStorage.java#L277-L281), and AsynchronousMetricStorage.createAggregatorHandle() (AsynchronousMetricStorage.java#L188-L191) compute the start timestamp via:

registeredReader.getLastCollectEpochNanosOrDefault(instrumentCreationEpochNanos)

Because RegisteredReader.lastCollectEpochNanos (RegisteredReader.java#L29-L63) is tracked per reader and only falls back to instrumentCreationEpochNanos when lastCollectEpochNanos == -1 (before the reader has performed any collection), an instrument created after the reader's first collection (instrumentCreationEpochNanos > lastCollectEpochNanos) will receive the reader's previous collection timestamp (from before the instrument existed) on its first collection instead of instrumentCreationEpochNanos.

Activity

  1. DevyanshMalhotra commented on Oct 28, 2026

    @DevyanshMalhotra

    Hi maintainers, I'd like to work on this issue if it's available for external contribution.

    My proposed approach is to first add deterministic regression coverage for instruments created after a reader has already collected, then investigate the start-timestamp selection in the affected delta synchronous and asynchronous storage paths. I'd also check that subsequent collections retain the expected temporality semantics.

    Would you be open to assigning this issue to me, or letting me know if someone is already working on it? I'll hold off on opening a PR until the approach is confirmed. Thanks!

  2. dashpole commented on Oct 30, 2026

    @dashpole
    ContributorAuthor

    Nobody is working on this yet, so feel free to open a PR! Taking Math.max of the reader's last collect timestamp and instrumentCreationEpochNanos (along with regression tests for delta sync, delta async, and cumulative async instruments created after a collection) should be sufficient.

  3. DevyanshMalhotra commented on Oct 31, 2026

    @DevyanshMalhotra

    Thanks @dashpole for the guidance!

    I've opened PR #8992 implementing the suggested Math.max fix, with regression tests covering delta synchronous, delta asynchronous, and cumulative asynchronous instruments across both memory modes.

    The local metrics-module checks are passing. Looking forward to your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions