test(diagnostics-otel): cover trace self-parent guard · openclaw/openclaw@84f183b
vincentkoc
·
2026-04-26
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1449,6 +1449,50 @@ describe("diagnostics-otel service", () => {
|
1449 | 1449 | await service.stop?.(ctx); |
1450 | 1450 | }); |
1451 | 1451 | |
| 1452 | +test("does not self-parent trusted diagnostic lifecycle spans without parent ids", async () => { |
| 1453 | +const service = createDiagnosticsOtelService(); |
| 1454 | +const ctx = createOtelContext(OTEL_TEST_ENDPOINT, { traces: true, metrics: true }); |
| 1455 | +await service.start(ctx); |
| 1456 | + |
| 1457 | +emitTrustedDiagnosticEvent({ |
| 1458 | +type: "run.completed", |
| 1459 | +runId: "run-1", |
| 1460 | +provider: "openai", |
| 1461 | +model: "gpt-5.4", |
| 1462 | +outcome: "completed", |
| 1463 | +durationMs: 100, |
| 1464 | +trace: { |
| 1465 | +traceId: TRACE_ID, |
| 1466 | +spanId: CHILD_SPAN_ID, |
| 1467 | +traceFlags: "01", |
| 1468 | +}, |
| 1469 | +}); |
| 1470 | +emitTrustedDiagnosticEvent({ |
| 1471 | +type: "model.call.completed", |
| 1472 | +runId: "run-1", |
| 1473 | +callId: "call-1", |
| 1474 | +provider: "openai", |
| 1475 | +model: "gpt-5.4", |
| 1476 | +durationMs: 80, |
| 1477 | +trace: { |
| 1478 | +traceId: TRACE_ID, |
| 1479 | +spanId: GRANDCHILD_SPAN_ID, |
| 1480 | +traceFlags: "01", |
| 1481 | +}, |
| 1482 | +}); |
| 1483 | +await flushDiagnosticEvents(); |
| 1484 | + |
| 1485 | +expect(telemetryState.tracer.setSpanContext).not.toHaveBeenCalled(); |
| 1486 | +const parentBySpanName = Object.fromEntries( |
| 1487 | +telemetryState.tracer.startSpan.mock.calls.map((call) => [call[0], call[2]]), |
| 1488 | +); |
| 1489 | +expect(parentBySpanName).toMatchObject({ |
| 1490 | +"openclaw.run": undefined, |
| 1491 | +"openclaw.model.call": undefined, |
| 1492 | +}); |
| 1493 | +await service.stop?.(ctx); |
| 1494 | +}); |
| 1495 | + |
1452 | 1496 | test("does not parent untrusted diagnostic lifecycle spans from injected trace ids", async () => { |
1453 | 1497 | const service = createDiagnosticsOtelService(); |
1454 | 1498 | const ctx = createOtelContext(OTEL_TEST_ENDPOINT, { traces: true, metrics: true }); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。