forked from mtusi2026/mtusi2026lab7
fix(tracing): preserve upload causality during watchdog republication
This commit is contained in:
@@ -145,3 +145,46 @@ def test_large_tracestate_cannot_break_durable_job_contract(signals):
|
||||
assert validate_job(message) == message
|
||||
assert retained["traceparent"].split("-")[1] == trace_id
|
||||
assert "tracestate" not in retained
|
||||
|
||||
|
||||
def test_watchdog_republication_keeps_original_upload_trace(signals):
|
||||
from datetime import UTC, datetime
|
||||
from uuid import uuid4
|
||||
|
||||
from src.pipeline import enqueue
|
||||
|
||||
exporter, _ = signals
|
||||
with telemetry.span("upload"):
|
||||
original = telemetry.carrier()
|
||||
row = {
|
||||
"id": uuid4(),
|
||||
"attachment_id": uuid4(),
|
||||
"pipeline_version": 1,
|
||||
"attempt": 0,
|
||||
"next_at": datetime.now(UTC),
|
||||
**original,
|
||||
}
|
||||
notifications = []
|
||||
|
||||
class Connection:
|
||||
def execute(self, statement, parameters):
|
||||
if statement.startswith("INSERT INTO outbox"):
|
||||
notifications.append(parameters[1].obj)
|
||||
return SimpleNamespace(fetchone=lambda: row)
|
||||
|
||||
with telemetry.span("watchdog.database"):
|
||||
enqueue(Connection(), row["id"])
|
||||
with telemetry.span("republished", parent=notifications[0]):
|
||||
pass
|
||||
spans = {s.name: s for s in exporter.get_finished_spans()}
|
||||
assert (
|
||||
spans["republished"].context.trace_id
|
||||
== spans["upload"].context.trace_id
|
||||
)
|
||||
assert (
|
||||
spans["republished"].context.trace_id
|
||||
!= spans["watchdog.database"].context.trace_id
|
||||
)
|
||||
assert (
|
||||
spans["republished"].parent.span_id == spans["upload"].context.span_id
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user