Skip to content

Commit 3dd7943

Browse files
committed
update test based on PR review feedback
1 parent 3931a20 commit 3dd7943

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

packages/node/test/integrations/undici.test.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,6 @@ conditionalTest({ min: 16 })('Undici integration', () => {
136136
expect(transaction.spanRecorder?.spans.length).toBe(1);
137137
});
138138

139-
it('does not create a span for sentry requests', async () => {
140-
const transaction = hub.startTransaction({ name: 'test-transaction' }) as Transaction;
141-
hub.getScope().setSpan(transaction);
142-
143-
expect(transaction.spanRecorder?.spans.length).toBe(1);
144-
145-
try {
146-
await fetch(`${SENTRY_DSN}/sub/route`, {
147-
method: 'POST',
148-
});
149-
} catch (e) {
150-
// ignore
151-
}
152-
153-
expect(transaction.spanRecorder?.spans.length).toBe(1);
154-
});
155-
156139
it('does not create a span if there is no active spans', async () => {
157140
try {
158141
await fetch(`${SENTRY_DSN}/sub/route`, { method: 'POST' });
@@ -194,6 +177,24 @@ conditionalTest({ min: 16 })('Undici integration', () => {
194177
);
195178
});
196179

180+
it('does not attach headers if `shouldCreateSpanForRequest` does not create a span', async () => {
181+
const transaction = hub.startTransaction({ name: 'test-transaction' }) as Transaction;
182+
hub.getScope().setSpan(transaction);
183+
184+
const client = new NodeClient({ ...DEFAULT_OPTIONS, shouldCreateSpanForRequest: url => url.includes('yes') });
185+
hub.bindClient(client);
186+
187+
await fetch('http://localhost:18099/no', { method: 'POST' });
188+
189+
expect(requestHeaders['sentry-trace']).toBeUndefined();
190+
expect(requestHeaders['baggage']).toBeUndefined();
191+
192+
await fetch('http://localhost:18099/yes', { method: 'POST' });
193+
194+
expect(requestHeaders['sentry-trace']).toBeDefined();
195+
expect(requestHeaders['baggage']).toBeDefined();
196+
});
197+
197198
it('uses tracePropagationTargets', async () => {
198199
const transaction = hub.startTransaction({ name: 'test-transaction' }) as Transaction;
199200
hub.getScope().setSpan(transaction);

0 commit comments

Comments
 (0)