|
1 |
| -import { defaultTextMapGetter, defaultTextMapSetter, ROOT_CONTEXT, trace, TraceFlags } from '@opentelemetry/api'; |
| 1 | +import { |
| 2 | + defaultTextMapGetter, |
| 3 | + defaultTextMapSetter, |
| 4 | + propagation, |
| 5 | + ROOT_CONTEXT, |
| 6 | + trace, |
| 7 | + TraceFlags, |
| 8 | +} from '@opentelemetry/api'; |
2 | 9 | import { suppressTracing } from '@opentelemetry/core';
|
3 | 10 | import { Hub, makeMain } from '@sentry/core';
|
4 | 11 | import { addExtensionMethods, Transaction } from '@sentry/tracing';
|
@@ -138,6 +145,27 @@ describe('SentryPropagator', () => {
|
138 | 145 | expect(carrier[SENTRY_TRACE_HEADER]).toBe(sentryTrace);
|
139 | 146 | });
|
140 | 147 |
|
| 148 | + it('should include existing baggage', () => { |
| 149 | + const transactionContext = { |
| 150 | + name: 'sampled-transaction', |
| 151 | + traceId: 'd4cda95b652f4a1592b449d5929fda1b', |
| 152 | + spanId: '6e0c63257de34c92', |
| 153 | + sampled: true, |
| 154 | + }; |
| 155 | + const spanContext = { |
| 156 | + traceId: 'd4cda95b652f4a1592b449d5929fda1b', |
| 157 | + spanId: '6e0c63257de34c92', |
| 158 | + traceFlags: TraceFlags.SAMPLED, |
| 159 | + }; |
| 160 | + createTransactionAndMaybeSpan(type, transactionContext); |
| 161 | + const context = trace.setSpanContext(ROOT_CONTEXT, spanContext); |
| 162 | + const baggage = propagation.createBaggage({ foo: { value: 'bar' } }); |
| 163 | + propagator.inject(propagation.setBaggage(context, baggage), carrier, defaultTextMapSetter); |
| 164 | + expect(carrier[SENTRY_BAGGAGE_HEADER]).toBe( |
| 165 | + 'foo=bar,sentry-environment=production,sentry-release=1.0.0,sentry-transaction=sampled-transaction,sentry-public_key=abc,sentry-trace_id=d4cda95b652f4a1592b449d5929fda1b', |
| 166 | + ); |
| 167 | + }); |
| 168 | + |
141 | 169 | it('should NOT set baggage and sentry-trace header if instrumentation is supressed', () => {
|
142 | 170 | const spanContext = {
|
143 | 171 | traceId: 'd4cda95b652f4a1592b449d5929fda1b',
|
|
0 commit comments