UNPKG

@opentelemetry/instrumentation-pg

Version:
1 lines 32.6 kB
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,oEAMwC;AACxC,4CAW4B;AAG5B,qDAO0B;AAE1B,iCAAiC;AACjC,0DAAmE;AACnE,kBAAkB;AAClB,uCAA0D;AAC1D,iDAA8C;AAC9C,8CAI6B;AAC7B,8EAM6C;AAC7C,uCAMmB;AAEnB,SAAS,oBAAoB,CAAC,MAAW;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,QAAQ;QAC5C,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM;QACvB,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW;AACzB,CAAC;AAED,MAAa,iBAAkB,SAAQ,qCAA4C;IAIjF,iEAAiE;IACjE,wEAAwE;IACxE,uEAAuE;IACvE,sFAAsF;IACtF,yBAAyB;IACjB,mBAAmB,GAAiC;QAC1D,IAAI,EAAE,CAAC;QACP,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;KACX,CAAC;IAEF,YAAY,SAAkC,EAAE;QAC9C,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAEQ,wBAAwB;QAC/B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAClD,6CAAmC,EACnC;YACE,WAAW,EAAE,yCAAyC;YACtD,IAAI,EAAE,GAAG;YACT,SAAS,EAAE,eAAS,CAAC,MAAM;YAC3B,MAAM,EAAE;gBACN,wBAAwB,EAAE;oBACxB,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;iBAC7C;aACF;SACF,CACF,CAAC;QAEF,IAAI,CAAC,mBAAmB,GAAG;YACzB,IAAI,EAA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ACL,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n isWrapped,\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n InstrumentationNodeModuleFile,\n} from '@opentelemetry/instrumentation';\nimport {\n context,\n trace,\n Span,\n SpanStatusCode,\n SpanKind,\n Histogram,\n ValueType,\n Attributes,\n HrTime,\n UpDownCounter,\n} from '@opentelemetry/api';\nimport type * as pgTypes from 'pg';\nimport type * as pgPoolTypes from 'pg-pool';\nimport {\n PgClientConnect,\n PgClientExtended,\n PostgresCallback,\n PgPoolExtended,\n PgPoolCallback,\n EVENT_LISTENERS_SET,\n} from './internal-types';\nimport { PgInstrumentationConfig } from './types';\nimport * as utils from './utils';\nimport { addSqlCommenterComment } from '@opentelemetry/sql-common';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\nimport { SpanNames } from './enums/SpanNames';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n} from '@opentelemetry/core';\nimport {\n DBSYSTEMVALUES_POSTGRESQL,\n SEMATTRS_DB_SYSTEM,\n ATTR_ERROR_TYPE,\n ATTR_SERVER_PORT,\n ATTR_SERVER_ADDRESS,\n} from '@opentelemetry/semantic-conventions';\nimport {\n METRIC_DB_CLIENT_CONNECTION_COUNT,\n METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS,\n METRIC_DB_CLIENT_OPERATION_DURATION,\n ATTR_DB_NAMESPACE,\n ATTR_DB_OPERATION_NAME,\n} from './semconv';\n\nfunction extractModuleExports(module: any) {\n return module[Symbol.toStringTag] === 'Module'\n ? module.default // ESM\n : module; // CommonJS\n}\n\nexport class PgInstrumentation extends InstrumentationBase<PgInstrumentationConfig> {\n private declare _operationDuration: Histogram;\n private declare _connectionsCount: UpDownCounter;\n private declare _connectionPendingRequests: UpDownCounter;\n // Pool events connect, acquire, release and remove can be called\n // multiple times without changing the values of total, idle and waiting\n // connections. The _connectionsCounter is used to keep track of latest\n // values and only update the metrics _connectionsCount and _connectionPendingRequests\n // when the value change.\n private _connectionsCounter: utils.poolConnectionsCounter = {\n used: 0,\n idle: 0,\n pending: 0,\n };\n\n constructor(config: PgInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n override _updateMetricInstruments() {\n this._operationDuration = this.meter.createHistogram(\n METRIC_DB_CLIENT_OPERATION_DURATION,\n {\n description: 'Duration of database client operations.',\n unit: 's',\n valueType: ValueType.DOUBLE,\n advice: {\n explicitBucketBoundaries: [\n 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10,\n ],\n },\n }\n );\n\n this._connectionsCounter = {\n idle: 0,\n pending: 0,\n used: 0,\n };\n this._connectionsCount = this.meter.createUpDownCounter(\n METRIC_DB_CLIENT_CONNECTION_COUNT,\n {\n description:\n 'The number of connections that are currently in state described by the state attribute.',\n unit: '{connection}',\n }\n );\n this._connectionPendingRequests = this.meter.createUpDownCounter(\n METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS,\n {\n description:\n 'The number of current pending requests for an open connection.',\n unit: '{connection}',\n }\n );\n }\n\n protected init() {\n const SUPPORTED_PG_VERSIONS = ['>=8.0.3 <9'];\n\n const modulePgNativeClient = new InstrumentationNodeModuleFile(\n 'pg/lib/native/client.js',\n SUPPORTED_PG_VERSIONS,\n this._patchPgClient.bind(this),\n this._unpatchPgClient.bind(this)\n );\n\n const modulePgClient = new InstrumentationNodeModuleFile(\n 'pg/lib/client.js',\n SUPPORTED_PG_VERSIONS,\n this._patchPgClient.bind(this),\n this._unpatchPgClient.bind(this)\n );\n\n const modulePG = new InstrumentationNodeModuleDefinition(\n 'pg',\n SUPPORTED_PG_VERSIONS,\n (module: any) => {\n const moduleExports = extractModuleExports(module);\n\n this._patchPgClient(moduleExports.Client);\n return module;\n },\n (module: any) => {\n const moduleExports = extractModuleExports(module);\n\n this._unpatchPgClient(moduleExports.Client);\n return module;\n },\n [modulePgClient, modulePgNativeClient]\n );\n\n const modulePGPool = new InstrumentationNodeModuleDefinition(\n 'pg-pool',\n ['>=2.0.0 <4'],\n (moduleExports: typeof pgPoolTypes) => {\n if (isWrapped(moduleExports.prototype.connect)) {\n this._unwrap(moduleExports.prototype, 'connect');\n }\n this._wrap(\n moduleExports.prototype,\n 'connect',\n this._getPoolConnectPatch() as any\n );\n return moduleExports;\n },\n (moduleExports: typeof pgPoolTypes) => {\n if (isWrapped(moduleExports.prototype.connect)) {\n this._unwrap(moduleExports.prototype, 'connect');\n }\n }\n );\n\n return [modulePG, modulePGPool];\n }\n\n private _patchPgClient(module: any) {\n if (!module) {\n return;\n }\n\n const moduleExports = extractModuleExports(module);\n\n if (isWrapped(moduleExports.prototype.query)) {\n this._unwrap(moduleExports.prototype, 'query');\n }\n\n if (isWrapped(moduleExports.prototype.connect)) {\n this._unwrap(moduleExports.prototype, 'connect');\n }\n\n this._wrap(\n moduleExports.prototype,\n 'query',\n this._getClientQueryPatch() as any\n );\n\n this._wrap(\n moduleExports.prototype,\n 'connect',\n this._getClientConnectPatch() as any\n );\n\n return module;\n }\n\n private _unpatchPgClient(module: any) {\n const moduleExports = extractModuleExports(module);\n\n if (isWrapped(moduleExports.prototype.query)) {\n this._unwrap(moduleExports.prototype, 'query');\n }\n\n if (isWrapped(moduleExports.prototype.connect)) {\n this._unwrap(moduleExports.prototype, 'connect');\n }\n\n return module;\n }\n\n private _getClientConnectPatch() {\n const plugin = this;\n return (original: PgClientConnect) => {\n return function connect(this: pgTypes.Client, callback?: Function) {\n if (utils.shouldSkipInstrumentation(plugin.getConfig())) {\n return original.call(this, callback);\n }\n\n const span = plugin.tracer.startSpan(SpanNames.CONNECT, {\n kind: SpanKind.CLIENT,\n attributes: utils.getSemanticAttributesFromConnection(this),\n });\n\n if (callback) {\n const parentSpan = trace.getSpan(context.active());\n callback = utils.patchClientConnectCallback(span, callback);\n if (parentSpan) {\n callback = context.bind(context.active(), callback);\n }\n }\n\n const connectResult: unknown = context.with(\n trace.setSpan(context.active(), span),\n () => {\n return original.call(this, callback);\n }\n );\n\n return handleConnectResult(span, connectResult);\n };\n };\n }\n\n private recordOperationDuration(attributes: Attributes, startTime: HrTime) {\n const metricsAttributes: Attributes = {};\n const keysToCopy = [\n SEMATTRS_DB_SYSTEM,\n ATTR_DB_NAMESPACE,\n ATTR_ERROR_TYPE,\n ATTR_SERVER_PORT,\n ATTR_SERVER_ADDRESS,\n ATTR_DB_OPERATION_NAME,\n ];\n\n keysToCopy.forEach(key => {\n if (key in attributes) {\n metricsAttributes[key] = attributes[key];\n }\n });\n\n const durationSeconds =\n hrTimeToMilliseconds(hrTimeDuration(startTime, hrTime())) / 1000;\n this._operationDuration.record(durationSeconds, metricsAttributes);\n }\n\n private _getClientQueryPatch() {\n const plugin = this;\n return (original: typeof pgTypes.Client.prototype.query) => {\n this._diag.debug('Patching pg.Client.prototype.query');\n return function query(this: PgClientExtended, ...args: unknown[]) {\n if (utils.shouldSkipInstrumentation(plugin.getConfig())) {\n return original.apply(this, args as never);\n }\n const startTime = hrTime();\n\n // client.query(text, cb?), client.query(text, values, cb?), and\n // client.query(configObj, cb?) are all valid signatures. We construct\n // a queryConfig obj from all (valid) signatures to build the span in a\n // unified way. We verify that we at least have query text, and code\n // defensively when dealing with `queryConfig` after that (to handle all\n // the other invalid cases, like a non-array for values being provided).\n // The type casts here reflect only what we've actually validated.\n const arg0 = args[0];\n const firstArgIsString = typeof arg0 === 'string';\n const firstArgIsQueryObjectWithText =\n utils.isObjectWithTextString(arg0);\n\n // TODO: remove the `as ...` casts below when the TS version is upgraded.\n // Newer TS versions will use the result of firstArgIsQueryObjectWithText\n // to properly narrow arg0, but TS 4.3.5 does not.\n const queryConfig = firstArgIsString\n ? {\n text: arg0 as string,\n values: Array.isArray(args[1]) ? args[1] : undefined,\n }\n : firstArgIsQueryObjectWithText\n ? (arg0 as utils.ObjectWithText)\n : undefined;\n\n const attributes: Attributes = {\n [SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_POSTGRESQL,\n [ATTR_DB_NAMESPACE]: this.database,\n [ATTR_SERVER_PORT]: this.connectionParameters.port,\n [ATTR_SERVER_ADDRESS]: this.connectionParameters.host,\n };\n\n if (queryConfig?.text) {\n attributes[ATTR_DB_OPERATION_NAME] =\n utils.parseNormalizedOperationName(queryConfig?.text);\n }\n\n const recordDuration = () => {\n plugin.recordOperationDuration(attributes, startTime);\n };\n\n const instrumentationConfig = plugin.getConfig();\n\n const span = utils.handleConfigQuery.call(\n this,\n plugin.tracer,\n instrumentationConfig,\n queryConfig\n );\n\n // Modify query text w/ a tracing comment before invoking original for\n // tracing, but only if args[0] has one of our expected shapes.\n if (instrumentationConfig.addSqlCommenterCommentToQueries) {\n if (firstArgIsString) {\n args[0] = addSqlCommenterComment(span, arg0);\n } else if (firstArgIsQueryObjectWithText && !('name' in arg0)) {\n // In the case of a query object, we need to ensure there's no name field\n // as this indicates a prepared query, where the comment would remain the same\n // for every invocation and contain an outdated trace context.\n args[0] = {\n ...arg0,\n text: addSqlCommenterComment(span, arg0.text),\n };\n }\n }\n\n // Bind callback (if any) to parent span (if any)\n if (args.length > 0) {\n const parentSpan = trace.getSpan(context.active());\n if (typeof args[args.length - 1] === 'function') {\n // Patch ParameterQuery callback\n args[args.length - 1] = utils.patchCallback(\n instrumentationConfig,\n span,\n args[args.length - 1] as PostgresCallback, // nb: not type safe.\n attributes,\n recordDuration\n );\n\n // If a parent span exists, bind the callback\n if (parentSpan) {\n args[args.length - 1] = context.bind(\n context.active(),\n args[args.length - 1]\n );\n }\n } else if (typeof queryConfig?.callback === 'function') {\n // Patch ConfigQuery callback\n let callback = utils.patchCallback(\n plugin.getConfig(),\n span,\n queryConfig.callback as PostgresCallback, // nb: not type safe.\n attributes,\n recordDuration\n );\n\n // If a parent span existed, bind the callback\n if (parentSpan) {\n callback = context.bind(context.active(), callback);\n }\n\n (args[0] as { callback?: PostgresCallback }).callback = callback;\n }\n }\n\n const { requestHook } = instrumentationConfig;\n if (typeof requestHook === 'function' && queryConfig) {\n safeExecuteInTheMiddle(\n () => {\n // pick keys to expose explicitly, so we're not leaking pg package\n // internals that are subject to change\n const { database, host, port, user } = this.connectionParameters;\n const connection = { database, host, port, user };\n\n requestHook(span, {\n connection,\n query: {\n text: queryConfig.text,\n // nb: if `client.query` is called with illegal arguments\n // (e.g., if `queryConfig.values` is passed explicitly, but a\n // non-array is given), then the type casts will be wrong. But\n // we leave it up to the queryHook to handle that, and we\n // catch and swallow any errors it throws. The other options\n // are all worse. E.g., we could leave `queryConfig.values`\n // and `queryConfig.name` as `unknown`, but then the hook body\n // would be forced to validate (or cast) them before using\n // them, which seems incredibly cumbersome given that these\n // casts will be correct 99.9% of the time -- and pg.query\n // will immediately throw during development in the other .1%\n // of cases. Alternatively, we could simply skip calling the\n // hook when `values` or `name` don't have the expected type,\n // but that would add unnecessary validation overhead to every\n // hook invocation and possibly be even more confusing/unexpected.\n values: queryConfig.values as unknown[],\n name: queryConfig.name as string | undefined,\n },\n });\n },\n err => {\n if (err) {\n plugin._diag.error('Error running query hook', err);\n }\n },\n true\n );\n }\n\n let result: unknown;\n try {\n result = original.apply(this, args as never);\n } catch (e: unknown) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: utils.getErrorMessage(e),\n });\n span.end();\n throw e;\n }\n\n // Bind promise to parent span and end the span\n if (result instanceof Promise) {\n return result\n .then((result: unknown) => {\n // Return a pass-along promise which ends the span and then goes to user's orig resolvers\n return new Promise(resolve => {\n utils.handleExecutionResult(plugin.getConfig(), span, result);\n recordDuration();\n span.end();\n resolve(result);\n });\n })\n .catch((error: Error) => {\n return new Promise((_, reject) => {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n recordDuration();\n span.end();\n reject(error);\n });\n });\n }\n\n // else returns void\n return result; // void\n };\n };\n }\n\n private _setPoolConnectEventListeners(pgPool: PgPoolExtended) {\n if (pgPool[EVENT_LISTENERS_SET]) return;\n const poolName = utils.getPoolName(pgPool.options);\n\n pgPool.on('connect', () => {\n this._connectionsCounter = utils.updateCounter(\n poolName,\n pgPool,\n this._connectionsCount,\n this._connectionPendingRequests,\n this._connectionsCounter\n );\n });\n\n pgPool.on('acquire', () => {\n this._connectionsCounter = utils.updateCounter(\n poolName,\n pgPool,\n this._connectionsCount,\n this._connectionPendingRequests,\n this._connectionsCounter\n );\n });\n\n pgPool.on('remove', () => {\n this._connectionsCounter = utils.updateCounter(\n poolName,\n pgPool,\n this._connectionsCount,\n this._connectionPendingRequests,\n this._connectionsCounter\n );\n });\n\n pgPool.on('release' as any, () => {\n this._connectionsCounter = utils.updateCounter(\n poolName,\n pgPool,\n this._connectionsCount,\n this._connectionPendingRequests,\n this._connectionsCounter\n );\n });\n pgPool[EVENT_LISTENERS_SET] = true;\n }\n\n private _getPoolConnectPatch() {\n const plugin = this;\n return (originalConnect: typeof pgPoolTypes.prototype.connect) => {\n return function connect(this: PgPoolExtended, callback?: PgPoolCallback) {\n if (utils.shouldSkipInstrumentation(plugin.getConfig())) {\n return originalConnect.call(this, callback as any);\n }\n\n // setup span\n const span = plugin.tracer.startSpan(SpanNames.POOL_CONNECT, {\n kind: SpanKind.CLIENT,\n attributes: utils.getSemanticAttributesFromPool(this.options),\n });\n\n plugin._setPoolConnectEventListeners(this);\n\n if (callback) {\n const parentSpan = trace.getSpan(context.active());\n callback = utils.patchCallbackPGPool(\n span,\n callback\n ) as PgPoolCallback;\n // If a parent span exists, bind the callback\n if (parentSpan) {\n callback = context.bind(context.active(), callback);\n }\n }\n\n const connectResult: unknown = context.with(\n trace.setSpan(context.active(), span),\n () => {\n return originalConnect.call(this, callback as any);\n }\n );\n\n return handleConnectResult(span, connectResult);\n };\n };\n }\n}\n\nfunction handleConnectResult(span: Span, connectResult: unknown) {\n if (!(connectResult instanceof Promise)) {\n return connectResult;\n }\n\n const connectResultPromise = connectResult as Promise<unknown>;\n return context.bind(\n context.active(),\n connectResultPromise\n .then(result => {\n span.end();\n return result;\n })\n .catch((error: unknown) => {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: utils.getErrorMessage(error),\n });\n span.end();\n return Promise.reject(error);\n })\n );\n}\n"]}