Skip to content

Commit d350c81

Browse files
authored
feat(core,node-core): Consolidate bun and node types with ServerRuntimeOptions (#18734)
closes #18437 closes [JS-1272](https://linear.app/getsentry/issue/JS-1272/extend-bunoptions-with-nodeoptions) This adds a new type `ServerRuntimeOptions` inside `@sentry/core`, a type which can be used for all SDKs without OpenTelemetry suppport. In case OpenTelemetry support is needed `OpenTelemetryServerRuntimeOptions` are exported from `@sentry/node-core`, which extends `ServerRuntimeOptions` with the options which are needed to support OTel. For now we don't have a nice testing strategy for Bun yet, and I didn't want to copy paste all Node integration/e2e tests just for this, I'm still up for suggestions.
1 parent 83445eb commit d350c81

File tree

6 files changed

+138
-243
lines changed

6 files changed

+138
-243
lines changed

packages/bun/src/types.ts

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,12 @@
1-
import type { BaseTransportOptions, ClientOptions, Options, TracePropagationTargets } from '@sentry/core';
1+
import type { BaseTransportOptions, ClientOptions, Options } from '@sentry/core';
2+
import type { OpenTelemetryServerRuntimeOptions } from '@sentry/node-core';
23

3-
export interface BaseBunOptions {
4-
/**
5-
* List of strings/regex controlling to which outgoing requests
6-
* the SDK will attach tracing headers.
7-
*
8-
* By default the SDK will attach those headers to all outgoing
9-
* requests. If this option is provided, the SDK will match the
10-
* request URL of outgoing requests against the items in this
11-
* array, and only attach tracing headers if a match was found.
12-
*
13-
* @example
14-
* ```js
15-
* Sentry.init({
16-
* tracePropagationTargets: ['api.site.com'],
17-
* });
18-
* ```
19-
*/
20-
tracePropagationTargets?: TracePropagationTargets;
21-
22-
/** Sets an optional server name (device name) */
23-
serverName?: string;
24-
25-
/**
26-
* If you use Spotlight by Sentry during development, use
27-
* this option to forward captured Sentry events to Spotlight.
28-
*
29-
* Either set it to true, or provide a specific Spotlight Sidecar URL.
30-
*
31-
* More details: https://spotlightjs.com/
32-
*
33-
* IMPORTANT: Only set this option to `true` while developing, not in production!
34-
*/
35-
spotlight?: boolean | string;
36-
37-
/**
38-
* If this is set to true, the SDK will not set up OpenTelemetry automatically.
39-
* In this case, you _have_ to ensure to set it up correctly yourself, including:
40-
* * The `SentrySpanProcessor`
41-
* * The `SentryPropagator`
42-
* * The `SentryContextManager`
43-
* * The `SentrySampler`
44-
*
45-
* 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.
46-
*/
47-
skipOpenTelemetrySetup?: boolean;
48-
49-
/** Callback that is executed when a fatal global error occurs. */
50-
onFatalError?(this: void, error: Error): void;
51-
}
4+
/**
5+
* Base options for the Sentry Bun SDK.
6+
* Extends the common WinterTC options with OpenTelemetry support shared with Node.js and other server-side SDKs.
7+
*/
8+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
9+
export interface BaseBunOptions extends OpenTelemetryServerRuntimeOptions {}
5210

5311
/**
5412
* Configuration options for the Sentry Bun SDK

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ export type { Extra, Extras } from './types-hoist/extra';
393393
export type { Integration, IntegrationFn } from './types-hoist/integration';
394394
export type { Mechanism } from './types-hoist/mechanism';
395395
export type { ExtractedNodeRequestData, HttpHeaderValue, Primitive, WorkerLocation } from './types-hoist/misc';
396-
export type { ClientOptions, CoreOptions as Options } from './types-hoist/options';
396+
export type { ClientOptions, CoreOptions as Options, ServerRuntimeOptions } from './types-hoist/options';
397397
export type { Package } from './types-hoist/package';
398398
export type { PolymorphicEvent, PolymorphicRequest } from './types-hoist/polymorphics';
399399
export type {

packages/core/src/types-hoist/options.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,95 @@ import type { StackLineParser, StackParser } from './stacktrace';
1111
import type { TracePropagationTargets } from './tracing';
1212
import type { BaseTransportOptions, Transport } from './transport';
1313

14+
/**
15+
* Base options for WinterTC-compatible server-side JavaScript runtimes.
16+
* This interface contains common configuration options shared between
17+
* SDKs.
18+
*/
19+
export interface ServerRuntimeOptions {
20+
/**
21+
* List of strings/regex controlling to which outgoing requests
22+
* the SDK will attach tracing headers.
23+
*
24+
* By default the SDK will attach those headers to all outgoing
25+
* requests. If this option is provided, the SDK will match the
26+
* request URL of outgoing requests against the items in this
27+
* array, and only attach tracing headers if a match was found.
28+
*
29+
* @example
30+
* ```js
31+
* Sentry.init({
32+
* tracePropagationTargets: ['api.site.com'],
33+
* });
34+
* ```
35+
*/
36+
tracePropagationTargets?: TracePropagationTargets;
37+
38+
/**
39+
* Sets an optional server name (device name).
40+
*
41+
* This is useful for identifying which server or instance is sending events.
42+
*/
43+
serverName?: string;
44+
45+
/**
46+
* If you use Spotlight by Sentry during development, use
47+
* this option to forward captured Sentry events to Spotlight.
48+
*
49+
* Either set it to true, or provide a specific Spotlight Sidecar URL.
50+
*
51+
* More details: https://spotlightjs.com/
52+
*
53+
* IMPORTANT: Only set this option to `true` while developing, not in production!
54+
*/
55+
spotlight?: boolean | string;
56+
57+
/**
58+
* If set to `false`, the SDK will not automatically detect the `serverName`.
59+
*
60+
* This is useful if you are using the SDK in a CLI app or Electron where the
61+
* hostname might be considered PII.
62+
*
63+
* @default true
64+
*/
65+
includeServerName?: boolean;
66+
67+
/**
68+
* By default, the SDK will try to identify problems with your instrumentation setup and warn you about it.
69+
* If you want to disable these warnings, set this to `true`.
70+
*/
71+
disableInstrumentationWarnings?: boolean;
72+
73+
/**
74+
* Controls how many milliseconds to wait before shutting down. The default is 2 seconds. Setting this too low can cause
75+
* problems for sending events from command line applications. Setting it too
76+
* high can cause the application to block for users with network connectivity
77+
* problems.
78+
*/
79+
shutdownTimeout?: number;
80+
81+
/**
82+
* Configures in which interval client reports will be flushed. Defaults to `60_000` (milliseconds).
83+
*/
84+
clientReportFlushInterval?: number;
85+
86+
/**
87+
* The max. duration in seconds that the SDK will wait for parent spans to be finished before discarding a span.
88+
* The SDK will automatically clean up spans that have no finished parent after this duration.
89+
* This is necessary to prevent memory leaks in case of parent spans that are never finished or otherwise dropped/missing.
90+
* However, if you have very long-running spans in your application, a shorter duration might cause spans to be discarded too early.
91+
* In this case, you can increase this duration to a value that fits your expected data.
92+
*
93+
* Defaults to 300 seconds (5 minutes).
94+
*/
95+
maxSpanWaitDuration?: number;
96+
97+
/**
98+
* Callback that is executed when a fatal global error occurs.
99+
*/
100+
onFatalError?(this: void, error: Error): void;
101+
}
102+
14103
/**
15104
* A filter object for ignoring spans.
16105
* At least one of the properties (`op` or `name`) must be set.

packages/node-core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export { NodeClient } from './sdk/client';
5050
export { cron } from './cron';
5151
export { NODE_VERSION } from './nodeVersion';
5252

53-
export type { NodeOptions } from './types';
53+
export type { NodeOptions, OpenTelemetryServerRuntimeOptions } from './types';
5454

5555
export {
5656
// This needs exporting so the NodeClient can be used without calling init

packages/node-core/src/types.ts

Lines changed: 31 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,43 @@
11
import type { Span as WriteableSpan } from '@opentelemetry/api';
22
import type { Instrumentation } from '@opentelemetry/instrumentation';
33
import type { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-base';
4-
import type { ClientOptions, Options, SamplingContext, Scope, Span, TracePropagationTargets } from '@sentry/core';
4+
import type { ClientOptions, Options, SamplingContext, Scope, ServerRuntimeOptions, Span } from '@sentry/core';
55
import type { NodeTransportOptions } from './transports';
66

7-
export interface BaseNodeOptions {
7+
/**
8+
* Base options for WinterTC-compatible server-side JavaScript runtimes with OpenTelemetry support.
9+
* This interface extends the base ServerRuntimeOptions from @sentry/core with OpenTelemetry-specific configuration options.
10+
* Used by Node.js, Bun, and other WinterTC-compliant runtime SDKs that support OpenTelemetry instrumentation.
11+
*/
12+
export interface OpenTelemetryServerRuntimeOptions extends ServerRuntimeOptions {
813
/**
9-
* List of strings/regex controlling to which outgoing requests
10-
* the SDK will attach tracing headers.
11-
*
12-
* By default the SDK will attach those headers to all outgoing
13-
* requests. If this option is provided, the SDK will match the
14-
* request URL of outgoing requests against the items in this
15-
* array, and only attach tracing headers if a match was found.
14+
* If this is set to true, the SDK will not set up OpenTelemetry automatically.
15+
* In this case, you _have_ to ensure to set it up correctly yourself, including:
16+
* * The `SentrySpanProcessor`
17+
* * The `SentryPropagator`
18+
* * The `SentryContextManager`
19+
* * The `SentrySampler`
20+
*/
21+
skipOpenTelemetrySetup?: boolean;
22+
23+
/**
24+
* Provide an array of OpenTelemetry Instrumentations that should be registered.
1625
*
17-
* @example
18-
* ```js
19-
* Sentry.init({
20-
* tracePropagationTargets: ['api.site.com'],
21-
* });
22-
* ```
26+
* Use this option if you want to register OpenTelemetry instrumentation that the Sentry SDK does not yet have support for.
2327
*/
24-
tracePropagationTargets?: TracePropagationTargets;
28+
openTelemetryInstrumentations?: Instrumentation[];
29+
30+
/**
31+
* Provide an array of additional OpenTelemetry SpanProcessors that should be registered.
32+
*/
33+
openTelemetrySpanProcessors?: SpanProcessor[];
34+
}
2535

36+
/**
37+
* Base options for the Sentry Node SDK.
38+
* Extends the common WinterTC options with OpenTelemetry support shared with Bun and other server-side SDKs.
39+
*/
40+
export interface BaseNodeOptions extends OpenTelemetryServerRuntimeOptions {
2641
/**
2742
* Sets profiling sample rate when @sentry/profiling-node is installed
2843
*
@@ -61,61 +76,13 @@ export interface BaseNodeOptions {
6176
*/
6277
profileLifecycle?: 'manual' | 'trace';
6378

64-
/**
65-
* If set to `false`, the SDK will not automatically detect the `serverName`.
66-
*
67-
* This is useful if you are using the SDK in a CLI app or Electron where the
68-
* hostname might be considered PII.
69-
*
70-
* @default true
71-
*/
72-
includeServerName?: boolean;
73-
74-
/** Sets an optional server name (device name) */
75-
serverName?: string;
76-
7779
/**
7880
* Include local variables with stack traces.
7981
*
8082
* Requires the `LocalVariables` integration.
8183
*/
8284
includeLocalVariables?: boolean;
8385

84-
/**
85-
* If you use Spotlight by Sentry during development, use
86-
* this option to forward captured Sentry events to Spotlight.
87-
*
88-
* Either set it to true, or provide a specific Spotlight Sidecar URL.
89-
*
90-
* More details: https://spotlightjs.com/
91-
*
92-
* IMPORTANT: Only set this option to `true` while developing, not in production!
93-
*/
94-
spotlight?: boolean | string;
95-
96-
/**
97-
* Provide an array of OpenTelemetry Instrumentations that should be registered.
98-
*
99-
* Use this option if you want to register OpenTelemetry instrumentation that the Sentry SDK does not yet have support for.
100-
*/
101-
openTelemetryInstrumentations?: Instrumentation[];
102-
103-
/**
104-
* Provide an array of additional OpenTelemetry SpanProcessors that should be registered.
105-
*/
106-
openTelemetrySpanProcessors?: SpanProcessor[];
107-
108-
/**
109-
* The max. duration in seconds that the SDK will wait for parent spans to be finished before discarding a span.
110-
* The SDK will automatically clean up spans that have no finished parent after this duration.
111-
* This is necessary to prevent memory leaks in case of parent spans that are never finished or otherwise dropped/missing.
112-
* However, if you have very long-running spans in your application, a shorter duration might cause spans to be discarded too early.
113-
* In this case, you can increase this duration to a value that fits your expected data.
114-
*
115-
* Defaults to 300 seconds (5 minutes).
116-
*/
117-
maxSpanWaitDuration?: number;
118-
11986
/**
12087
* Whether to register ESM loader hooks to automatically instrument libraries.
12188
* This is necessary to auto instrument libraries that are loaded via ESM imports, but it can cause issues
@@ -125,28 +92,6 @@ export interface BaseNodeOptions {
12592
* Defaults to `true`.
12693
*/
12794
registerEsmLoaderHooks?: boolean;
128-
129-
/**
130-
* Configures in which interval client reports will be flushed. Defaults to `60_000` (milliseconds).
131-
*/
132-
clientReportFlushInterval?: number;
133-
134-
/**
135-
* By default, the SDK will try to identify problems with your instrumentation setup and warn you about it.
136-
* If you want to disable these warnings, set this to `true`.
137-
*/
138-
disableInstrumentationWarnings?: boolean;
139-
140-
/**
141-
* Controls how many milliseconds to wait before shutting down. The default is 2 seconds. Setting this too low can cause
142-
* problems for sending events from command line applications. Setting it too
143-
* high can cause the application to block for users with network connectivity
144-
* problems.
145-
*/
146-
shutdownTimeout?: number;
147-
148-
/** Callback that is executed when a fatal global error occurs. */
149-
onFatalError?(this: void, error: Error): void;
15095
}
15196

15297
/**

0 commit comments

Comments
 (0)