File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 11import * as os from 'node:os' ;
22import type { Tracer } from '@opentelemetry/api' ;
33import { trace } from '@opentelemetry/api' ;
4+ import { registerInstrumentations } from '@opentelemetry/instrumentation' ;
45import type { BasicTracerProvider } from '@opentelemetry/sdk-trace-base' ;
56import type { ServerRuntimeClientOptions } from '@sentry/core' ;
67import { SDK_VERSION , ServerRuntimeClient , applySdkMetadata } from '@sentry/core' ;
@@ -26,6 +27,12 @@ export class NodeClient extends ServerRuntimeClient<NodeClientOptions> {
2627 serverName : options . serverName || global . process . env . SENTRY_NAME || os . hostname ( ) ,
2728 } ;
2829
30+ if ( options . openTelemetryInstrumentations ) {
31+ registerInstrumentations ( {
32+ instrumentations : options . openTelemetryInstrumentations ,
33+ } ) ;
34+ }
35+
2936 applySdkMetadata ( clientOptions , 'node' ) ;
3037
3138 logger . log (
Original file line number Diff line number Diff line change @@ -90,6 +90,13 @@ export interface BaseNodeOptions {
9090 */
9191 skipOpenTelemetrySetup ?: boolean ;
9292
93+ /**
94+ * Provide an array of OpenTelemetry Instrumentations that should be registered.
95+ *
96+ * Use this option if you want to register OpenTelemetry instrumentation that the Sentry SDK does not yet have support for.
97+ */
98+ openTelemetryInstrumentations ?: Instrumentation [ ] ;
99+
93100 /**
94101 * The max. duration in seconds that the SDK will wait for parent spans to be finished before discarding a span.
95102 * The SDK will automatically clean up spans that have no finished parent after this duration.
@@ -156,7 +163,7 @@ export interface CurrentScopes {
156163 * The base `Span` type is basically a `WriteableSpan`.
157164 * There are places where we basically want to allow passing _any_ span,
158165 * so in these cases we type this as `AbstractSpan` which could be either a regular `Span` or a `ReadableSpan`.
159- * You'll have to make sur to check revelant fields before accessing them.
166+ * You'll have to make sur to check relevant fields before accessing them.
160167 *
161168 * Note that technically, the `Span` exported from `@opentelemetry/sdk-trace-base` matches this,
162169 * but we cannot be 100% sure that we are actually getting such a span, so this type is more defensive.
Original file line number Diff line number Diff line change 11import * as os from 'os' ;
22import { ProxyTracer } from '@opentelemetry/api' ;
3+ import * as opentelemetryInstrumentationPackage from '@opentelemetry/instrumentation' ;
34import {
45 SDK_VERSION ,
56 SessionFlusher ,
@@ -495,6 +496,21 @@ describe('NodeClient', () => {
495496 expect ( sendEnvelopeSpy ) . toHaveBeenCalledTimes ( 0 ) ;
496497 } ) ;
497498 } ) ;
499+
500+ it ( 'registers instrumentations provided with `openTelemetryInstrumentations`' , ( ) => {
501+ const registerInstrumentationsSpy = jest
502+ . spyOn ( opentelemetryInstrumentationPackage , 'registerInstrumentations' )
503+ . mockImplementationOnce ( ( ) => ( ) => undefined ) ;
504+ const instrumentationsArray = [ 'foobar' ] as unknown as opentelemetryInstrumentationPackage . Instrumentation [ ] ;
505+
506+ new NodeClient ( getDefaultNodeClientOptions ( { openTelemetryInstrumentations : instrumentationsArray } ) ) ;
507+
508+ expect ( registerInstrumentationsSpy ) . toHaveBeenCalledWith (
509+ expect . objectContaining ( {
510+ instrumentations : instrumentationsArray ,
511+ } ) ,
512+ ) ;
513+ } ) ;
498514} ) ;
499515
500516describe ( 'flush/close' , ( ) => {
You can’t perform that action at this time.
0 commit comments