Skip to content

Commit 1304a2b

Browse files
committed
add node handler unit tests
1 parent ac1b7c8 commit 1304a2b

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

packages/node/test/handlers.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as sentryCore from '@sentry/core';
22
import * as sentryHub from '@sentry/hub';
33
import { Hub } from '@sentry/hub';
44
import { Transaction } from '@sentry/tracing';
5-
import { Runtime } from '@sentry/types';
5+
import { Baggage, Runtime } from '@sentry/types';
66
import { SentryError } from '@sentry/utils';
77
import * as http from 'http';
88
import * as net from 'net';
@@ -368,6 +368,41 @@ describe('tracingHandler', () => {
368368
expect(transaction.traceId).toEqual('12312012123120121231201212312012');
369369
expect(transaction.parentSpanId).toEqual('1121201211212012');
370370
expect(transaction.sampled).toEqual(false);
371+
expect(transaction.metadata?.baggage).toBeUndefined();
372+
});
373+
374+
it("pulls parent's data from tracing and baggage headers on the request", () => {
375+
req.headers = {
376+
'sentry-trace': '12312012123120121231201212312012-1121201211212012-0',
377+
baggage: 'sentry-version=1.0,sentry-environment=production',
378+
};
379+
380+
sentryTracingMiddleware(req, res, next);
381+
382+
const transaction = (res as any).__sentry_transaction;
383+
384+
// since we have no tracesSampler defined, the default behavior (inherit if possible) applies
385+
expect(transaction.traceId).toEqual('12312012123120121231201212312012');
386+
expect(transaction.parentSpanId).toEqual('1121201211212012');
387+
expect(transaction.sampled).toEqual(false);
388+
expect(transaction.metadata?.baggage).toBeDefined();
389+
expect(transaction.metadata?.baggage).toEqual([{ version: '1.0', environment: 'production' }, ''] as Baggage);
390+
});
391+
392+
it("pulls parent's baggage (sentry + third party entries) headers on the request", () => {
393+
req.headers = {
394+
baggage: 'sentry-version=1.0,sentry-environment=production,dogs=great,cats=boring',
395+
};
396+
397+
sentryTracingMiddleware(req, res, next);
398+
399+
const transaction = (res as any).__sentry_transaction;
400+
401+
expect(transaction.metadata?.baggage).toBeDefined();
402+
expect(transaction.metadata?.baggage).toEqual([
403+
{ version: '1.0', environment: 'production' },
404+
'dogs=great,cats=boring',
405+
] as Baggage);
371406
});
372407

373408
it('extracts request data for sampling context', () => {

0 commit comments

Comments
 (0)