UNPKG

4.38 kBTypeScriptView Raw
1import type { Scope, Span, StartSpanOptions } from '@sentry/types';
2import { propagationContextFromHeaders } from '@sentry/utils';
3/**
4 * Wraps a function with a transaction/span and finishes the span after the function is done.
5 * The created span is the active span and will be used as parent by other spans created inside the function
6 * and can be accessed via `Sentry.getActiveSpan()`, as long as the function is executed while the scope is active.
7 *
8 * If you want to create a span that is not set as active, use {@link startInactiveSpan}.
9 *
10 * You'll always get a span passed to the callback,
11 * it may just be a non-recording span if the span is not sampled or if tracing is disabled.
12 */
13export declare function startSpan<T>(context: StartSpanOptions, callback: (span: Span) => T): T;
14/**
15 * Similar to `Sentry.startSpan`. Wraps a function with a transaction/span, but does not finish the span
16 * after the function is done automatically. You'll have to call `span.end()` manually.
17 *
18 * The created span is the active span and will be used as parent by other spans created inside the function
19 * and can be accessed via `Sentry.getActiveSpan()`, as long as the function is executed while the scope is active.
20 *
21 * You'll always get a span passed to the callback,
22 * it may just be a non-recording span if the span is not sampled or if tracing is disabled.
23 */
24export declare function startSpanManual<T>(context: StartSpanOptions, callback: (span: Span, finish: () => void) => T): T;
25/**
26 * Creates a span. This span is not set as active, so will not get automatic instrumentation spans
27 * as children or be able to be accessed via `Sentry.getActiveSpan()`.
28 *
29 * If you want to create a span that is set as active, use {@link startSpan}.
30 *
31 * This function will always return a span,
32 * it may just be a non-recording span if the span is not sampled or if tracing is disabled.
33 */
34export declare function startInactiveSpan(context: StartSpanOptions): Span;
35/**
36 * Continue a trace from `sentry-trace` and `baggage` values.
37 * These values can be obtained from incoming request headers, or in the browser from `<meta name="sentry-trace">`
38 * and `<meta name="baggage">` HTML tags.
39 *
40 * Spans started with `startSpan`, `startSpanManual` and `startInactiveSpan`, within the callback will automatically
41 * be attached to the incoming trace.
42 */
43export declare const continueTrace: <V>({ sentryTrace, baggage, }: {
44 sentryTrace: Parameters<typeof propagationContextFromHeaders>[0];
45 baggage: Parameters<typeof propagationContextFromHeaders>[1];
46}, callback: () => V) => V;
47/**
48 * Forks the current scope and sets the provided span as active span in the context of the provided callback. Can be
49 * passed `null` to start an entirely new span tree.
50 *
51 * @param span Spans started in the context of the provided callback will be children of this span. If `null` is passed,
52 * spans started within the callback will not be attached to a parent span.
53 * @param callback Execution context in which the provided span will be active. Is passed the newly forked scope.
54 * @returns the value returned from the provided callback function.
55 */
56export declare function withActiveSpan<T>(span: Span | null, callback: (scope: Scope) => T): T;
57/** Suppress tracing in the given callback, ensuring no spans are generated inside of it. */
58export declare function suppressTracing<T>(callback: () => T): T;
59/**
60 * Starts a new trace for the duration of the provided callback. Spans started within the
61 * callback will be part of the new trace instead of a potentially previously started trace.
62 *
63 * Important: Only use this function if you want to override the default trace lifetime and
64 * propagation mechanism of the SDK for the duration and scope of the provided callback.
65 * The newly created trace will also be the root of a new distributed trace, for example if
66 * you make http requests within the callback.
67 * This function might be useful if the operation you want to instrument should not be part
68 * of a potentially ongoing trace.
69 *
70 * Default behavior:
71 * - Server-side: A new trace is started for each incoming request.
72 * - Browser: A new trace is started for each page our route. Navigating to a new route
73 * or page will automatically create a new trace.
74 */
75export declare function startNewTrace<T>(callback: () => T): T;
76//# sourceMappingURL=trace.d.ts.map
\No newline at end of file