Skip to content

Commit 8e78e7c

Browse files
committed
Improve node and tracing tests
1 parent d243198 commit 8e78e7c

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

packages/node/test/integrations/http.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ describe('tracing', () => {
2121
dsn: 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012',
2222
tracesSampleRate: 1.0,
2323
integrations: [new HttpIntegration({ tracing: true })],
24+
release: '1.0.0',
25+
environment: 'production',
2426
});
2527
const hub = new Hub(new NodeClient(options));
2628
addExtensionMethods();
@@ -96,8 +98,7 @@ describe('tracing', () => {
9698
const baggageHeader = request.getHeader('baggage') as string;
9799

98100
expect(baggageHeader).toBeDefined();
99-
// this might change once we actually add our baggage data to the header
100-
expect(baggageHeader).toEqual('');
101+
expect(baggageHeader).toEqual('sentry-environment=production,sentry-release=1.0.0');
101102
});
102103

103104
it('propagates 3rd party baggage header data to outgoing non-sentry requests', async () => {
@@ -109,8 +110,7 @@ describe('tracing', () => {
109110
const baggageHeader = request.getHeader('baggage') as string;
110111

111112
expect(baggageHeader).toBeDefined();
112-
// this might change once we actually add our baggage data to the header
113-
expect(baggageHeader).toEqual('dog=great');
113+
expect(baggageHeader).toEqual('dog=great,sentry-environment=production,sentry-release=1.0.0');
114114
});
115115

116116
it("doesn't attach the sentry-trace header to outgoing sentry requests", () => {

packages/tracing/test/browser/browsertracing.test.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BrowserClient } from '@sentry/browser';
22
import { Hub, makeMain } from '@sentry/hub';
3-
import { BaggageObj } from '@sentry/types';
3+
import type { BaggageObj, BaseTransportOptions, ClientOptions } from '@sentry/types';
44
import { getGlobalObject, InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';
55
import { JSDOM } from 'jsdom';
66

@@ -415,7 +415,16 @@ describe('BrowserTracing', () => {
415415
});
416416
});
417417

418-
describe('using the data', () => {
418+
describe('using the <meta> tag data', () => {
419+
beforeEach(() => {
420+
hub.getClient()!.getOptions = () => {
421+
return {
422+
release: '1.0.0',
423+
environment: 'production',
424+
} as ClientOptions<BaseTransportOptions>;
425+
};
426+
});
427+
419428
it('uses the tracing data for pageload transactions', () => {
420429
// make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one
421430
document.head.innerHTML =
@@ -439,11 +448,34 @@ describe('BrowserTracing', () => {
439448
expect(baggage[1]).toEqual('foo=bar');
440449
});
441450

451+
it('adds Sentry baggage data to pageload transactions if not present in meta tags', () => {
452+
// make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one
453+
document.head.innerHTML =
454+
'<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">' +
455+
'<meta name="baggage" content="foo=bar">';
456+
457+
// pageload transactions are created as part of the BrowserTracing integration's initialization
458+
createBrowserTracing(true);
459+
const transaction = getActiveTransaction(hub) as IdleTransaction;
460+
const baggage = transaction.getBaggage()!;
461+
462+
expect(transaction).toBeDefined();
463+
expect(transaction.op).toBe('pageload');
464+
expect(transaction.traceId).toEqual('12312012123120121231201212312012');
465+
expect(transaction.parentSpanId).toEqual('1121201211212012');
466+
expect(transaction.sampled).toBe(false);
467+
expect(baggage).toBeDefined();
468+
expect(baggage[0]).toBeDefined();
469+
expect(baggage[0]).toEqual({ environment: 'production', release: '1.0.0' });
470+
expect(baggage[1]).toBeDefined();
471+
expect(baggage[1]).toEqual('foo=bar');
472+
});
473+
442474
it('ignores the data for navigation transactions', () => {
443475
mockChangeHistory = () => undefined;
444476
document.head.innerHTML =
445477
'<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">' +
446-
'<meta name="baggage" content="sentry-release=2.1.14,foo=bar">';
478+
'<meta name="baggage" content="sentry-release=2.1.14">';
447479

448480
createBrowserTracing(true);
449481

@@ -455,7 +487,11 @@ describe('BrowserTracing', () => {
455487
expect(transaction.op).toBe('navigation');
456488
expect(transaction.traceId).not.toEqual('12312012123120121231201212312012');
457489
expect(transaction.parentSpanId).toBeUndefined();
458-
expect(baggage).toBeUndefined();
490+
expect(baggage).toBeDefined();
491+
expect(baggage[0]).toBeDefined();
492+
expect(baggage[0]).toEqual({ release: '1.0.0', environment: 'production' });
493+
expect(baggage[1]).toBeDefined();
494+
expect(baggage[1]).toEqual('');
459495
});
460496
});
461497
});

0 commit comments

Comments
 (0)