opencensus-python
opencensus-python copied to clipboard
Method on exporter to flush metrics before process exits
I believe the method to flush metrics via the exporter exists in go lang binding but I haven't been able to find it via python3 classes. Happy to help implement it if lack of bandwidth is an issue. Also, keen to know if there is a different approach in python. FWIW, I'm using the stackdriver exporter in GCP. Thanks for any consideration or advice.
There's a relevant .close
method here: https://github.com/census-instrumentation/opencensus-python/blob/master/opencensus/metrics/transport.py#L87
In stackdriver the relevant code is here: https://github.com/census-instrumentation/opencensus-python/blob/07588770a68c259768c9a372c1a5e3b027711a7b/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/stats_exporter/init.py#L404
I'll send a sample cl that adds a close method to the exporter that then calls the close method on the transport exporter thread
. Would that help?
@shanemhansen @MikeWoodGCP I ran into this while looking into exactly the same issue - did this go anywhere in the end? Thanks!
@shanemhansen @MikeWoodGCP Let us know if any progress has been made!
Thank you so much!
As a stopgap, one way to flush is:
import threading
from opencensus.metrics.transport import PeriodicMetricTask
def flush_all_metrics():
for thread in threading.enumerate():
if isinstance(thread, PeriodicMetricTask):
thread.close()
thread.join(timeout=60)