Skip to content

Commit c04b6bc

Browse files
committed
open telemetry fix test
1 parent b939777 commit c04b6bc

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/backend/base/langflow/services/telemetry/opentelemetry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ def shutdown(self):
326326
self._logger_provider.shutdown()
327327
self._metrics.clear()
328328
OpenTelemetry._initialized = False
329+
# Evict from the singleton cache: __init__ never re-runs on a cached instance.
330+
with ThreadSafeSingletonMetaUsingWeakref._lock:
331+
ThreadSafeSingletonMetaUsingWeakref._instances.pop(OpenTelemetry, None)
329332

330333

331334
# Connection-pool saturation, read from SQLAlchemy at collection time rather than tracked.

src/backend/tests/unit/test_telemetry.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ def test_opentelementry_singleton(opentelemetry_instance):
188188
assert opentelemetry_instance.prometheus_enabled == opentelemetry_instance_3.prometheus_enabled
189189

190190

191+
def test_shutdown_then_reinit_restores_counters(opentelemetry_instance):
192+
"""A shut-down singleton must not poison later OpenTelemetry() callers.
193+
194+
TelemetryService.teardown() calls shutdown(), which clears the instrument map.
195+
While the old instance is still strongly referenced (the torn-down service holds
196+
it), the next OpenTelemetry() call must still return a working instance instead
197+
of the cleared one, or every metric call in the process fails with
198+
"Metric '...' is not a counter".
199+
"""
200+
opentelemetry_instance.shutdown()
201+
202+
fresh = OpenTelemetry()
203+
fresh.increment_counter(metric_name="num_files_uploaded", value=1, labels=fixed_labels)
204+
205+
191206
def test_missing_labels(opentelemetry_instance):
192207
with pytest.raises(ValueError, match="Labels must be provided for the metric"):
193208
opentelemetry_instance.increment_counter(metric_name="num_files_uploaded", labels=None, value=1.0)

0 commit comments

Comments
 (0)