39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""Real exporter failure must remain bounded and account for lost sampled spans."""
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def test_span_queue_loss_conservation_when_collector_absent():
|
|
code = '''
|
|
import json, time
|
|
from messenger.telemetry import setup
|
|
class Pool:
|
|
def get_stats(self): return {}
|
|
class Store:
|
|
pool=Pool()
|
|
t=setup("messenger-api")
|
|
t.start_background(Store())
|
|
for index in range(1200):
|
|
with t.tracer.start_as_current_span("synthetic-safe-span"):
|
|
pass
|
|
time.sleep(7)
|
|
counts=t.export_stats.snapshot()
|
|
pending=len(t.batch_spans._batch_processor._queue)
|
|
loss=counts["spans_recorded"]-counts["spans_exported"]-counts["spans_export_failed"]-counts["spans_in_flight"]-pending
|
|
assert counts["spans_recorded"]==1200
|
|
assert 0<=pending<=256
|
|
assert loss>0
|
|
assert counts["spans_export_failed"]>0
|
|
print(json.dumps({"recorded":1200,"pending":pending,"queue_lost":loss,"export_failed":counts["spans_export_failed"]}))
|
|
t.close()
|
|
'''
|
|
env = {**os.environ, "PYTHONPATH": str(Path(__file__).resolve().parents[1]/"src"),
|
|
"OTEL_ENABLED": "1", "OTEL_EXPORTER_OTLP_ENDPOINT": "http://127.0.0.1:1"}
|
|
result = subprocess.run([sys.executable, "-c", code], env=env, capture_output=True, text=True, timeout=15)
|
|
assert result.returncode == 0, result.stderr[-1000:]
|
|
payload = json.loads(next(line for line in result.stdout.splitlines() if line.startswith('{')))
|
|
assert payload["queue_lost"] > 0
|