Skip to content

Commit 8057584

Browse files
committed
test: assert breadcrumbs first
1 parent 5c7772d commit 8057584

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

dev-packages/e2e-tests/test-applications/nextjs-16/tests/middleware.test.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ test('Faulty middlewares', async ({ request }) => {
6262
test('Should trace outgoing fetch requests inside middleware and create breadcrumbs for it', async ({ request }) => {
6363
test.skip(isDevMode, 'The fetch requests ends up in a separate tx in dev atm');
6464

65-
// First, let's see what middleware transactions we get
66-
// FIXME: Remove this once we know what's going on
6765
const allMiddlewareTransactions: Event[] = [];
6866
const middlewareTransactionPromise = waitForTransaction('nextjs-16', async transactionEvent => {
6967
console.log('Transaction event:', transactionEvent?.transaction);
@@ -75,9 +73,21 @@ test('Should trace outgoing fetch requests inside middleware and create breadcru
7573
);
7674

7775
const hasHttpClientSpan = !!transactionEvent.spans?.find(span => span.op === 'http.client');
78-
if (hasHttpClientSpan) {
79-
return true;
76+
77+
// Add diagnostic logging when span is missing to help debug CI failures
78+
if (!hasHttpClientSpan) {
79+
console.warn('[TEST] Middleware transaction found but missing http.client span');
80+
console.warn(
81+
'[TEST] Available spans:',
82+
transactionEvent.spans?.map(s => ({ op: s.op, description: s.description })),
83+
);
84+
console.warn(
85+
'[TEST] Breadcrumbs:',
86+
transactionEvent.breadcrumbs?.filter(b => b.category === 'http'),
87+
);
8088
}
89+
90+
return hasHttpClientSpan;
8191
}
8292
return false;
8393
});
@@ -90,6 +100,21 @@ test('Should trace outgoing fetch requests inside middleware and create breadcru
90100

91101
const middlewareTransaction = await middlewareTransactionPromise;
92102

103+
// Assert breadcrumbs FIRST - these are more reliable as they don't depend on OTEL instrumentation
104+
expect(middlewareTransaction.breadcrumbs).toEqual(
105+
expect.arrayContaining([
106+
{
107+
category: 'http',
108+
data: { 'http.method': 'GET', status_code: 200, url: 'http://localhost:3030/' },
109+
timestamp: expect.any(Number),
110+
type: 'http',
111+
},
112+
]),
113+
);
114+
115+
// Assert the http.client span exists
116+
// This tests that OTEL fetch instrumentation is working in Next.js middleware
117+
// If this fails consistently in CI but breadcrumbs pass, it indicates a real instrumentation bug
93118
expect(middlewareTransaction.spans).toEqual(
94119
expect.arrayContaining([
95120
{
@@ -123,15 +148,4 @@ test('Should trace outgoing fetch requests inside middleware and create breadcru
123148
},
124149
]),
125150
);
126-
127-
expect(middlewareTransaction.breadcrumbs).toEqual(
128-
expect.arrayContaining([
129-
{
130-
category: 'http',
131-
data: { 'http.method': 'GET', status_code: 200, url: 'http://localhost:3030/' },
132-
timestamp: expect.any(Number),
133-
type: 'http',
134-
},
135-
]),
136-
);
137151
});

0 commit comments

Comments
 (0)