Unverified Commit fff74ebf authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Isolate scoped trace collector failures

Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent a62a1f96
...@@ -117,6 +117,31 @@ describe('span recording', () => { ...@@ -117,6 +117,31 @@ describe('span recording', () => {
expect(getRequestInsightsSnapshot()).toEqual({ requests: [] }) expect(getRequestInsightsSnapshot()).toEqual({ requests: [] })
}) })
it('does not let a failing scoped sink interrupt span completion or the batch', () => {
const records: SpanStoreRecord[] = []
setSpanRecorderForTest((span) => records.push(span))
const sink = jest.fn(() => {
throw new Error('failed scoped sink')
})
const spans = [
{ name: 'first', timestamp: 1 },
{ name: 'second', timestamp: 2 },
]
const record = runWithLocalSpanSink(sink, captureLocalSpanRecorder)
expect(() => record(spans)).not.toThrow()
expect(sink).toHaveBeenCalledTimes(2)
expect(records).toEqual(spans)
expect(() =>
runWithLocalSpanSink(sink, () => recordSpan({ name: 'completed' }))
).not.toThrow()
expect(records.map((span) => span.name)).toEqual([
'first',
'second',
'completed',
])
})
it('keeps concurrent local span sinks isolated', async () => { it('keeps concurrent local span sinks isolated', async () => {
const firstRecords: SpanStoreRecord[] = [] const firstRecords: SpanStoreRecord[] = []
const secondRecords: SpanStoreRecord[] = [] const secondRecords: SpanStoreRecord[] = []
......
...@@ -106,7 +106,11 @@ function exportSpans( ...@@ -106,7 +106,11 @@ function exportSpans(
} }
for (const span of spans) { for (const span of spans) {
localSpanSink?.(span) try {
localSpanSink?.(span)
} catch {
// A scoped collector must not interrupt application work or later spans.
}
spanRecorderForTest?.(span) spanRecorderForTest?.(span)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment