UNPKG

8.51 kBTypeScriptView Raw
1import type { Span as WriteableSpan } from '@opentelemetry/api';
2import type { Instrumentation } from '@opentelemetry/instrumentation';
3import type { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-base';
4import type { ClientOptions, Options, SamplingContext, Scope, Span, TracePropagationTargets } from '@sentry/core';
5import type { NodeTransportOptions } from './transports';
6/**
7 * Note: In the next major version of the Sentry SDK this interface will be removed and the SDK will by default only wrap
8 * ESM modules that are required to be wrapped by OpenTelemetry Instrumentation.
9 */
10export interface EsmLoaderHookOptions {
11 /**
12 * Provide a list of modules to wrap with `import-in-the-middle`.
13 *
14 * @deprecated It is recommended to use `onlyIncludeInstrumentedModules: true` instead of manually defining modules to include and exclude.
15 */
16 include?: Array<string | RegExp>;
17 /**
18 * Provide a list of modules to prevent them from being wrapped with `import-in-the-middle`.
19 *
20 * @deprecated It is recommended to use `onlyIncludeInstrumentedModules: true` instead of manually defining modules to include and exclude.
21 */
22 exclude?: Array<string | RegExp>;
23 /**
24 * When set to `true`, `import-in-the-middle` will only wrap ESM modules that are specifically instrumented by
25 * OpenTelemetry plugins. This is useful to avoid issues where `import-in-the-middle` is not compatible with some of
26 * your dependencies.
27 *
28 * **Note**: This feature will only work if you `Sentry.init()` the SDK before the instrumented modules are loaded.
29 * This can be achieved via the Node `--import` CLI flag or by loading your app via async `import()` after calling
30 * `Sentry.init()`.
31 *
32 * Defaults to `false`.
33 *
34 * Note: In the next major version of the Sentry SDK this option will be removed and the SDK will by default only wrap
35 * ESM modules that are required to be wrapped by OpenTelemetry Instrumentation.
36 */
37 onlyIncludeInstrumentedModules?: boolean;
38}
39export interface BaseNodeOptions {
40 /**
41 * List of strings/regex controlling to which outgoing requests
42 * the SDK will attach tracing headers.
43 *
44 * By default the SDK will attach those headers to all outgoing
45 * requests. If this option is provided, the SDK will match the
46 * request URL of outgoing requests against the items in this
47 * array, and only attach tracing headers if a match was found.
48 *
49 * @example
50 * ```js
51 * Sentry.init({
52 * tracePropagationTargets: ['api.site.com'],
53 * });
54 * ```
55 */
56 tracePropagationTargets?: TracePropagationTargets;
57 /**
58 * Sets profiling sample rate when @sentry/profiling-node is installed
59 */
60 profilesSampleRate?: number;
61 /**
62 * Function to compute profiling sample rate dynamically and filter unwanted profiles.
63 *
64 * Profiling is enabled if either this or `profilesSampleRate` is defined. If both are defined, `profilesSampleRate` is
65 * ignored.
66 *
67 * Will automatically be passed a context object of default and optional custom data. See
68 * {@link Transaction.samplingContext} and {@link Hub.startTransaction}.
69 *
70 * @returns A sample rate between 0 and 1 (0 drops the profile, 1 guarantees it will be sent). Returning `true` is
71 * equivalent to returning 1 and returning `false` is equivalent to returning 0.
72 */
73 profilesSampler?: (samplingContext: SamplingContext) => number | boolean;
74 /** Sets an optional server name (device name) */
75 serverName?: string;
76 /**
77 * Include local variables with stack traces.
78 *
79 * Requires the `LocalVariables` integration.
80 */
81 includeLocalVariables?: boolean;
82 /**
83 * If you use Spotlight by Sentry during development, use
84 * this option to forward captured Sentry events to Spotlight.
85 *
86 * Either set it to true, or provide a specific Spotlight Sidecar URL.
87 *
88 * More details: https://spotlightjs.com/
89 *
90 * IMPORTANT: Only set this option to `true` while developing, not in production!
91 */
92 spotlight?: boolean | string;
93 /**
94 * If this is set to true, the SDK will not set up OpenTelemetry automatically.
95 * In this case, you _have_ to ensure to set it up correctly yourself, including:
96 * * The `SentrySpanProcessor`
97 * * The `SentryPropagator`
98 * * The `SentryContextManager`
99 * * The `SentrySampler`
100 *
101 * If you are registering your own OpenTelemetry Loader Hooks (or `import-in-the-middle` hooks), it is also recommended to set the `registerEsmLoaderHooks` option to false.
102 */
103 skipOpenTelemetrySetup?: boolean;
104 /**
105 * Provide an array of OpenTelemetry Instrumentations that should be registered.
106 *
107 * Use this option if you want to register OpenTelemetry instrumentation that the Sentry SDK does not yet have support for.
108 */
109 openTelemetryInstrumentations?: Instrumentation[];
110 /**
111 * Provide an array of additional OpenTelemetry SpanProcessors that should be registered.
112 */
113 openTelemetrySpanProcessors?: SpanProcessor[];
114 /**
115 * The max. duration in seconds that the SDK will wait for parent spans to be finished before discarding a span.
116 * The SDK will automatically clean up spans that have no finished parent after this duration.
117 * This is necessary to prevent memory leaks in case of parent spans that are never finished or otherwise dropped/missing.
118 * However, if you have very long-running spans in your application, a shorter duration might cause spans to be discarded too early.
119 * In this case, you can increase this duration to a value that fits your expected data.
120 *
121 * Defaults to 300 seconds (5 minutes).
122 */
123 maxSpanWaitDuration?: number;
124 /**
125 * Whether to register ESM loader hooks to automatically instrument libraries.
126 * This is necessary to auto instrument libraries that are loaded via ESM imports, but it can cause issues
127 * with certain libraries. If you run into problems running your app with this enabled,
128 * please raise an issue in https://github.com/getsentry/sentry-javascript.
129 *
130 * You can optionally exclude specific modules or only include specific modules from being instrumented by providing
131 * an object with `include` or `exclude` properties.
132 *
133 * ```js
134 * registerEsmLoaderHooks: {
135 * exclude: ['openai'],
136 * }
137 * ```
138 *
139 * Defaults to `true`.
140 *
141 * Note: In the next major version of the SDK, the possibility to provide fine-grained control will be removed from this option.
142 * This means that it will only be possible to pass `true` or `false`. The default value will continue to be `true`.
143 */
144 registerEsmLoaderHooks?: boolean | EsmLoaderHookOptions;
145 /**
146 * Configures in which interval client reports will be flushed. Defaults to `60_000` (milliseconds).
147 */
148 clientReportFlushInterval?: number;
149 /**
150 * By default, the SDK will try to identify problems with your instrumentation setup and warn you about it.
151 * If you want to disable these warnings, set this to `true`.
152 */
153 disableInstrumentationWarnings?: boolean;
154 /** Callback that is executed when a fatal global error occurs. */
155 onFatalError?(this: void, error: Error): void;
156}
157/**
158 * Configuration options for the Sentry Node SDK
159 * @see @sentry/core Options for more information.
160 */
161export interface NodeOptions extends Options<NodeTransportOptions>, BaseNodeOptions {
162}
163/**
164 * Configuration options for the Sentry Node SDK Client class
165 * @see NodeClient for more information.
166 */
167export interface NodeClientOptions extends ClientOptions<NodeTransportOptions>, BaseNodeOptions {
168}
169export interface CurrentScopes {
170 scope: Scope;
171 isolationScope: Scope;
172}
173/**
174 * The base `Span` type is basically a `WriteableSpan`.
175 * There are places where we basically want to allow passing _any_ span,
176 * so in these cases we type this as `AbstractSpan` which could be either a regular `Span` or a `ReadableSpan`.
177 * You'll have to make sur to check relevant fields before accessing them.
178 *
179 * Note that technically, the `Span` exported from `@opentelemetry/sdk-trace-base` matches this,
180 * but we cannot be 100% sure that we are actually getting such a span, so this type is more defensive.
181 */
182export type AbstractSpan = WriteableSpan | ReadableSpan | Span;
183//# sourceMappingURL=types.d.ts.map
\No newline at end of file