|
1 | 1 | import { BrowserClient } from '@sentry/browser';
|
2 | 2 | import { Hub, Scope } from '@sentry/hub';
|
| 3 | +import * as hubPackage from '@sentry/hub'; |
3 | 4 |
|
4 | 5 | import { Span, SpanStatus, Transaction } from '../src';
|
5 |
| -import { SENTRY_TRACE_REGEX } from '../src/utils'; |
| 6 | +import { computeTracestateValue, SENTRY_TRACE_REGEX } from '../src/utils'; |
6 | 7 |
|
7 | 8 | describe('Span', () => {
|
8 | 9 | let hub: Hub;
|
@@ -101,6 +102,48 @@ describe('Span', () => {
|
101 | 102 | });
|
102 | 103 | });
|
103 | 104 |
|
| 105 | + describe('toTracestate', () => { |
| 106 | + const publicKey = 'dogsarebadatkeepingsecrets'; |
| 107 | + const release = 'off.leash.trail'; |
| 108 | + const environment = 'dogpark'; |
| 109 | + const traceId = '12312012123120121231201212312012'; |
| 110 | + |
| 111 | + const computedTracestate = `sentry=${computeTracestateValue({ traceId, environment, release, publicKey })}`; |
| 112 | + const thirdpartyData = 'maisey=silly,charlie=goofy'; |
| 113 | + |
| 114 | + const hub = new Hub( |
| 115 | + new BrowserClient({ |
| 116 | + dsn: 'https://[email protected]/12312012', |
| 117 | + tracesSampleRate: 1, |
| 118 | + release, |
| 119 | + environment, |
| 120 | + }), |
| 121 | + ); |
| 122 | + |
| 123 | + test('no third-party data', () => { |
| 124 | + const transaction = new Transaction({ name: 'FETCH /ball', traceId }, hub); |
| 125 | + const span = transaction.startChild({ op: 'dig.hole' }); |
| 126 | + |
| 127 | + expect(span.toTracestate()).toEqual(computedTracestate); |
| 128 | + }); |
| 129 | + |
| 130 | + test('third-party data', () => { |
| 131 | + const transaction = new Transaction({ name: 'FETCH /ball' }, hub); |
| 132 | + transaction.setMetadata({ tracestate: { sentry: computedTracestate, thirdparty: thirdpartyData } }); |
| 133 | + const span = transaction.startChild({ op: 'dig.hole' }); |
| 134 | + |
| 135 | + expect(span.toTracestate()).toEqual(`${computedTracestate},${thirdpartyData}`); |
| 136 | + }); |
| 137 | + |
| 138 | + test('orphan span', () => { |
| 139 | + jest.spyOn(hubPackage, 'getCurrentHub').mockReturnValueOnce(hub); |
| 140 | + const span = new Span({ op: 'dig.hole' }); |
| 141 | + span.traceId = traceId; |
| 142 | + |
| 143 | + expect(span.toTracestate()).toEqual(computedTracestate); |
| 144 | + }); |
| 145 | + }); |
| 146 | + |
104 | 147 | describe('getTraceHeaders', () => {
|
105 | 148 | it('returns correct headers', () => {
|
106 | 149 | const hub = new Hub(
|
|
0 commit comments