fix(js/plugins/google-cloud): Implement forceFlush and shutdown #1869
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.
We were seeing occasions where flows run on Cloud functions are not exporting all metrics. We suspect that there are times where we were not waiting for metrics to complete because of the way that the cloud exporter exports asynchronously: https://github.com/GoogleCloudPlatform/opentelemetry-operations-js/blob/main/packages/opentelemetry-cloud-monitoring-exporter/src/monitoring.ts#L117C53-L117C56
Adding a shutdown hook to our metrics wrapper ensures we are awaiting the callback function from the wrapped cloud exporter.
Manually tested locally using
![image](https://private-user-images.githubusercontent.com/1417421/410195234-2fabf68e-63f4-4d44-b85f-6eefbbdf39b4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNjU2NDgsIm5iZiI6MTczOTE2NTM0OCwicGF0aCI6Ii8xNDE3NDIxLzQxMDE5NTIzNC0yZmFiZjY4ZS02M2Y0LTRkNDQtYjg1Zi02ZWVmYmJkZjM5YjQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTBUMDUyOTA4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZWRmNTdjZjE0YTQ1NjFiNmYzMDc1Y2YxY2U4YjA0MzhiZmQ2Mzg3NmUxZjlkMjA0MmMyNWIzN2M3MjA2MTRkYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.amRPzXNp0KYrhidl31JoFt-hhkXQPU0ukHflLbHgkRI)
forceDevExport = true
to make sure metrics are still being exported.Checklist (if applicable):