diff --git a/packages/bun/src/types.ts b/packages/bun/src/types.ts index 91686f9cf8c3..8ad40714de61 100644 --- a/packages/bun/src/types.ts +++ b/packages/bun/src/types.ts @@ -1,54 +1,11 @@ -import type { BaseTransportOptions, ClientOptions, Options, TracePropagationTargets } from '@sentry/core'; +import type { BaseTransportOptions, ClientOptions, Options, ServerRuntimeOptions } from '@sentry/core'; -export interface BaseBunOptions { - /** - * List of strings/regex controlling to which outgoing requests - * the SDK will attach tracing headers. - * - * By default the SDK will attach those headers to all outgoing - * requests. If this option is provided, the SDK will match the - * request URL of outgoing requests against the items in this - * array, and only attach tracing headers if a match was found. - * - * @example - * ```js - * Sentry.init({ - * tracePropagationTargets: ['api.site.com'], - * }); - * ``` - */ - tracePropagationTargets?: TracePropagationTargets; - - /** Sets an optional server name (device name) */ - serverName?: string; - - /** - * If you use Spotlight by Sentry during development, use - * this option to forward captured Sentry events to Spotlight. - * - * Either set it to true, or provide a specific Spotlight Sidecar URL. - * - * More details: https://spotlightjs.com/ - * - * IMPORTANT: Only set this option to `true` while developing, not in production! - */ - spotlight?: boolean | string; - - /** - * If this is set to true, the SDK will not set up OpenTelemetry automatically. - * In this case, you _have_ to ensure to set it up correctly yourself, including: - * * The `SentrySpanProcessor` - * * The `SentryPropagator` - * * The `SentryContextManager` - * * The `SentrySampler` - * - * 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. - */ - skipOpenTelemetrySetup?: boolean; - - /** Callback that is executed when a fatal global error occurs. */ - onFatalError?(this: void, error: Error): void; -} +/** + * Base options for the Sentry Bun SDK. + * Extends the common WinterTC options shared with Node.js and other server-side SDKs. + */ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface BaseBunOptions extends ServerRuntimeOptions {} /** * Configuration options for the Sentry Bun SDK diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 30e24c3b35c7..03e7434e44aa 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -386,7 +386,7 @@ export type { Extra, Extras } from './types-hoist/extra'; export type { Integration, IntegrationFn } from './types-hoist/integration'; export type { Mechanism } from './types-hoist/mechanism'; export type { ExtractedNodeRequestData, HttpHeaderValue, Primitive, WorkerLocation } from './types-hoist/misc'; -export type { ClientOptions, CoreOptions as Options } from './types-hoist/options'; +export type { ServerRuntimeOptions, ClientOptions, CoreOptions as Options } from './types-hoist/options'; export type { Package } from './types-hoist/package'; export type { PolymorphicEvent, PolymorphicRequest } from './types-hoist/polymorphics'; export type { diff --git a/packages/core/src/types-hoist/options.ts b/packages/core/src/types-hoist/options.ts index ac4ce839ff85..7b3eb16443b7 100644 --- a/packages/core/src/types-hoist/options.ts +++ b/packages/core/src/types-hoist/options.ts @@ -1,3 +1,5 @@ +import type { Instrumentation } from '@opentelemetry/instrumentation'; +import type { SpanProcessor } from '@opentelemetry/sdk-trace-base'; import type { CaptureContext } from '../scope'; import type { Breadcrumb, BreadcrumbHint } from './breadcrumb'; import type { ErrorEvent, EventHint, TransactionEvent } from './event'; @@ -11,6 +13,119 @@ import type { StackLineParser, StackParser } from './stacktrace'; import type { TracePropagationTargets } from './tracing'; import type { BaseTransportOptions, Transport } from './transport'; +/** + * Base options for WinterTC-compatible server-side JavaScript runtimes. + * This interface contains common configuration options shared between + * Node.js, Bun, and other WinterTC-compliant runtime SDKs. + * + * @see https://wintercg.org/ + */ +export interface ServerRuntimeOptions { + /** + * List of strings/regex controlling to which outgoing requests + * the SDK will attach tracing headers. + * + * By default the SDK will attach those headers to all outgoing + * requests. If this option is provided, the SDK will match the + * request URL of outgoing requests against the items in this + * array, and only attach tracing headers if a match was found. + * + * @example + * ```js + * Sentry.init({ + * tracePropagationTargets: ['api.site.com'], + * }); + * ``` + */ + tracePropagationTargets?: TracePropagationTargets; + + /** + * Sets an optional server name (device name). + * + * This is useful for identifying which server or instance is sending events. + */ + serverName?: string; + + /** + * If you use Spotlight by Sentry during development, use + * this option to forward captured Sentry events to Spotlight. + * + * Either set it to true, or provide a specific Spotlight Sidecar URL. + * + * More details: https://spotlightjs.com/ + * + * IMPORTANT: Only set this option to `true` while developing, not in production! + */ + spotlight?: boolean | string; + + /** + * If this is set to true, the SDK will not set up OpenTelemetry automatically. + * In this case, you _have_ to ensure to set it up correctly yourself, including: + * * The `SentrySpanProcessor` + * * The `SentryPropagator` + * * The `SentryContextManager` + * * The `SentrySampler` + */ + skipOpenTelemetrySetup?: boolean; + + /** + * If set to `false`, the SDK will not automatically detect the `serverName`. + * + * This is useful if you are using the SDK in a CLI app or Electron where the + * hostname might be considered PII. + * + * @default true + */ + includeServerName?: boolean; + + /** + * By default, the SDK will try to identify problems with your instrumentation setup and warn you about it. + * If you want to disable these warnings, set this to `true`. + */ + disableInstrumentationWarnings?: boolean; + + /** + * Controls how many milliseconds to wait before shutting down. The default is 2 seconds. Setting this too low can cause + * problems for sending events from command line applications. Setting it too + * high can cause the application to block for users with network connectivity + * problems. + */ + shutdownTimeout?: number; + + /** + * Configures in which interval client reports will be flushed. Defaults to `60_000` (milliseconds). + */ + clientReportFlushInterval?: number; + + /** + * Provide an array of OpenTelemetry Instrumentations that should be registered. + * + * Use this option if you want to register OpenTelemetry instrumentation that the Sentry SDK does not yet have support for. + */ + openTelemetryInstrumentations?: Instrumentation[]; + + /** + * Provide an array of additional OpenTelemetry SpanProcessors that should be registered. + */ + openTelemetrySpanProcessors?: SpanProcessor[]; + + /** + * The max. duration in seconds that the SDK will wait for parent spans to be finished before discarding a span. + * The SDK will automatically clean up spans that have no finished parent after this duration. + * This is necessary to prevent memory leaks in case of parent spans that are never finished or otherwise dropped/missing. + * However, if you have very long-running spans in your application, a shorter duration might cause spans to be discarded too early. + * In this case, you can increase this duration to a value that fits your expected data. + * + * Defaults to 300 seconds (5 minutes). + */ + maxSpanWaitDuration?: number; + + /** + * Callback that is executed when a fatal global error occurs. + */ + onFatalError?(this: void, error: Error): void; +} + /** * A filter object for ignoring spans. * At least one of the properties (`op` or `name`) must be set. diff --git a/packages/node-core/src/types.ts b/packages/node-core/src/types.ts index a331b876166d..83b592666f60 100644 --- a/packages/node-core/src/types.ts +++ b/packages/node-core/src/types.ts @@ -1,28 +1,13 @@ import type { Span as WriteableSpan } from '@opentelemetry/api'; -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import type { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-base'; -import type { ClientOptions, Options, SamplingContext, Scope, Span, TracePropagationTargets } from '@sentry/core'; +import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'; +import type { ClientOptions, Options, SamplingContext, Scope, ServerRuntimeOptions, Span } from '@sentry/core'; import type { NodeTransportOptions } from './transports'; -export interface BaseNodeOptions { - /** - * List of strings/regex controlling to which outgoing requests - * the SDK will attach tracing headers. - * - * By default the SDK will attach those headers to all outgoing - * requests. If this option is provided, the SDK will match the - * request URL of outgoing requests against the items in this - * array, and only attach tracing headers if a match was found. - * - * @example - * ```js - * Sentry.init({ - * tracePropagationTargets: ['api.site.com'], - * }); - * ``` - */ - tracePropagationTargets?: TracePropagationTargets; - +/** + * Base options for the Sentry Node SDK. + * Extends the common WinterTC options shared with Bun and other server-side SDKs. + */ +export interface BaseNodeOptions extends ServerRuntimeOptions { /** * Sets profiling sample rate when @sentry/profiling-node is installed * @@ -61,19 +46,6 @@ export interface BaseNodeOptions { */ profileLifecycle?: 'manual' | 'trace'; - /** - * If set to `false`, the SDK will not automatically detect the `serverName`. - * - * This is useful if you are using the SDK in a CLI app or Electron where the - * hostname might be considered PII. - * - * @default true - */ - includeServerName?: boolean; - - /** Sets an optional server name (device name) */ - serverName?: string; - /** * Include local variables with stack traces. * @@ -81,41 +53,6 @@ export interface BaseNodeOptions { */ includeLocalVariables?: boolean; - /** - * If you use Spotlight by Sentry during development, use - * this option to forward captured Sentry events to Spotlight. - * - * Either set it to true, or provide a specific Spotlight Sidecar URL. - * - * More details: https://spotlightjs.com/ - * - * IMPORTANT: Only set this option to `true` while developing, not in production! - */ - spotlight?: boolean | string; - - /** - * Provide an array of OpenTelemetry Instrumentations that should be registered. - * - * Use this option if you want to register OpenTelemetry instrumentation that the Sentry SDK does not yet have support for. - */ - openTelemetryInstrumentations?: Instrumentation[]; - - /** - * Provide an array of additional OpenTelemetry SpanProcessors that should be registered. - */ - openTelemetrySpanProcessors?: SpanProcessor[]; - - /** - * The max. duration in seconds that the SDK will wait for parent spans to be finished before discarding a span. - * The SDK will automatically clean up spans that have no finished parent after this duration. - * This is necessary to prevent memory leaks in case of parent spans that are never finished or otherwise dropped/missing. - * However, if you have very long-running spans in your application, a shorter duration might cause spans to be discarded too early. - * In this case, you can increase this duration to a value that fits your expected data. - * - * Defaults to 300 seconds (5 minutes). - */ - maxSpanWaitDuration?: number; - /** * Whether to register ESM loader hooks to automatically instrument libraries. * This is necessary to auto instrument libraries that are loaded via ESM imports, but it can cause issues @@ -125,28 +62,6 @@ export interface BaseNodeOptions { * Defaults to `true`. */ registerEsmLoaderHooks?: boolean; - - /** - * Configures in which interval client reports will be flushed. Defaults to `60_000` (milliseconds). - */ - clientReportFlushInterval?: number; - - /** - * By default, the SDK will try to identify problems with your instrumentation setup and warn you about it. - * If you want to disable these warnings, set this to `true`. - */ - disableInstrumentationWarnings?: boolean; - - /** - * Controls how many milliseconds to wait before shutting down. The default is 2 seconds. Setting this too low can cause - * problems for sending events from command line applications. Setting it too - * high can cause the application to block for users with network connectivity - * problems. - */ - shutdownTimeout?: number; - - /** Callback that is executed when a fatal global error occurs. */ - onFatalError?(this: void, error: Error): void; } /** diff --git a/packages/node/src/types.ts b/packages/node/src/types.ts index 1f84b69a9f28..a143f270d346 100644 --- a/packages/node/src/types.ts +++ b/packages/node/src/types.ts @@ -1,28 +1,13 @@ import type { Span as WriteableSpan } from '@opentelemetry/api'; -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import type { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-base'; -import type { ClientOptions, Options, SamplingContext, Scope, Span, TracePropagationTargets } from '@sentry/core'; +import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'; +import type { ClientOptions, Options, SamplingContext, Scope, ServerRuntimeOptions, Span } from '@sentry/core'; import type { NodeTransportOptions } from '@sentry/node-core'; -export interface BaseNodeOptions { - /** - * List of strings/regex controlling to which outgoing requests - * the SDK will attach tracing headers. - * - * By default the SDK will attach those headers to all outgoing - * requests. If this option is provided, the SDK will match the - * request URL of outgoing requests against the items in this - * array, and only attach tracing headers if a match was found. - * - * @example - * ```js - * Sentry.init({ - * tracePropagationTargets: ['api.site.com'], - * }); - * ``` - */ - tracePropagationTargets?: TracePropagationTargets; - +/** + * Base options for the Sentry Node SDK. + * Extends the common WinterTC options shared with Bun and other server-side SDKs. + */ +export interface BaseNodeOptions extends ServerRuntimeOptions { /** * Sets profiling sample rate when @sentry/profiling-node is installed * @@ -64,19 +49,6 @@ export interface BaseNodeOptions { */ profileLifecycle?: 'manual' | 'trace'; - /** - * If set to `false`, the SDK will not automatically detect the `serverName`. - * - * This is useful if you are using the SDK in a CLI app or Electron where the - * hostname might be considered PII. - * - * @default true - */ - includeServerName?: boolean; - - /** Sets an optional server name (device name) */ - serverName?: string; - /** * Include local variables with stack traces. * @@ -84,53 +56,6 @@ export interface BaseNodeOptions { */ includeLocalVariables?: boolean; - /** - * If you use Spotlight by Sentry during development, use - * this option to forward captured Sentry events to Spotlight. - * - * Either set it to true, or provide a specific Spotlight Sidecar URL. - * - * More details: https://spotlightjs.com/ - * - * IMPORTANT: Only set this option to `true` while developing, not in production! - */ - spotlight?: boolean | string; - - /** - * If this is set to true, the SDK will not set up OpenTelemetry automatically. - * In this case, you _have_ to ensure to set it up correctly yourself, including: - * * The `SentrySpanProcessor` - * * The `SentryPropagator` - * * The `SentryContextManager` - * * The `SentrySampler` - * - * 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. - */ - skipOpenTelemetrySetup?: boolean; - - /** - * Provide an array of OpenTelemetry Instrumentations that should be registered. - * - * Use this option if you want to register OpenTelemetry instrumentation that the Sentry SDK does not yet have support for. - */ - openTelemetryInstrumentations?: Instrumentation[]; - - /** - * Provide an array of additional OpenTelemetry SpanProcessors that should be registered. - */ - openTelemetrySpanProcessors?: SpanProcessor[]; - - /** - * The max. duration in seconds that the SDK will wait for parent spans to be finished before discarding a span. - * The SDK will automatically clean up spans that have no finished parent after this duration. - * This is necessary to prevent memory leaks in case of parent spans that are never finished or otherwise dropped/missing. - * However, if you have very long-running spans in your application, a shorter duration might cause spans to be discarded too early. - * In this case, you can increase this duration to a value that fits your expected data. - * - * Defaults to 300 seconds (5 minutes). - */ - maxSpanWaitDuration?: number; - /** * Whether to register ESM loader hooks to automatically instrument libraries. * This is necessary to auto instrument libraries that are loaded via ESM imports, but it can cause issues @@ -140,28 +65,6 @@ export interface BaseNodeOptions { * Defaults to `true`. */ registerEsmLoaderHooks?: boolean; - - /** - * Configures in which interval client reports will be flushed. Defaults to `60_000` (milliseconds). - */ - clientReportFlushInterval?: number; - - /** - * By default, the SDK will try to identify problems with your instrumentation setup and warn you about it. - * If you want to disable these warnings, set this to `true`. - */ - disableInstrumentationWarnings?: boolean; - - /** - * Controls how many milliseconds to wait before shutting down. The default is 2 seconds. Setting this too low can cause - * problems for sending events from command line applications. Setting it too - * high can cause the application to block for users with network connectivity - * problems. - */ - shutdownTimeout?: number; - - /** Callback that is executed when a fatal global error occurs. */ - onFatalError?(this: void, error: Error): void; } /**