Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Add instrumenter option to ClientOptions #6128

Merged
merged 3 commits into from Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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');
});
});
});
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