Skip to content

Commit 291fd63

Browse files
committed
fix(observability): close each telemetry exporter when the builder exits, draining what its per-run copies shared
Signed-off-by: Somay-kousis <somaykaush@gmail.com>
1 parent 5b1f53e commit 291fd63

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎packages/nvidia_nat_core/src/nat/builder/workflow_builder.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,9 @@ async def add_telemetry_exporter(self, name: str, config: TelemetryExporterBaseC
14021402

14031403
# Only protect the shared state modifications (serialized)
14041404
exporter = await self._get_exit_stack().enter_async_context(exporter_context_manager)
1405+
if isinstance(exporter, BaseExporter):
1406+
# runs use per-run copies of the exporter, so this instance may never be started or stopped
1407+
self._get_exit_stack().push_async_callback(exporter.close)
14051408

14061409
self._telemetry_exporters[name] = ConfiguredTelemetryExporter(config=config, instance=exporter)
14071410

‎packages/nvidia_nat_core/src/nat/observability/exporter/base_exporter.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,17 @@ async def wait_for_tasks(self, timeout: float = 5.0):
377377
except Exception as e:
378378
logger.exception("%s: Error while waiting for tasks: %s", self.name, e)
379379

380+
async def close(self):
381+
"""Release what this exporter shares with its per-run copies, whether or not it was started itself.
382+
383+
Per-run copies share the processors of this instance, so this is where a batcher's remaining items are
384+
exported for the last time. Safe to call more than once.
385+
"""
386+
if self._running:
387+
await self.stop()
388+
else:
389+
await self._cleanup()
390+
380391
@override
381392
async def stop(self):
382393
"""Stop the exporter immediately without waiting for background tasks.

0 commit comments

Comments
 (0)