Skip to content

PeriodicReader.Shutdown now applies the periodic reader's timeout by default#4356

Merged
pellared merged 4 commits into
open-telemetry:mainfrom
dashpole:shutdown_timeout
Jul 25, 2023
Merged

PeriodicReader.Shutdown now applies the periodic reader's timeout by default#4356
pellared merged 4 commits into
open-telemetry:mainfrom
dashpole:shutdown_timeout

Conversation

@dashpole
Copy link
Copy Markdown
Collaborator

@dashpole dashpole commented Jul 24, 2023

From https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#shutdown,

Shutdown SHOULD complete or abort within some timeout. Shutdown MAY be implemented as a blocking API or an asynchronous API which notifies the caller via a callback or an event. OpenTelemetry SDK authors MAY decide if they want to make the shutdown timeout configurable.

We don't currently have a timeout, so this PR adds a timeout to meet the specification.

We could hard-code the timeout, but I think it makes the most sense to re-use the timeout set with WithTimeout(), since Shutdown essentially is a collectAndExport call, which the shutdown is intended for. We can always add a separate timeout for Shutdown, as long as it defaults to the general timeout.

Fixes #3663

This is also relevant for #3666. For MetricExporter.Export:

Export MUST NOT block indefinitely, there MUST be a reasonable upper limit after which the call must time out with an error result (Failure).

That implies we should set a timeout on contexts we pass to Export, which this PR does.

@dashpole dashpole marked this pull request as ready for review July 24, 2023 17:22
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 24, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.4%. Comparing base (d8d3502) to head (2c41d82).
Report is 1538 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #4356     +/-   ##
=======================================
- Coverage   83.4%   83.4%   -0.1%     
=======================================
  Files        184     184             
  Lines      14374   14376      +2     
=======================================
- Hits       12001   11999      -2     
- Misses      2145    2149      +4     
  Partials     228     228             
Files with missing lines Coverage Δ
sdk/metric/periodic_reader.go 84.1% <100.0%> (+0.1%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dashpole dashpole force-pushed the shutdown_timeout branch 2 times, most recently from 450de18 to 0412711 Compare July 24, 2023 17:27
Copy link
Copy Markdown
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update WithTimeout documentation to include this behavior?

@dashpole
Copy link
Copy Markdown
Collaborator Author

Can we update WithTimeout documentation to include this behavior?

Done

Comment thread CHANGELOG.md Outdated
@pellared pellared merged commit c1a644a into open-telemetry:main Jul 25, 2023
@MrAlias MrAlias modified the milestone: Metric SDK v0.40.0 Aug 3, 2023
@MrAlias MrAlias added this to the v1.17.0/v0.40.0 milestone Aug 3, 2023
@MrAlias MrAlias added the area:metrics Part of OpenTelemetry Metrics label Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:metrics Part of OpenTelemetry Metrics

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

Verify compliant metric SDK specification implementation: MetricReader/MetricReader operations/Shutdown

5 participants