Skip to content

Commit

Permalink
Improve node and tracing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Jun 2, 2022
1 parent d243198 commit 8e78e7c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/node/test/integrations/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ describe('tracing', () => {
dsn: 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012',
tracesSampleRate: 1.0,
integrations: [new HttpIntegration({ tracing: true })],
release: '1.0.0',
environment: 'production',
});
const hub = new Hub(new NodeClient(options));
addExtensionMethods();
Expand Down Expand Up @@ -96,8 +98,7 @@ describe('tracing', () => {
const baggageHeader = request.getHeader('baggage') as string;

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

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

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

it("doesn't attach the sentry-trace header to outgoing sentry requests", () => {
Expand Down
44 changes: 40 additions & 4 deletions packages/tracing/test/browser/browsertracing.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BrowserClient } from '@sentry/browser';
import { Hub, makeMain } from '@sentry/hub';
import { BaggageObj } from '@sentry/types';
import type { BaggageObj, BaseTransportOptions, ClientOptions } from '@sentry/types';
import { getGlobalObject, InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';
import { JSDOM } from 'jsdom';

Expand Down Expand Up @@ -415,7 +415,16 @@ describe('BrowserTracing', () => {
});
});

describe('using the data', () => {
describe('using the <meta> tag data', () => {
beforeEach(() => {
hub.getClient()!.getOptions = () => {
return {
release: '1.0.0',
environment: 'production',
} as ClientOptions<BaseTransportOptions>;
};
});

it('uses the tracing data for pageload transactions', () => {
// make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one
document.head.innerHTML =
Expand All @@ -439,11 +448,34 @@ describe('BrowserTracing', () => {
expect(baggage[1]).toEqual('foo=bar');
});

it('adds Sentry baggage data to pageload transactions if not present in meta tags', () => {
// make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one
document.head.innerHTML =
'<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">' +
'<meta name="baggage" content="foo=bar">';

// pageload transactions are created as part of the BrowserTracing integration's initialization
createBrowserTracing(true);
const transaction = getActiveTransaction(hub) as IdleTransaction;
const baggage = transaction.getBaggage()!;

expect(transaction).toBeDefined();
expect(transaction.op).toBe('pageload');
expect(transaction.traceId).toEqual('12312012123120121231201212312012');
expect(transaction.parentSpanId).toEqual('1121201211212012');
expect(transaction.sampled).toBe(false);
expect(baggage).toBeDefined();
expect(baggage[0]).toBeDefined();
expect(baggage[0]).toEqual({ environment: 'production', release: '1.0.0' });
expect(baggage[1]).toBeDefined();
expect(baggage[1]).toEqual('foo=bar');
});

it('ignores the data for navigation transactions', () => {
mockChangeHistory = () => undefined;
document.head.innerHTML =
'<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">' +
'<meta name="baggage" content="sentry-release=2.1.14,foo=bar">';
'<meta name="baggage" content="sentry-release=2.1.14">';

createBrowserTracing(true);

Expand All @@ -455,7 +487,11 @@ describe('BrowserTracing', () => {
expect(transaction.op).toBe('navigation');
expect(transaction.traceId).not.toEqual('12312012123120121231201212312012');
expect(transaction.parentSpanId).toBeUndefined();
expect(baggage).toBeUndefined();
expect(baggage).toBeDefined();
expect(baggage[0]).toBeDefined();
expect(baggage[0]).toEqual({ release: '1.0.0', environment: 'production' });
expect(baggage[1]).toBeDefined();
expect(baggage[1]).toEqual('');
});
});
});
Expand Down

0 comments on commit 8e78e7c

Please sign in to comment.