diff --git a/packages/opentelemetry-node/src/spanprocessor.ts b/packages/opentelemetry-node/src/spanprocessor.ts index 197a17587327..b75094f78e06 100644 --- a/packages/opentelemetry-node/src/spanprocessor.ts +++ b/packages/opentelemetry-node/src/spanprocessor.ts @@ -45,7 +45,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor { if (sentryParentSpan) { const sentryChildSpan = sentryParentSpan.startChild({ description: otelSpan.name, - // instrumentor: 'otel', + instrumenter: 'otel', startTimestamp: convertOtelTimeToSeconds(otelSpan.startTime), spanId: otelSpanId, }); @@ -56,7 +56,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor { const transaction = hub.startTransaction({ name: otelSpan.name, ...traceCtx, - // instrumentor: 'otel', + instrumenter: 'otel', startTimestamp: convertOtelTimeToSeconds(otelSpan.startTime), spanId: otelSpanId, }); diff --git a/packages/tracing/src/hubextensions.ts b/packages/tracing/src/hubextensions.ts index e3e833262a97..c3cc2967be9d 100644 --- a/packages/tracing/src/hubextensions.ts +++ b/packages/tracing/src/hubextensions.ts @@ -166,6 +166,19 @@ function _startTransaction( const client = this.getClient(); const options: Partial = (client && client.getOptions()) || {}; + const configInstrumenter = options.instrumenter || 'sentry'; + const transactionInstrumenter = transactionContext.instrumenter || 'sentry'; + + if (configInstrumenter !== transactionInstrumenter) { + __DEBUG_BUILD__ && + logger.error( + `A transaction was started with instrumenter=\`${transactionInstrumenter}\`, but the SDK is configured with the \`${configInstrumenter}\` instrumenter. +The transaction will not be sampled. Please use the ${configInstrumenter} instrumentation to start transactions.`, + ); + + transactionContext.sampled = false; + } + let transaction = new Transaction(transactionContext, this); transaction = sample(transaction, options, { parentSampled: transactionContext.parentSampled, diff --git a/packages/tracing/test/hub.test.ts b/packages/tracing/test/hub.test.ts index 5679431187c6..18c357066ff5 100644 --- a/packages/tracing/test/hub.test.ts +++ b/packages/tracing/test/hub.test.ts @@ -21,6 +21,7 @@ const mathRandom = jest.spyOn(Math, 'random'); jest.spyOn(Transaction.prototype, 'setMetadata'); jest.spyOn(logger, 'warn'); jest.spyOn(logger, 'log'); +jest.spyOn(logger, 'error'); jest.spyOn(utilsModule, 'isNodeEnv'); addDOMPropertiesToGlobal(['XMLHttpRequest', 'Event', 'location', 'document']); @@ -377,6 +378,27 @@ describe('Hub', () => { expect(client.captureEvent).not.toBeCalled(); }); + it('should drop transactions when using wrong instrumenter', () => { + const options = getDefaultBrowserClientOptions({ tracesSampleRate: 1, instrumenter: 'otel' }); + const client = new BrowserClient(options); + jest.spyOn(client, 'captureEvent'); + + const hub = new Hub(client); + makeMain(hub); + const transaction = hub.startTransaction({ name: 'dogpark' }); + + jest.spyOn(transaction, 'finish'); + transaction.finish(); + + expect(transaction.sampled).toBe(false); + expect(transaction.finish).toReturnWith(undefined); + expect(client.captureEvent).not.toBeCalled(); + expect(logger.error).toHaveBeenCalledWith( + `A transaction was started with instrumenter=\`sentry\`, but the SDK is configured with the \`otel\` instrumenter. +The transaction will not be sampled. Please use the otel instrumentation to start transactions.`, + ); + }); + describe('sampling inheritance', () => { it('should propagate sampling decision to child spans', () => { const options = getDefaultBrowserClientOptions({ tracesSampleRate: Math.random() });