From 9d6823655e5246ad35224823612b09233efeb0c8 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 28 Jul 2026 12:14:13 +0200 Subject: [PATCH] ref(node): Remove vendored generic-pool instrumentation This instrumentation is dead code: the generic-pool integration is provided by the channel-based implementation in `@sentry/server-utils` (default since #22501), and the vendored OpenTelemetry instrumentation here is no longer wired up. Ref: #22346 Co-Authored-By: Claude Opus 4.8 --- .../integrations/tracing/genericPool/index.ts | 6 - .../vendored/generic-pool-types.ts | 8 - .../genericPool/vendored/instrumentation.ts | 160 ------------------ 3 files changed, 174 deletions(-) delete mode 100644 packages/node/src/integrations/tracing/genericPool/index.ts delete mode 100644 packages/node/src/integrations/tracing/genericPool/vendored/generic-pool-types.ts delete mode 100644 packages/node/src/integrations/tracing/genericPool/vendored/instrumentation.ts diff --git a/packages/node/src/integrations/tracing/genericPool/index.ts b/packages/node/src/integrations/tracing/genericPool/index.ts deleted file mode 100644 index 0d5090622ad1..000000000000 --- a/packages/node/src/integrations/tracing/genericPool/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { GenericPoolInstrumentation } from './vendored/instrumentation'; -import { generateInstrumentOnce } from '../../../otel/instrument'; - -const INTEGRATION_NAME = 'GenericPool' as const; - -export const instrumentGenericPool = generateInstrumentOnce(INTEGRATION_NAME, () => new GenericPoolInstrumentation({})); diff --git a/packages/node/src/integrations/tracing/genericPool/vendored/generic-pool-types.ts b/packages/node/src/integrations/tracing/genericPool/vendored/generic-pool-types.ts deleted file mode 100644 index 361d2081173e..000000000000 --- a/packages/node/src/integrations/tracing/genericPool/vendored/generic-pool-types.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Simplified types inlined from generic-pool. - */ - -export declare class Pool { - acquire(priority?: number): PromiseLike; - [key: string]: unknown; -} diff --git a/packages/node/src/integrations/tracing/genericPool/vendored/instrumentation.ts b/packages/node/src/integrations/tracing/genericPool/vendored/instrumentation.ts deleted file mode 100644 index d9987d65f66d..000000000000 --- a/packages/node/src/integrations/tracing/genericPool/vendored/instrumentation.ts +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - * - * NOTICE from the Sentry authors: - * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-generic-pool - * - Upstream version: @opentelemetry/instrumentation-generic-pool@0.61.0 - * - Minor TypeScript strictness adjustments for this repository's compiler settings - */ - -import type { InstrumentationConfig } from '@opentelemetry/instrumentation'; -import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation'; -import { - SDK_VERSION, - SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, - SPAN_STATUS_ERROR, - startSpan, - startSpanManual, -} from '@sentry/core'; -import type * as genericPool from './generic-pool-types'; - -const MODULE_NAME = 'generic-pool'; -const PACKAGE_NAME = '@sentry/instrumentation-generic-pool'; - -type AcquireFn = (this: unknown, ...args: unknown[]) => unknown; -interface PoolConstructor { - prototype: { acquire: AcquireFn }; -} -interface GenericPoolModule { - Pool: PoolConstructor; -} - -export class GenericPoolInstrumentation extends InstrumentationBase { - // only used for v2 - v2.3) - private _isDisabled = false; - - constructor(config: InstrumentationConfig = {}) { - super(PACKAGE_NAME, SDK_VERSION, config); - } - - init() { - return [ - new InstrumentationNodeModuleDefinition( - MODULE_NAME, - ['>=3.0.0 <4'], - (moduleExports: GenericPoolModule) => { - const Pool = moduleExports.Pool; - if (isWrapped(Pool.prototype.acquire)) { - this._unwrap(Pool.prototype, 'acquire'); - } - this._wrap(Pool.prototype, 'acquire', this._acquirePatcher.bind(this)); - return moduleExports; - }, - (moduleExports: GenericPoolModule) => { - const Pool = moduleExports.Pool; - this._unwrap(Pool.prototype, 'acquire'); - return moduleExports; - }, - ), - new InstrumentationNodeModuleDefinition( - MODULE_NAME, - ['>=2.4.0 <3'], - (moduleExports: GenericPoolModule) => { - const Pool = moduleExports.Pool; - if (isWrapped(Pool.prototype.acquire)) { - this._unwrap(Pool.prototype, 'acquire'); - } - this._wrap(Pool.prototype, 'acquire', this._acquireWithCallbacksPatcher.bind(this)); - return moduleExports; - }, - (moduleExports: GenericPoolModule) => { - const Pool = moduleExports.Pool; - this._unwrap(Pool.prototype, 'acquire'); - return moduleExports; - }, - ), - new InstrumentationNodeModuleDefinition( - MODULE_NAME, - ['>=2.0.0 <2.4'], - (moduleExports: GenericPoolModule) => { - this._isDisabled = false; - if (isWrapped(moduleExports.Pool)) { - this._unwrap(moduleExports, 'Pool'); - } - this._wrap(moduleExports, 'Pool', this._poolWrapper.bind(this)); - return moduleExports; - }, - (moduleExports: GenericPoolModule) => { - // since the object is created on the fly every time, we need to use - // a boolean switch here to disable the instrumentation - this._isDisabled = true; - return moduleExports; - }, - ), - ]; - } - - private _acquirePatcher(original: AcquireFn) { - return function wrapped_acquire(this: genericPool.Pool, ...args: unknown[]) { - return startSpan( - { - name: 'generic-pool.acquire', - attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.otel.generic_pool' }, - }, - () => { - return original.call(this, ...args) as PromiseLike; - }, - ); - }; - } - - private _poolWrapper(original: (this: unknown, ...args: unknown[]) => { acquire: AcquireFn }) { - const wrap = this._wrap.bind(this); - const acquireWithCallbacksPatcher = this._acquireWithCallbacksPatcher.bind(this); - return function wrapped_pool(this: unknown, ...args: unknown[]) { - const pool = original.apply(this, args); - wrap(pool, 'acquire', acquireWithCallbacksPatcher); - return pool; - }; - } - - private _acquireWithCallbacksPatcher(original: AcquireFn) { - const isDisabled = (): boolean => this._isDisabled; - return function wrapped_acquire( - this: genericPool.Pool, - cb: (err: unknown, client: unknown) => unknown, - priority: number, - ) { - // only used for v2 - v2.3 - if (isDisabled()) { - return original.call(this, cb, priority); - } - - return startSpanManual( - { - name: 'generic-pool.acquire', - attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.otel.generic_pool' }, - }, - span => { - original.call( - this, - (err: unknown, client: unknown) => { - if (err) { - span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' }); - } - span.end(); - // Not checking whether cb is a function because - // the original code doesn't do that either. - // The callback's return value is unused by generic-pool, so we don't return it. - if (cb) { - cb(err, client); - } - }, - priority, - ); - }, - ); - }; - } -}