Skip to content

Commit 52a9a7f

Browse files
committed
feat(node): Add instrumentor option to Node SDK
1 parent c2b4650 commit 52a9a7f

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

packages/node/src/sdk.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ export function init(options: NodeOptions = {}): void {
148148
options.autoSessionTracking = true;
149149
}
150150

151+
if (options.instrumenter === undefined) {
152+
options.instrumenter = 'sentry';
153+
}
154+
151155
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
152156
if ((domain as any).active) {
153157
setHubOnCarrier(carrier, getCurrentHub());

packages/node/src/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { ClientOptions, Options, TracePropagationTargets } from '@sentry/types';
22

33
import { NodeTransportOptions } from './transports';
44

5+
type SentryNodeInstrumenter = 'sentry' | 'otel';
6+
57
export interface BaseNodeOptions {
68
/** Sets an optional server name (device name) */
79
serverName?: string;
@@ -19,6 +21,15 @@ export interface BaseNodeOptions {
1921
*/
2022
tracePropagationTargets?: TracePropagationTargets;
2123

24+
/**
25+
* The instrumenter to use. Defaults to `sentry`.
26+
* When not set to `sentry`, auto-instrumentation inside of Sentry will be disabled,
27+
* in favor of using external auto instrumentation.
28+
*
29+
* NOTE: Any option except for `sentry` is highly experimental and subject to change!
30+
*/
31+
instrumenter?: SentryNodeInstrumenter;
32+
2233
/** Callback that is executed when a fatal global error occurs. */
2334
onFatalError?(error: Error): void;
2435
}

packages/node/test/index.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from '../src';
1717
import { ContextLines, LinkedErrors } from '../src/integrations';
1818
import { defaultStackParser } from '../src/sdk';
19+
import { NodeClientOptions } from '../src/types';
1920
import { getDefaultNodeClientOptions } from './helper/node-client-options';
2021

2122
jest.mock('@sentry/core', () => {
@@ -466,4 +467,22 @@ describe('SentryNode initialization', () => {
466467
expect(options.autoSessionTracking).toBe(undefined);
467468
});
468469
});
470+
471+
describe('instrumenter', () => {
472+
it('defaults to sentry instrumenter', () => {
473+
init({ dsn });
474+
475+
const instrumenter = (getCurrentHub()?.getClient()?.getOptions() as NodeClientOptions).instrumenter;
476+
477+
expect(instrumenter).toEqual('sentry');
478+
});
479+
480+
it('allows to set instrumenter', () => {
481+
init({ dsn, instrumenter: 'otel' });
482+
483+
const instrumenter = (getCurrentHub()?.getClient()?.getOptions() as NodeClientOptions).instrumenter;
484+
485+
expect(instrumenter).toEqual('otel');
486+
});
487+
});
469488
});

0 commit comments

Comments
 (0)