|
| 1 | +import { Carrier, getCurrentHub, getMainCarrier } from '@sentry/core'; |
| 2 | +import { Transaction } from '@sentry/tracing'; |
| 3 | +import { Hub } from '@sentry/types'; |
| 4 | + |
| 5 | +import { _addTracingExtensions, StartTransactionFunction } from '../src/js/measurements'; |
| 6 | + |
| 7 | +describe('Tracing extensions', () => { |
| 8 | + let hub: Hub; |
| 9 | + let carrier: Carrier; |
| 10 | + let startTransaction: StartTransactionFunction | undefined; |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + _addTracingExtensions(); |
| 14 | + hub = getCurrentHub(); |
| 15 | + carrier = getMainCarrier(); |
| 16 | + startTransaction = carrier.__SENTRY__?.extensions?.startTransaction as StartTransactionFunction | undefined; |
| 17 | + }); |
| 18 | + |
| 19 | + test('transaction has default op', async () => { |
| 20 | + const transaction: Transaction = startTransaction?.apply(hub, [{}]); |
| 21 | + |
| 22 | + expect(transaction).toEqual(expect.objectContaining({ op: 'default' })); |
| 23 | + }); |
| 24 | + |
| 25 | + test('transaction does not overwrite custom op', async () => { |
| 26 | + const transaction: Transaction = startTransaction?.apply(hub, [{ op: 'custom' }]); |
| 27 | + |
| 28 | + expect(transaction).toEqual(expect.objectContaining({ op: 'custom' })); |
| 29 | + }); |
| 30 | + |
| 31 | + test('transaction start span creates default op', async () => { |
| 32 | + const transaction: Transaction = startTransaction?.apply(hub, [{ op: 'custom' }]); |
| 33 | + const span = transaction?.startChild(); |
| 34 | + |
| 35 | + expect(span).toEqual(expect.objectContaining({ op: 'default' })); |
| 36 | + }); |
| 37 | + |
| 38 | + test('transaction start span keeps custom op', async () => { |
| 39 | + const transaction: Transaction = startTransaction?.apply(hub, [{ op: 'custom' }]); |
| 40 | + const span = transaction?.startChild({ op: 'custom' }); |
| 41 | + |
| 42 | + expect(span).toEqual(expect.objectContaining({ op: 'custom' })); |
| 43 | + }); |
| 44 | + |
| 45 | + test('transaction start span passes correct values to the child', async () => { |
| 46 | + const transaction: Transaction = startTransaction?.apply(hub, [{ op: 'custom' }]); |
| 47 | + const span = transaction?.startChild({ op: 'custom' }); |
| 48 | + |
| 49 | + expect(span).toEqual(expect.objectContaining({ |
| 50 | + transaction, |
| 51 | + parentSpanId: transaction.spanId, |
| 52 | + sampled: transaction.sampled, |
| 53 | + traceId: transaction.traceId, |
| 54 | + })); |
| 55 | + }); |
| 56 | +}); |
0 commit comments