|
7 | 7 | BrowserTracing,
|
8 | 8 | BrowserTracingOptions,
|
9 | 9 | DEFAULT_MAX_TRANSACTION_DURATION_SECONDS,
|
| 10 | + getHeaderContext, |
10 | 11 | getMetaContent,
|
11 | 12 | } from '../../src/browser/browsertracing';
|
12 | 13 | import { defaultRequestInstrumentionOptions } from '../../src/browser/request';
|
@@ -379,5 +380,65 @@ describe('BrowserTracing', () => {
|
379 | 380 | expect(metaTagValue).toBe(content);
|
380 | 381 | });
|
381 | 382 | });
|
| 383 | + |
| 384 | + describe('getHeaderContext', () => { |
| 385 | + it('correctly parses a valid sentry-trace meta header', () => { |
| 386 | + document.head.innerHTML = `<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">`; |
| 387 | + |
| 388 | + const headerContext = getHeaderContext(); |
| 389 | + |
| 390 | + expect(headerContext).toBeDefined(); |
| 391 | + expect(headerContext!.traceId).toEqual('12312012123120121231201212312012'); |
| 392 | + expect(headerContext!.parentSpanId).toEqual('1121201211212012'); |
| 393 | + expect(headerContext!.parentSampled).toEqual(false); |
| 394 | + }); |
| 395 | + |
| 396 | + it('returns undefined if the header is malformed', () => { |
| 397 | + document.head.innerHTML = `<meta name="sentry-trace" content="12312012-112120121-0">`; |
| 398 | + |
| 399 | + const headerContext = getHeaderContext(); |
| 400 | + |
| 401 | + expect(headerContext).toBeUndefined(); |
| 402 | + }); |
| 403 | + |
| 404 | + it("returns undefined if the header isn't there", () => { |
| 405 | + document.head.innerHTML = `<meta name="dogs" content="12312012123120121231201212312012-1121201211212012-0">`; |
| 406 | + |
| 407 | + const headerContext = getHeaderContext(); |
| 408 | + |
| 409 | + expect(headerContext).toBeUndefined(); |
| 410 | + }); |
| 411 | + }); |
| 412 | + |
| 413 | + describe('using the data', () => { |
| 414 | + it('uses the data for pageload transactions', () => { |
| 415 | + document.head.innerHTML = `<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">`; |
| 416 | + |
| 417 | + // pageload transactions are created as part of the BrowserTracing integration's initialization |
| 418 | + createBrowserTracing(true); |
| 419 | + const transaction = getActiveTransaction(hub) as IdleTransaction; |
| 420 | + |
| 421 | + expect(transaction).toBeDefined(); |
| 422 | + expect(transaction.op).toBe('pageload'); |
| 423 | + expect(transaction.traceId).toEqual('12312012123120121231201212312012'); |
| 424 | + expect(transaction.parentSpanId).toEqual('1121201211212012'); |
| 425 | + expect(transaction.sampled).toBe(false); |
| 426 | + }); |
| 427 | + |
| 428 | + it('ignores the data for navigation transactions', () => { |
| 429 | + mockChangeHistory = () => undefined; |
| 430 | + document.head.innerHTML = `<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">`; |
| 431 | + |
| 432 | + createBrowserTracing(true); |
| 433 | + |
| 434 | + mockChangeHistory({ to: 'here', from: 'there' }); |
| 435 | + const transaction = getActiveTransaction(hub) as IdleTransaction; |
| 436 | + |
| 437 | + expect(transaction).toBeDefined(); |
| 438 | + expect(transaction.op).toBe('navigation'); |
| 439 | + expect(transaction.traceId).not.toEqual('12312012123120121231201212312012'); |
| 440 | + expect(transaction.parentSpanId).toBeUndefined(); |
| 441 | + }); |
| 442 | + }); |
382 | 443 | });
|
383 | 444 | });
|
0 commit comments