Uh oh!
There was an error while loading. Please reload this page.
test(e2e): Port cloudflare-autoinstrument to span streaming - #23861
Conversation
size-limit report 📦
|
07903f7 to
a44c247Comparea44c247 to
71e611bCompare71e611b to
6a8bb1cCompare6a8bb1c to
6c19779CompareUh oh!
There was an error while loading. Please reload this page.
| event.transaction === 'webSocketMessage' && | ||
| (event.spans ?? []).some(span => span.op === 'rpc' && span.description === 'greet') | ||
| !!rpcSpan && | ||
| spans.some(span => span.is_segment && span.name === 'webSocketMessage' && span.trace_id === rpcSpan.trace_id) |
There was a problem hiding this comment.
If you rebase on develop, the traceid distinction is no longer needed.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
6c19779 to
116adf9Compare| spans => | ||
| spans.some( | ||
| span => | ||
| getSpanOp(span) === 'rpc' && | ||
| span.name === 'greet' && |
There was a problem hiding this comment.
Bug: The waitForStreamedSpan test utility lacks trace isolation, which can cause race conditions and flaky results when tests are run in parallel.
Severity: MEDIUM
Suggested Fix
Modify waitForStreamedSpan to implement trace isolation. It should group spans by trace_id before evaluating them, similar to how collectStreamedSpans is implemented. This will ensure that the function only resolves with a span that belongs to the same trace as the action that triggered it, preventing cross-test contamination during parallel execution.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location:
dev-packages/e2e-tests/test-applications/cloudflare-autoinstrument/tests/autoinstrument.test.ts#L60-L64
Potential issue: The `waitForStreamedSpan` test utility function lacks trace isolation.
It filters incoming spans by a timestamp but not by `trace_id`. When tests are run in
parallel, as configured with `workers: '100%'`, a race condition can occur. If two tests
concurrently make requests that generate similar spans, the test calling
`waitForStreamedSpan` may incorrectly capture and validate a span generated by the other
test. This can lead to flaky tests that pass or fail based on timing and not because
their own specific action was correctly instrumented.
Uh oh!
There was an error while loading. Please reload this page.
Ports
cloudflare-autoinstrumentto span streaming (pin removed fromsrc/instrument.server.ts).environment: 'qa'proof now reads thesentry.environmentspan attribute.greetrpc span directly and usecollectStreamedSpansuntil the owningwebSocketMessagesegment of the same trace has arrived, since the child is streamed before its segment./plain-dosegment.