Skip to content

Commit

Permalink
feat(node): Add instrumentor option to Node SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Nov 3, 2022
1 parent c2b4650 commit 52a9a7f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/node/src/sdk.ts
Expand Up @@ -148,6 +148,10 @@ export function init(options: NodeOptions = {}): void {
options.autoSessionTracking = true;
}

if (options.instrumenter === undefined) {
options.instrumenter = 'sentry';
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
if ((domain as any).active) {
setHubOnCarrier(carrier, getCurrentHub());
Expand Down
11 changes: 11 additions & 0 deletions packages/node/src/types.ts
Expand Up @@ -2,6 +2,8 @@ import { ClientOptions, Options, TracePropagationTargets } from '@sentry/types';

import { NodeTransportOptions } from './transports';

type SentryNodeInstrumenter = 'sentry' | 'otel';

export interface BaseNodeOptions {
/** Sets an optional server name (device name) */
serverName?: string;
Expand All @@ -19,6 +21,15 @@ export interface BaseNodeOptions {
*/
tracePropagationTargets?: TracePropagationTargets;

/**
* The instrumenter to use. Defaults to `sentry`.
* When not set to `sentry`, auto-instrumentation inside of Sentry will be disabled,
* in favor of using external auto instrumentation.
*
* NOTE: Any option except for `sentry` is highly experimental and subject to change!
*/
instrumenter?: SentryNodeInstrumenter;

/** Callback that is executed when a fatal global error occurs. */
onFatalError?(error: Error): void;
}
Expand Down
19 changes: 19 additions & 0 deletions packages/node/test/index.test.ts
Expand Up @@ -16,6 +16,7 @@ import {
} from '../src';
import { ContextLines, LinkedErrors } from '../src/integrations';
import { defaultStackParser } from '../src/sdk';
import { NodeClientOptions } from '../src/types';
import { getDefaultNodeClientOptions } from './helper/node-client-options';

jest.mock('@sentry/core', () => {
Expand Down Expand Up @@ -466,4 +467,22 @@ describe('SentryNode initialization', () => {
expect(options.autoSessionTracking).toBe(undefined);
});
});

describe('instrumenter', () => {
it('defaults to sentry instrumenter', () => {
init({ dsn });

const instrumenter = (getCurrentHub()?.getClient()?.getOptions() as NodeClientOptions).instrumenter;

expect(instrumenter).toEqual('sentry');
});

it('allows to set instrumenter', () => {
init({ dsn, instrumenter: 'otel' });

const instrumenter = (getCurrentHub()?.getClient()?.getOptions() as NodeClientOptions).instrumenter;

expect(instrumenter).toEqual('otel');
});
});
});

0 comments on commit 52a9a7f

Please sign in to comment.