File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
opentelemetry-sdk/src/opentelemetry/sdk/_shared_internal Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 1515from __future__ import annotations
1616
1717import collections
18+ import time
1819import enum
1920import inspect
2021import logging
@@ -185,20 +186,26 @@ def emit(self, data: Telemetry) -> None:
185186 def shutdown (self , timeout_millis : int = 30000 ):
186187 if self ._shutdown :
187188 return
189+ shutdown_should_end = time .time () + timeout_millis / 1000
188190 # Causes emit to reject telemetry and makes force_flush a no-op.
189191 self ._shutdown = True
190192 # Interrupts sleep in the worker if it's sleeping.
191193 self ._worker_awaken .set ()
192194 self ._worker_thread .join (timeout_millis / 1000 )
193195 # Stops worker thread from calling export again if queue is still not empty.
194196 self ._shutdown_timeout_exceeded = True
195- # We want to shutdown immediately because we already waited `timeout_millis`.
197+ # We want to shutdown immediately only if we already waited `timeout_millis`.
198+ # Otherwise we pass the remaining timeout to the exporter.
196199 # Some exporter's shutdown support a timeout param.
197200 if (
198201 "timeout_millis"
199202 in inspect .getfullargspec (self ._exporter .shutdown ).args
200203 ):
201- self ._exporter .shutdown (timeout_millis = 0 ) # type: ignore
204+ remaining_time = shutdown_should_end - time .time ()
205+ if remaining_time < 0 :
206+ self ._exporter .shutdown (timeout_millis = 0 ) # type: ignore
207+ else :
208+ self ._exporter .shutdown (timeout_millis = remaining_time * 1000 ) # type: ignore
202209 else :
203210 self ._exporter .shutdown ()
204211 # Worker thread **should** be finished at this point, because we called shutdown on the exporter,
You can’t perform that action at this time.
0 commit comments