Skip to content

Metrics: clarify and align PeriodicMetricReader export timeout semantics with batching spec #8311

Closed

Description

@zeitlinger

Summary

The Java metrics SDK now has batching support in PeriodicMetricReader via maxExportBatchSize, but it still appears to lack reader-level timeout enforcement for metric exports.

This matters because the metrics spec now treats exportTimeoutMillis and maxExportBatchSize together on the periodic exporting metric reader, and requires the timeout to apply to each individual export request.

Spec reference:

Current Java behavior

From code inspection:

  • PeriodicMetricReaderBuilder exposes setInterval(...), setExecutor(...), and setMaxExportBatchSize(...), but no reader-level export timeout configuration.
  • PeriodicMetricReader serializes batched export(...) calls, but it does not apply a timeout budget around each batch export itself.
  • Some exporters (for example OTLP metric exporters) have their own exporter/network timeout settings, so per-request timeout may happen in practice there, but that is exporter-specific behavior rather than PeriodicMetricReader behavior.
  • By contrast, Java's BatchSpanProcessor and BatchLogRecordProcessor do explicitly join export results with an exporter timeout.

Why this seems like a gap

The merged metrics spec text says the periodic reader has:

  • exportIntervalMillis
  • exportTimeoutMillis
  • development-status maxExportBatchSize

and that:

  • batches must be exported serially
  • timeout applies to individual requests
  • ForceFlush should collect, split into batches if needed, export each batch, call exporter ForceFlush, and report success/failure/timeout

Java seems aligned on serial batching/order, but not on reader-level timeout enforcement.

Questions

  • Should Java metrics add a reader-level timeout configuration on PeriodicMetricReaderBuilder to align with the spec model?
  • Should that timeout be enforced per batch in both scheduled export and forceFlush() paths?
  • Should timeout handling mirror the existing trace/logs processors as closely as possible?
  • If exporter-specific timeout already exists (e.g. OTLP), is that considered sufficient for now, or should the reader still own timeout semantics explicitly?

Related

Activity

  1. ADITYA-CODE-SOURCE commented on May 24, 2026

    @ADITYA-CODE-SOURCE
    Contributor

    Hi @zeitlinger — I’d like to take this on with a focused PR, but want to confirm the intended Java-side API/semantics first.
    From current code, PeriodicMetricReaderBuilder has setInterval(...) / setExecutor(...) and PeriodicMetricReader calls exporter.export(...) without enforcing a reader-level timeout per request/batch, and forceFlush() similarly doesn’t apply an export-timeout budget.

    Proposed direction (spec-aligned):

    • Add PeriodicMetricReaderBuilder#setExportTimeout(Duration) (or similar), defaulting to the spec’s exportTimeoutMillis default.
    • Enforce the timeout per individual export(...) call (per batch when maxExportBatchSize is enabled), both for scheduled exports and forceFlush(), mirroring BatchSpanProcessor / BatchLogRecordProcessor behavior (join-with-timeout, mark failure on timeout).

    Questions to confirm before I implement:

    • Do you want the timeout owned by PeriodicMetricReader (reader-level), even if exporters also have their own network timeouts?
    • Should forceFlush() apply the same per-batch timeout semantics (collect → split into batches → export serially with per-batch timeout → exporter.flush), and return failure if any batch times out/fails?
    • Any preference on naming (setExportTimeout vs setTimeout) and default value to match the spec?
  2. jack-berg commented on May 27, 2026

    @jack-berg
    Member

    Personally, I find the spec ambiguous about whether the timeout applies to individual export requires to the collective batch: https://github.com/open-telemetry/opentelemetry-specification/blame/f1c6078c75f137b8b21084107e988204156d8372/specification/metrics/sdk.md#L1497-L1512

    In slack, @dashpole (the author of the spec batch PR), says the timeout should apply to each export call. This seems reasonable to me, but I would like the spec to be explicit.

    Should Java metrics add a reader-level timeout configuration on PeriodicMetricReaderBuilder to align with the spec model?
    Should that timeout be enforced per batch in both scheduled export and forceFlush() paths?

    As noted, right now, PMR doesn't enforce any limit. Practically, this rarely matters because PMR is paired with an OTLP exporter, which has a default timeout of 10s. PMR runs on an interval of 60s. So for the lack of PMR timeout to matter, PMR interval and OTLP exporter timeout must be adjusted such that PMR interval is shorter than OTLP timeout. I.e. PMR interval of 10s with OTLP exporter timeout of 20s. In this case, long running OTLP exports would cause subsequent PMR collections to be dropped as the previous would still be in progress.

    If the semantics of PMR export timeout are that it applies to each individual export call, then is there any value added by adding this additional property? Can't you achieve the desired affect by just configuring OTLP exporter timeout to your desired PMR export timeout value?

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

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions