|
1 | 1 | import type { Span } from '@sentry/core'; |
2 | | -import { addChildSpanToSpan, SentrySpan, spanToJSON, timestampInSeconds } from '@sentry/core'; |
| 2 | +import { addChildSpanToSpan, debug, SentrySpan, spanToJSON, timestampInSeconds } from '@sentry/core'; |
3 | 3 | import { beforeEach, describe, expect, it, vi } from 'vitest'; |
4 | 4 | import { BrowserClient } from '../../src'; |
5 | 5 | import type { PreviousTraceInfo } from '../../src/tracing/linkedTraces'; |
@@ -201,6 +201,47 @@ describe('addPreviousTraceSpanLink', () => { |
201 | 201 | }); |
202 | 202 | }); |
203 | 203 |
|
| 204 | + it('logs a debug message when adding a previous trace link (with stringified context)', () => { |
| 205 | + const debugLogSpy = vi.spyOn(debug, 'log'); |
| 206 | + |
| 207 | + const currentSpanStart = timestampInSeconds(); |
| 208 | + |
| 209 | + const previousTraceInfo: PreviousTraceInfo = { |
| 210 | + spanContext: { traceId: '123', spanId: '456', traceFlags: 1 }, |
| 211 | + startTimestamp: currentSpanStart - PREVIOUS_TRACE_MAX_DURATION + 1, |
| 212 | + sampleRand: 0.0126, |
| 213 | + sampleRate: 0.5, |
| 214 | + }; |
| 215 | + |
| 216 | + const currentSpan = new SentrySpan({ |
| 217 | + name: 'test', |
| 218 | + op: 'navigation', |
| 219 | + startTimestamp: currentSpanStart, |
| 220 | + parentSpanId: '789', |
| 221 | + spanId: 'abc', |
| 222 | + traceId: 'def', |
| 223 | + sampled: true, |
| 224 | + }); |
| 225 | + |
| 226 | + const oldPropagationContext = { |
| 227 | + sampleRand: 0.0126, |
| 228 | + traceId: '123', |
| 229 | + sampled: true, |
| 230 | + dsc: { sample_rand: '0.0126', sample_rate: '0.5' }, |
| 231 | + }; |
| 232 | + |
| 233 | + addPreviousTraceSpanLink(previousTraceInfo, currentSpan, oldPropagationContext); |
| 234 | + |
| 235 | + expect(debugLogSpy).not.toHaveBeenCalledWith(expect.stringContaining('[object Object]')); |
| 236 | + expect(debugLogSpy).toHaveBeenCalledWith( |
| 237 | + expect.stringContaining( |
| 238 | + 'Adding previous_trace `{"traceId":"123","spanId":"456","traceFlags":1}` link to span `{"op":"navigation","spanId":"abc","traceId":"def","traceFlags":1}`', |
| 239 | + ), |
| 240 | + ); |
| 241 | + |
| 242 | + debugLogSpy.mockRestore(); |
| 243 | + }); |
| 244 | + |
204 | 245 | it(`doesn't add a previous_trace span link if the previous trace was created more than ${PREVIOUS_TRACE_MAX_DURATION}s ago`, () => { |
205 | 246 | const currentSpanStart = timestampInSeconds(); |
206 | 247 |
|
|
0 commit comments