UNPKG

5.02 kBTypeScriptView Raw
1import type { Scope, Span, StartSpanOptions, TransactionContext } from '@sentry/types';
2import { tracingContextFromHeaders } from '@sentry/utils';
3/**
4 * Wraps a function with a transaction/span and finishes the span after the function is done.
5 *
6 * Note that if you have not enabled tracing extensions via `addTracingExtensions`
7 * or you didn't set `tracesSampleRate`, this function will not generate spans
8 * and the `span` returned from the callback will be undefined.
9 *
10 * This function is meant to be used internally and may break at any time. Use at your own risk.
11 *
12 * @internal
13 * @private
14 *
15 * @deprecated Use `startSpan` instead.
16 */
17export declare function trace<T>(context: TransactionContext, callback: (span?: Span) => T, onError?: (error: unknown, span?: Span) => void, afterFinish?: () => void): T;
18/**
19 * Wraps a function with a transaction/span and finishes the span after the function is done.
20 * The created span is the active span and will be used as parent by other spans created inside the function
21 * and can be accessed via `Sentry.getSpan()`, as long as the function is executed while the scope is active.
22 *
23 * If you want to create a span that is not set as active, use {@link startInactiveSpan}.
24 *
25 * Note that if you have not enabled tracing extensions via `addTracingExtensions`
26 * or you didn't set `tracesSampleRate`, this function will not generate spans
27 * and the `span` returned from the callback will be undefined.
28 */
29export declare function startSpan<T>(context: StartSpanOptions, callback: (span: Span | undefined) => T): T;
30/**
31 * @deprecated Use {@link startSpan} instead.
32 */
33export declare const startActiveSpan: typeof startSpan;
34/**
35 * Similar to `Sentry.startSpan`. Wraps a function with a transaction/span, but does not finish the span
36 * after the function is done automatically. You'll have to call `span.end()` manually.
37 *
38 * The created span is the active span and will be used as parent by other spans created inside the function
39 * and can be accessed via `Sentry.getActiveSpan()`, as long as the function is executed while the scope is active.
40 *
41 * Note that if you have not enabled tracing extensions via `addTracingExtensions`
42 * or you didn't set `tracesSampleRate`, this function will not generate spans
43 * and the `span` returned from the callback will be undefined.
44 */
45export declare function startSpanManual<T>(context: StartSpanOptions, callback: (span: Span | undefined, finish: () => void) => T): T;
46/**
47 * Creates a span. This span is not set as active, so will not get automatic instrumentation spans
48 * as children or be able to be accessed via `Sentry.getSpan()`.
49 *
50 * If you want to create a span that is set as active, use {@link startSpan}.
51 *
52 * Note that if you have not enabled tracing extensions via `addTracingExtensions`
53 * or you didn't set `tracesSampleRate` or `tracesSampler`, this function will not generate spans
54 * and the `span` returned from the callback will be undefined.
55 */
56export declare function startInactiveSpan(context: StartSpanOptions): Span | undefined;
57/**
58 * Returns the currently active span.
59 */
60export declare function getActiveSpan(): Span | undefined;
61interface ContinueTrace {
62 /**
63 * Continue a trace from `sentry-trace` and `baggage` values.
64 * These values can be obtained from incoming request headers,
65 * or in the browser from `<meta name="sentry-trace">` and `<meta name="baggage">` HTML tags.
66 *
67 * @deprecated Use the version of this function taking a callback as second parameter instead:
68 *
69 * ```
70 * Sentry.continueTrace(sentryTrace: '...', baggage: '...' }, () => {
71 * // ...
72 * })
73 * ```
74 *
75 */
76 ({ sentryTrace, baggage, }: {
77 sentryTrace: Parameters<typeof tracingContextFromHeaders>[0];
78 baggage: Parameters<typeof tracingContextFromHeaders>[1];
79 }): Partial<TransactionContext>;
80 /**
81 * Continue a trace from `sentry-trace` and `baggage` values.
82 * These values can be obtained from incoming request headers, or in the browser from `<meta name="sentry-trace">`
83 * and `<meta name="baggage">` HTML tags.
84 *
85 * Spans started with `startSpan`, `startSpanManual` and `startInactiveSpan`, within the callback will automatically
86 * be attached to the incoming trace.
87 *
88 * Deprecation notice: In the next major version of the SDK the provided callback will not receive a transaction
89 * context argument.
90 */
91 <V>({ sentryTrace, baggage, }: {
92 sentryTrace: Parameters<typeof tracingContextFromHeaders>[0];
93 baggage: Parameters<typeof tracingContextFromHeaders>[1];
94 }, callback: (transactionContext: Partial<TransactionContext>) => V): V;
95}
96export declare const continueTrace: ContinueTrace;
97/**
98 * Grabs the scope and isolation scope off a span that were active when the span was started.
99 */
100export declare function getCapturedScopesOnSpan(span: Span): {
101 scope?: Scope;
102 isolationScope?: Scope;
103};
104export {};
105//# sourceMappingURL=trace.d.ts.map
\No newline at end of file