GoogleCloudPlatform / opentelemetry-operations-python

OpenTelemetry Python exporters for Google Cloud Monitoring and Trace
https://google-cloud-opentelemetry.readthedocs.io/en/stable/
Apache License 2.0
64 stars 45 forks source link

Graceful Shutdown for `CloudMonitoringMetricsExporter` #315

Closed damjad closed 6 months ago

damjad commented 7 months ago

CloudMonitoringMetricsExporter does not export metrics on shutdown events because the implementation is empty.

https://github.com/GoogleCloudPlatform/opentelemetry-operations-python/blob/6b7211df1ebbb37d9a16141346ffec3a7a5c90d9/opentelemetry-exporter-gcp-monitoring/src/opentelemetry/exporter/cloud_monitoring/__init__.py#L373-L374

damjad commented 7 months ago

Is it because the implementation is empty because of an extra collect call when the thread is ended?

https://github.com/open-telemetry/opentelemetry-python/blob/01d1d4b1574b18ce73d7ab925f1f7308f8debdee/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py#L521-L522

aabmass commented 6 months ago

Is it because the implementation is empty because of an extra collect call when the thread is ended?

Yes, SDK will flush any remaining metrics at shutdown, assuming it is correctly called. The exporter's shutdown function would be for cleaning up or shutting down the exporter itself.

Did you encounter any specific issue?

damjad commented 6 months ago

Nothing, in particular, I needed to make sure that it worked without explicitly calling shutdown.