@@ -790,6 +790,28 @@ async def test_enqueue_records_enqueued_metric(self, monkeypatch):
790790
791791 mock_metrics .span_events_enqueued .add .assert_any_call (1 , {"event_type" : "start" })
792792
793+ async def test_enqueue_during_shutdown_records_dropped_metric (self , monkeypatch ):
794+ monkeypatch .setenv ("AGENTEX_TRACING_METRICS" , "1" )
795+ import agentex .lib .core .observability .tracing_metrics_recording as recording
796+
797+ recording ._metrics_enabled = None
798+ recording ._tracing = None
799+ mock_metrics = MagicMock ()
800+ proc = _make_processor ()
801+ queue = AsyncSpanQueue (linger_ms = 0 )
802+
803+ with patch (
804+ "agentex.lib.core.observability.tracing_metrics.get_tracing_metrics" ,
805+ return_value = mock_metrics ,
806+ ):
807+ queue .enqueue (SpanEventType .START , _make_span (), [proc ])
808+ await asyncio .sleep (0.05 )
809+ queue ._stopping = True
810+ queue .enqueue (SpanEventType .END , _make_span (), [proc ])
811+ await queue .shutdown ()
812+
813+ mock_metrics .span_events_dropped .add .assert_any_call (1 , {"reason" : "shutdown" })
814+
793815 async def test_processor_failure_records_export_failure (self , monkeypatch ):
794816 monkeypatch .setenv ("AGENTEX_TRACING_METRICS" , "1" )
795817 import agentex .lib .core .observability .tracing_metrics_recording as recording
0 commit comments