Skip to content

Commit

Permalink
feat(core): Add instrumenter option to ClientOptions (#6128)
Browse files Browse the repository at this point in the history
* feat(node): Add `instrumentor` option to Node SDK

* chore(otel): Move `Instrumenter` type to `@sentry/types`

* feat(otel): Move instrumenter option to base ClientOptions
  • Loading branch information
mydea committed Nov 4, 2022
1 parent f2516fd commit a0564ed
Show file tree
Hide file tree
Showing 5 changed files with 35 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
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 @@ -470,4 +471,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');
});
});
});
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Expand Up @@ -92,3 +92,4 @@ export type {
} from './transport';
export type { User, UserFeedback } from './user';
export type { WrappedFunction } from './wrappedfunction';
export type { Instrumenter } from './instrumenter';
1 change: 1 addition & 0 deletions packages/types/src/instrumenter.ts
@@ -0,0 +1 @@
export type Instrumenter = 'sentry' | 'otel';
10 changes: 10 additions & 0 deletions packages/types/src/options.ts
@@ -1,5 +1,6 @@
import { Breadcrumb, BreadcrumbHint } from './breadcrumb';
import { Event, EventHint } from './event';
import { Instrumenter } from './instrumenter';
import { Integration } from './integration';
import { CaptureContext } from './scope';
import { SdkMetadata } from './sdkmetadata';
Expand Down Expand Up @@ -58,6 +59,15 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
*/
integrations: Integration[];

/**
* 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?: Instrumenter;

/**
* A function that takes transport options and returns the Transport object which is used to send events to Sentry.
* The function is invoked internally when the client is initialized.
Expand Down

0 comments on commit a0564ed

Please sign in to comment.