fix(sdk-metrics): Add missing catch and handle error in promise of PeriodicExportingMetricReader
#5006
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which problem is this PR solving?
PeriodicExportingMetricReader
'sdoExport
method will throw an Error if metrics export failed, and is expected to be caught within this try-catch.This method is called in two locations within the same
if-else
, but is only caught/handled in theelse
while not being caught/handled in theif
. Although theif-else
is within atry-catch
, one of thedoExport
invocations is called within a Promise.then(), which isn't being caught right nowLocation 1 (
doExport
's error is NOT caught):opentelemetry-js/packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts
Lines 141 to 145 in 6515ed8
Location 2 (
doExport
's error is caught):opentelemetry-js/packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts
Line 147 in 6515ed8
This PR ensures that
doExport
in Location 1 is caught.Short description of the changes
doExport
in thethen
statementType of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test in my application involving
PeriodicExportingMetricReader
with small metric export interval and many resource detectors (which causesresourceMetrics.resource.asyncAttributesPending
to be true)Checklist: