Skip to content

Commit a0564ed

Browse files
authored
feat(core): Add instrumenter option to ClientOptions (#6128)
* feat(node): Add `instrumentor` option to Node SDK * chore(otel): Move `Instrumenter` type to `@sentry/types` * feat(otel): Move instrumenter option to base ClientOptions
1 parent f2516fd commit a0564ed

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

packages/node/src/sdk.ts

+4
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/test/index.test.ts

+19
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', () => {
@@ -470,4 +471,22 @@ describe('SentryNode initialization', () => {
470471
expect(options.autoSessionTracking).toBe(undefined);
471472
});
472473
});
474+
475+
describe('instrumenter', () => {
476+
it('defaults to sentry instrumenter', () => {
477+
init({ dsn });
478+
479+
const instrumenter = (getCurrentHub()?.getClient()?.getOptions() as NodeClientOptions).instrumenter;
480+
481+
expect(instrumenter).toEqual('sentry');
482+
});
483+
484+
it('allows to set instrumenter', () => {
485+
init({ dsn, instrumenter: 'otel' });
486+
487+
const instrumenter = (getCurrentHub()?.getClient()?.getOptions() as NodeClientOptions).instrumenter;
488+
489+
expect(instrumenter).toEqual('otel');
490+
});
491+
});
473492
});

packages/types/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ export type {
9292
} from './transport';
9393
export type { User, UserFeedback } from './user';
9494
export type { WrappedFunction } from './wrappedfunction';
95+
export type { Instrumenter } from './instrumenter';

packages/types/src/instrumenter.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Instrumenter = 'sentry' | 'otel';

packages/types/src/options.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Breadcrumb, BreadcrumbHint } from './breadcrumb';
22
import { Event, EventHint } from './event';
3+
import { Instrumenter } from './instrumenter';
34
import { Integration } from './integration';
45
import { CaptureContext } from './scope';
56
import { SdkMetadata } from './sdkmetadata';
@@ -58,6 +59,15 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
5859
*/
5960
integrations: Integration[];
6061

62+
/**
63+
* The instrumenter to use. Defaults to `sentry`.
64+
* When not set to `sentry`, auto-instrumentation inside of Sentry will be disabled,
65+
* in favor of using external auto instrumentation.
66+
*
67+
* NOTE: Any option except for `sentry` is highly experimental and subject to change!
68+
*/
69+
instrumenter?: Instrumenter;
70+
6171
/**
6272
* A function that takes transport options and returns the Transport object which is used to send events to Sentry.
6373
* The function is invoked internally when the client is initialized.

0 commit comments

Comments
 (0)