|
1 | 1 | import { Hub, Scope } from '@sentry/hub';
|
2 |
| -import { Event, Severity } from '@sentry/types'; |
| 2 | +import { Event, Severity, Span } from '@sentry/types'; |
3 | 3 | import { SentryError } from '@sentry/utils';
|
4 | 4 |
|
5 | 5 | import { TestBackend } from '../mocks/backend';
|
@@ -570,6 +570,54 @@ describe('BaseClient', () => {
|
570 | 570 | });
|
571 | 571 | });
|
572 | 572 |
|
| 573 | + test('normalization applies to Transaction and Span consistently', () => { |
| 574 | + expect.assertions(1); |
| 575 | + const client = new TestClient({ dsn: PUBLIC_DSN }); |
| 576 | + const transaction: Event = { |
| 577 | + contexts: { |
| 578 | + trace: { |
| 579 | + data: { _sentry_web_vitals: { LCP: { value: 99.9 } } }, |
| 580 | + op: 'pageload', |
| 581 | + span_id: 'a3df84a60c2e4e76', |
| 582 | + trace_id: '86f39e84263a4de99c326acab3bfe3bd', |
| 583 | + }, |
| 584 | + }, |
| 585 | + event_id: '972f45b826a248bba98e990878a177e1', |
| 586 | + spans: [ |
| 587 | + ({ |
| 588 | + data: { _sentry_extra_metrics: { M1: { value: 1 }, M2: { value: 2 } } }, |
| 589 | + description: 'first-paint', |
| 590 | + endTimestamp: 1591603196.637835, |
| 591 | + op: 'paint', |
| 592 | + parentSpanId: 'a3df84a60c2e4e76', |
| 593 | + spanId: '9e15bf99fbe4bc80', |
| 594 | + startTimestamp: 1591603196.637835, |
| 595 | + traceId: '86f39e84263a4de99c326acab3bfe3bd', |
| 596 | + } as any) as Span, // `as any` to bypass linter https://palantir.github.io/tslint/rules/no-object-literal-type-assertion/ |
| 597 | + ({ |
| 598 | + description: 'first-contentful-paint', |
| 599 | + endTimestamp: 1591603196.637835, |
| 600 | + op: 'paint', |
| 601 | + parentSpanId: 'a3df84a60c2e4e76', |
| 602 | + spanId: 'aa554c1f506b0783', |
| 603 | + startTimestamp: 1591603196.637835, |
| 604 | + traceId: '86f39e84263a4de99c326acab3bfe3bd', |
| 605 | + } as any) as Span, |
| 606 | + ], |
| 607 | + start_timestamp: 1591603196.614865, |
| 608 | + timestamp: 1591603196.728485, |
| 609 | + transaction: '/', |
| 610 | + type: 'transaction', |
| 611 | + }; |
| 612 | + // To be consistent, normalization could apply either to both transactions |
| 613 | + // and spans, or to none. So far the decision is to skip normalization for |
| 614 | + // both, such that the expected normalizedTransaction is the same as the |
| 615 | + // input transaction. |
| 616 | + const normalizedTransaction = JSON.parse(JSON.stringify(transaction)); // deep-copy |
| 617 | + client.captureEvent(transaction); |
| 618 | + expect(TestBackend.instance!.event!).toEqual(normalizedTransaction); |
| 619 | + }); |
| 620 | + |
573 | 621 | test('calls beforeSend and uses original event without any changes', () => {
|
574 | 622 | expect.assertions(1);
|
575 | 623 | const beforeSend = jest.fn(event => event);
|
|
0 commit comments