MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / startNewTrace

Function startNewTrace

packages/opentelemetry/src/trace.ts:313–333  ·  view source on GitHub ↗
(callback: () => T)

Source from the content-addressed store, hash-verified

311 * `startInactiveSpan` and `startSpan` pick it up correctly.
312 */
313export function startNewTrace<T>(callback: () => T): T {
314 const traceId = generateTraceId();
315 const spanId = generateSpanId();
316
317 const spanContext: SpanContext = {
318 traceId,
319 spanId,
320 isRemote: true,
321 traceFlags: TraceFlags.NONE,
322 };
323
324 const ctxWithTrace = trace.setSpanContext(context.active(), spanContext);
325
326 return context.with(ctxWithTrace, () => {
327 getCurrentScope().setPropagationContext({
328 traceId,
329 sampleRand: _INTERNAL_safeMathRandom(),
330 });
331 return callback();
332 });
333}
334
335/**
336 * Get the trace context for a given scope.

Callers 1

trace.test.tsFile · 0.90

Calls 7

generateTraceIdFunction · 0.90
generateSpanIdFunction · 0.90
getCurrentScopeFunction · 0.90
setPropagationContextMethod · 0.80
callbackFunction · 0.50
activeMethod · 0.45
withMethod · 0.45

Tested by

no test coverage detected