@opentelemetry/instrumentation-mysql 0.55.0 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -76,11 +76,9 @@ Attributes collected:
|
|
|
76
76
|
|
|
77
77
|
Metrics collected:
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
| ----------------------------- | -------------- | ----------- |
|
|
81
|
-
| `db.client.connections.usage` | (removed) | The number of connections currently in a given state. See note below. |
|
|
79
|
+
- [`db.client.connections.usage`](https://github.com/open-telemetry/semantic-conventions/blob/v1.24.0/docs/database/database-metrics.md#metric-dbclientconnectionsusage) - The number of connections currently in a given state.
|
|
82
80
|
|
|
83
|
-
Note: While `db.client.connections.usage`
|
|
81
|
+
Note: While `db.client.connections.usage` has been deprecated in favor of `db.client.connection.count` in the [semconv database migration](https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count), the new metric is still unstable, so cannot be enabled via `OTEL_SEMCONV_STABILITY_OPT_IN=database`. There is ongoing work to provide an opt-in setting to select the latest experimental semconv.
|
|
84
82
|
|
|
85
83
|
## Useful links
|
|
86
84
|
|
|
@@ -35,15 +35,12 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
35
35
|
_setSemconvStabilityFromEnv() {
|
|
36
36
|
this._netSemconvStability = (0, instrumentation_1.semconvStabilityFromStr)('http', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);
|
|
37
37
|
this._dbSemconvStability = (0, instrumentation_1.semconvStabilityFromStr)('database', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);
|
|
38
|
-
this._updateMetricInstruments();
|
|
39
38
|
}
|
|
40
39
|
_updateMetricInstruments() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
}
|
|
40
|
+
this._connectionsUsageOld = this.meter.createUpDownCounter(semconv_1.METRIC_DB_CLIENT_CONNECTIONS_USAGE, {
|
|
41
|
+
description: 'The number of connections that are currently in state described by the state attribute.',
|
|
42
|
+
unit: '{connection}',
|
|
43
|
+
});
|
|
47
44
|
}
|
|
48
45
|
/**
|
|
49
46
|
* Convenience function for updating the `db.client.connections.usage` metric.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAQ4B;AAC5B,oEAMwC;AACxC,8EAO6C;AAC7C,uCAUmB;AAEnB,qDAAkD;AAElD,mCAOiB;AACjB,kBAAkB;AAClB,uCAA0D;AAQ1D,MAAa,oBAAqB,SAAQ,qCAA+C;IAC/E,oBAAoB,CAAoB;IACxC,mBAAmB,CAAoB;IAG/C,YAAY,SAAqC,EAAE;QACjD,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,2BAA2B,EAAE,CAAC;IACrC,CAAC;IAED,oBAAoB;IACZ,2BAA2B;QACjC,IAAI,CAAC,oBAAoB,GAAG,IAAA,yCAAuB,EACjD,MAAM,EACN,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAC1C,CAAC;QACF,IAAI,CAAC,mBAAmB,GAAG,IAAA,yCAAuB,EAChD,UAAU,EACV,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAC1C,CAAC;QACF,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IAEkB,wBAAwB;QACzC,IAAI,IAAI,CAAC,mBAAmB,GAAG,kCAAgB,CAAC,GAAG,EAAE;YACnD,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CACxD,4CAAkC,EAClC;gBACE,WAAW,EACT,yFAAyF;gBAC3F,IAAI,EAAE,cAAc;aACrB,CACF,CAAC;SACH;IACH,CAAC;IAED;;;;OAIG;IACK,aAAa,CAAC,CAAS,EAAE,W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rB,CAAC,CAAC;iBACJ;gBACD,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,OAAO,aAAO,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,EAAE,CACtC,gBAAgB,CAAC,GAAG,SAAS,CAAC,CAC/B,CAAC;YACJ,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAEO,iBAAiB,CAAC,IAAqB,EAAE,EAAU;QACzD,MAAM,WAAW,GAAG,EAAE,IAAI,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAC;QAE/C,IAAI,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,CAAC,EAAE;YAClC,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE;YAC/B,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;YAC5C,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE;YAC/B,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;YAC3C,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhZD,oDAgZC","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 */\n\nimport {\n context,\n Context,\n trace,\n Span,\n SpanKind,\n SpanStatusCode,\n type Attributes,\n} from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n SemconvStability,\n semconvStabilityFromStr,\n} from '@opentelemetry/instrumentation';\nimport {\n ATTR_DB_NAMESPACE,\n ATTR_DB_QUERY_TEXT,\n ATTR_DB_SYSTEM_NAME,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n DB_SYSTEM_NAME_VALUE_MYSQL,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_DB_CONNECTION_STRING,\n ATTR_DB_NAME,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n ATTR_DB_USER,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n DB_SYSTEM_VALUE_MYSQL,\n METRIC_DB_CLIENT_CONNECTIONS_USAGE,\n} from './semconv';\nimport type * as mysqlTypes from 'mysql';\nimport { AttributeNames } from './AttributeNames';\nimport { MySQLInstrumentationConfig } from './types';\nimport {\n getConfig,\n getDbQueryText,\n getDbValues,\n getJDBCString,\n getSpanName,\n getPoolNameOld,\n} from './utils';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\nimport { UpDownCounter } from '@opentelemetry/api';\n\ntype getConnectionCallbackType = (\n err: mysqlTypes.MysqlError,\n connection: mysqlTypes.PoolConnection\n) => void;\n\nexport class MySQLInstrumentation extends InstrumentationBase<MySQLInstrumentationConfig> {\n private _netSemconvStability!: SemconvStability;\n private _dbSemconvStability!: SemconvStability;\n declare private _connectionsUsageOld: UpDownCounter;\n\n constructor(config: MySQLInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n this._setSemconvStabilityFromEnv();\n }\n\n // Used for testing.\n private _setSemconvStabilityFromEnv() {\n this._netSemconvStability = semconvStabilityFromStr(\n 'http',\n process.env.OTEL_SEMCONV_STABILITY_OPT_IN\n );\n this._dbSemconvStability = semconvStabilityFromStr(\n 'database',\n process.env.OTEL_SEMCONV_STABILITY_OPT_IN\n );\n this._updateMetricInstruments();\n }\n\n protected override _updateMetricInstruments() {\n if (this._dbSemconvStability & SemconvStability.OLD) {\n this._connectionsUsageOld = this.meter.createUpDownCounter(\n METRIC_DB_CLIENT_CONNECTIONS_USAGE,\n {\n description:\n 'The number of connections that are currently in state described by the state attribute.',\n unit: '{connection}',\n }\n );\n }\n }\n\n /**\n * Convenience function for updating the `db.client.connections.usage` metric.\n * The name \"count\" comes from the eventually replacement for this metric per\n * https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count\n */\n private _connCountAdd(n: number, poolNameOld: string, state: string) {\n this._connectionsUsageOld?.add(n, { state, name: poolNameOld });\n }\n\n protected init() {\n return [\n new InstrumentationNodeModuleDefinition(\n 'mysql',\n ['>=2.0.0 <3'],\n (moduleExports: typeof mysqlTypes) => {\n if (isWrapped(moduleExports.createConnection)) {\n this._unwrap(moduleExports, 'createConnection');\n }\n this._wrap(\n moduleExports,\n 'createConnection',\n this._patchCreateConnection() as any\n );\n\n if (isWrapped(moduleExports.createPool)) {\n this._unwrap(moduleExports, 'createPool');\n }\n this._wrap(\n moduleExports,\n 'createPool',\n this._patchCreatePool() as any\n );\n\n if (isWrapped(moduleExports.createPoolCluster)) {\n this._unwrap(moduleExports, 'createPoolCluster');\n }\n this._wrap(\n moduleExports,\n 'createPoolCluster',\n this._patchCreatePoolCluster() as any\n );\n\n return moduleExports;\n },\n (moduleExports: typeof mysqlTypes) => {\n if (moduleExports === undefined) return;\n this._unwrap(moduleExports, 'createConnection');\n this._unwrap(moduleExports, 'createPool');\n this._unwrap(moduleExports, 'createPoolCluster');\n }\n ),\n ];\n }\n\n // global export function\n private _patchCreateConnection() {\n return (originalCreateConnection: Function) => {\n const thisPlugin = this;\n\n return function createConnection(\n _connectionUri: string | mysqlTypes.ConnectionConfig\n ) {\n const originalResult = originalCreateConnection(...arguments);\n\n // This is unwrapped on next call after unpatch\n thisPlugin._wrap(\n originalResult,\n 'query',\n thisPlugin._patchQuery(originalResult) as any\n );\n\n return originalResult;\n };\n };\n }\n\n // global export function\n private _patchCreatePool() {\n return (originalCreatePool: Function) => {\n const thisPlugin = this;\n return function createPool(_config: string | mysqlTypes.PoolConfig) {\n const pool = originalCreatePool(...arguments);\n\n thisPlugin._wrap(pool, 'query', thisPlugin._patchQuery(pool));\n thisPlugin._wrap(\n pool,\n 'getConnection',\n thisPlugin._patchGetConnection(pool)\n );\n thisPlugin._wrap(pool, 'end', thisPlugin._patchPoolEnd(pool));\n thisPlugin._setPoolCallbacks(pool, '');\n\n return pool;\n };\n };\n }\n\n private _patchPoolEnd(pool: any) {\n return (originalPoolEnd: Function) => {\n const thisPlugin = this;\n return function end(callback?: unknown) {\n const nAll = (pool as any)._allConnections.length;\n const nFree = (pool as any)._freeConnections.length;\n const nUsed = nAll - nFree;\n const poolNameOld = getPoolNameOld(pool);\n thisPlugin._connCountAdd(-nUsed, poolNameOld, 'used');\n thisPlugin._connCountAdd(-nFree, poolNameOld, 'idle');\n originalPoolEnd.apply(pool, arguments);\n };\n };\n }\n\n // global export function\n private _patchCreatePoolCluster() {\n return (originalCreatePoolCluster: Function) => {\n const thisPlugin = this;\n return function createPool(_config: string | mysqlTypes.PoolConfig) {\n const cluster = originalCreatePoolCluster(...arguments);\n\n // This is unwrapped on next call after unpatch\n thisPlugin._wrap(\n cluster,\n 'getConnection',\n thisPlugin._patchGetConnection(cluster)\n );\n thisPlugin._wrap(cluster, 'add', thisPlugin._patchAdd(cluster));\n\n return cluster;\n };\n };\n }\n private _patchAdd(cluster: mysqlTypes.PoolCluster) {\n return (originalAdd: Function) => {\n const thisPlugin = this;\n return function add(id: string, config: unknown) {\n // Unwrap if unpatch has been called\n if (!thisPlugin['_enabled']) {\n thisPlugin._unwrap(cluster, 'add');\n return originalAdd.apply(cluster, arguments);\n }\n originalAdd.apply(cluster, arguments);\n const nodes = cluster['_nodes' as keyof mysqlTypes.PoolCluster] as any;\n if (nodes) {\n const nodeId =\n typeof id === 'object'\n ? 'CLUSTER::' + (cluster as any)._lastId\n : String(id);\n\n const pool = nodes[nodeId].pool;\n thisPlugin._setPoolCallbacks(pool, id);\n }\n };\n };\n }\n\n // method on cluster or pool\n private _patchGetConnection(pool: mysqlTypes.Pool | mysqlTypes.PoolCluster) {\n return (originalGetConnection: Function) => {\n const thisPlugin = this;\n\n return function getConnection(\n arg1?: unknown,\n arg2?: unknown,\n arg3?: unknown\n ) {\n // Unwrap if unpatch has been called\n if (!thisPlugin['_enabled']) {\n thisPlugin._unwrap(pool, 'getConnection');\n return originalGetConnection.apply(pool, arguments);\n }\n\n if (arguments.length === 1 && typeof arg1 === 'function') {\n const patchFn = thisPlugin._getConnectionCallbackPatchFn(\n arg1 as getConnectionCallbackType\n );\n return originalGetConnection.call(pool, patchFn);\n }\n if (arguments.length === 2 && typeof arg2 === 'function') {\n const patchFn = thisPlugin._getConnectionCallbackPatchFn(\n arg2 as getConnectionCallbackType\n );\n return originalGetConnection.call(pool, arg1, patchFn);\n }\n if (arguments.length === 3 && typeof arg3 === 'function') {\n const patchFn = thisPlugin._getConnectionCallbackPatchFn(\n arg3 as getConnectionCallbackType\n );\n return originalGetConnection.call(pool, arg1, arg2, patchFn);\n }\n\n return originalGetConnection.apply(pool, arguments);\n };\n };\n }\n\n private _getConnectionCallbackPatchFn(cb: getConnectionCallbackType) {\n const thisPlugin = this;\n const activeContext = context.active();\n return function (\n this: any,\n err: mysqlTypes.MysqlError,\n connection: mysqlTypes.PoolConnection\n ) {\n if (connection) {\n // this is the callback passed into a query\n // no need to unwrap\n if (!isWrapped(connection.query)) {\n thisPlugin._wrap(\n connection,\n 'query',\n thisPlugin._patchQuery(connection)\n );\n }\n }\n if (typeof cb === 'function') {\n context.with(activeContext, cb, this, err, connection);\n }\n };\n }\n\n private _patchQuery(connection: mysqlTypes.Connection | mysqlTypes.Pool) {\n return (originalQuery: Function): mysqlTypes.QueryFunction => {\n const thisPlugin = this;\n\n return function query(\n query: string | mysqlTypes.Query | mysqlTypes.QueryOptions,\n _valuesOrCallback?: unknown[] | mysqlTypes.queryCallback,\n _callback?: mysqlTypes.queryCallback\n ) {\n if (!thisPlugin['_enabled']) {\n thisPlugin._unwrap(connection, 'query');\n return originalQuery.apply(connection, arguments);\n }\n\n const attributes: Attributes = {};\n const { host, port, database, user } = getConfig(connection.config);\n const portNumber = parseInt(port, 10);\n const dbQueryText = getDbQueryText(query);\n if (thisPlugin._dbSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_SYSTEM] = DB_SYSTEM_VALUE_MYSQL;\n attributes[ATTR_DB_CONNECTION_STRING] = getJDBCString(\n host,\n port,\n database\n );\n attributes[ATTR_DB_NAME] = database;\n attributes[ATTR_DB_USER] = user;\n attributes[ATTR_DB_STATEMENT] = dbQueryText;\n }\n if (thisPlugin._dbSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_SYSTEM_NAME] = DB_SYSTEM_NAME_VALUE_MYSQL;\n attributes[ATTR_DB_NAMESPACE] = database;\n attributes[ATTR_DB_QUERY_TEXT] = dbQueryText;\n }\n if (thisPlugin._netSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_NET_PEER_NAME] = host;\n if (!isNaN(portNumber)) {\n attributes[ATTR_NET_PEER_PORT] = portNumber;\n }\n }\n if (thisPlugin._netSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_SERVER_ADDRESS] = host;\n if (!isNaN(portNumber)) {\n attributes[ATTR_SERVER_PORT] = portNumber;\n }\n }\n const span = thisPlugin.tracer.startSpan(getSpanName(query), {\n kind: SpanKind.CLIENT,\n attributes,\n });\n\n if (thisPlugin.getConfig().enhancedDatabaseReporting) {\n let values;\n\n if (Array.isArray(_valuesOrCallback)) {\n values = _valuesOrCallback;\n } else if (arguments[2]) {\n values = [_valuesOrCallback];\n }\n\n span.setAttribute(\n AttributeNames.MYSQL_VALUES,\n getDbValues(query, values)\n );\n }\n\n const cbIndex = Array.from(arguments).findIndex(\n arg => typeof arg === 'function'\n );\n\n const parentContext = context.active();\n\n if (cbIndex === -1) {\n const streamableQuery: mysqlTypes.Query = context.with(\n trace.setSpan(context.active(), span),\n () => {\n return originalQuery.apply(connection, arguments);\n }\n );\n context.bind(parentContext, streamableQuery);\n\n return streamableQuery\n .on('error', err =>\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err.message,\n })\n )\n .on('end', () => {\n span.end();\n });\n } else {\n thisPlugin._wrap(\n arguments,\n cbIndex,\n thisPlugin._patchCallbackQuery(span, parentContext)\n );\n\n return context.with(trace.setSpan(context.active(), span), () => {\n return originalQuery.apply(connection, arguments);\n });\n }\n };\n };\n }\n\n private _patchCallbackQuery(span: Span, parentContext: Context) {\n return (originalCallback: Function) => {\n return function (\n err: mysqlTypes.MysqlError | null,\n results?: any,\n fields?: mysqlTypes.FieldInfo[]\n ) {\n if (err) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err.message,\n });\n }\n span.end();\n return context.with(parentContext, () =>\n originalCallback(...arguments)\n );\n };\n };\n }\n\n private _setPoolCallbacks(pool: mysqlTypes.Pool, id: string) {\n const poolNameOld = id || getPoolNameOld(pool);\n\n pool.on('connection', _connection => {\n this._connCountAdd(1, poolNameOld, 'idle');\n });\n\n pool.on('acquire', _connection => {\n this._connCountAdd(-1, poolNameOld, 'idle');\n this._connCountAdd(1, poolNameOld, 'used');\n });\n\n pool.on('release', _connection => {\n this._connCountAdd(1, poolNameOld, 'idle');\n this._connCountAdd(-1, poolNameOld, 'used');\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAQ4B;AAC5B,oEAMwC;AACxC,8EAO6C;AAC7C,uCAUmB;AAEnB,qDAAk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AC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE;YAC/B,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;YAC5C,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE;YAC/B,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;YAC3C,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA7YD,oDA6YC","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 */\n\nimport {\n context,\n Context,\n trace,\n Span,\n SpanKind,\n SpanStatusCode,\n type Attributes,\n} from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n SemconvStability,\n semconvStabilityFromStr,\n} from '@opentelemetry/instrumentation';\nimport {\n ATTR_DB_NAMESPACE,\n ATTR_DB_QUERY_TEXT,\n ATTR_DB_SYSTEM_NAME,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n DB_SYSTEM_NAME_VALUE_MYSQL,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_DB_CONNECTION_STRING,\n ATTR_DB_NAME,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n ATTR_DB_USER,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n DB_SYSTEM_VALUE_MYSQL,\n METRIC_DB_CLIENT_CONNECTIONS_USAGE,\n} from './semconv';\nimport type * as mysqlTypes from 'mysql';\nimport { AttributeNames } from './AttributeNames';\nimport { MySQLInstrumentationConfig } from './types';\nimport {\n getConfig,\n getDbQueryText,\n getDbValues,\n getJDBCString,\n getSpanName,\n getPoolNameOld,\n} from './utils';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\nimport { UpDownCounter } from '@opentelemetry/api';\n\ntype getConnectionCallbackType = (\n err: mysqlTypes.MysqlError,\n connection: mysqlTypes.PoolConnection\n) => void;\n\nexport class MySQLInstrumentation extends InstrumentationBase<MySQLInstrumentationConfig> {\n private _netSemconvStability!: SemconvStability;\n private _dbSemconvStability!: SemconvStability;\n declare private _connectionsUsageOld: UpDownCounter;\n\n constructor(config: MySQLInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n this._setSemconvStabilityFromEnv();\n }\n\n // Used for testing.\n private _setSemconvStabilityFromEnv() {\n this._netSemconvStability = semconvStabilityFromStr(\n 'http',\n process.env.OTEL_SEMCONV_STABILITY_OPT_IN\n );\n this._dbSemconvStability = semconvStabilityFromStr(\n 'database',\n process.env.OTEL_SEMCONV_STABILITY_OPT_IN\n );\n }\n\n protected override _updateMetricInstruments() {\n this._connectionsUsageOld = this.meter.createUpDownCounter(\n METRIC_DB_CLIENT_CONNECTIONS_USAGE,\n {\n description:\n 'The number of connections that are currently in state described by the state attribute.',\n unit: '{connection}',\n }\n );\n }\n\n /**\n * Convenience function for updating the `db.client.connections.usage` metric.\n * The name \"count\" comes from the eventually replacement for this metric per\n * https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count\n */\n private _connCountAdd(n: number, poolNameOld: string, state: string) {\n this._connectionsUsageOld?.add(n, { state, name: poolNameOld });\n }\n\n protected init() {\n return [\n new InstrumentationNodeModuleDefinition(\n 'mysql',\n ['>=2.0.0 <3'],\n (moduleExports: typeof mysqlTypes) => {\n if (isWrapped(moduleExports.createConnection)) {\n this._unwrap(moduleExports, 'createConnection');\n }\n this._wrap(\n moduleExports,\n 'createConnection',\n this._patchCreateConnection() as any\n );\n\n if (isWrapped(moduleExports.createPool)) {\n this._unwrap(moduleExports, 'createPool');\n }\n this._wrap(\n moduleExports,\n 'createPool',\n this._patchCreatePool() as any\n );\n\n if (isWrapped(moduleExports.createPoolCluster)) {\n this._unwrap(moduleExports, 'createPoolCluster');\n }\n this._wrap(\n moduleExports,\n 'createPoolCluster',\n this._patchCreatePoolCluster() as any\n );\n\n return moduleExports;\n },\n (moduleExports: typeof mysqlTypes) => {\n if (moduleExports === undefined) return;\n this._unwrap(moduleExports, 'createConnection');\n this._unwrap(moduleExports, 'createPool');\n this._unwrap(moduleExports, 'createPoolCluster');\n }\n ),\n ];\n }\n\n // global export function\n private _patchCreateConnection() {\n return (originalCreateConnection: Function) => {\n const thisPlugin = this;\n\n return function createConnection(\n _connectionUri: string | mysqlTypes.ConnectionConfig\n ) {\n const originalResult = originalCreateConnection(...arguments);\n\n // This is unwrapped on next call after unpatch\n thisPlugin._wrap(\n originalResult,\n 'query',\n thisPlugin._patchQuery(originalResult) as any\n );\n\n return originalResult;\n };\n };\n }\n\n // global export function\n private _patchCreatePool() {\n return (originalCreatePool: Function) => {\n const thisPlugin = this;\n return function createPool(_config: string | mysqlTypes.PoolConfig) {\n const pool = originalCreatePool(...arguments);\n\n thisPlugin._wrap(pool, 'query', thisPlugin._patchQuery(pool));\n thisPlugin._wrap(\n pool,\n 'getConnection',\n thisPlugin._patchGetConnection(pool)\n );\n thisPlugin._wrap(pool, 'end', thisPlugin._patchPoolEnd(pool));\n thisPlugin._setPoolCallbacks(pool, '');\n\n return pool;\n };\n };\n }\n\n private _patchPoolEnd(pool: any) {\n return (originalPoolEnd: Function) => {\n const thisPlugin = this;\n return function end(callback?: unknown) {\n const nAll = (pool as any)._allConnections.length;\n const nFree = (pool as any)._freeConnections.length;\n const nUsed = nAll - nFree;\n const poolNameOld = getPoolNameOld(pool);\n thisPlugin._connCountAdd(-nUsed, poolNameOld, 'used');\n thisPlugin._connCountAdd(-nFree, poolNameOld, 'idle');\n originalPoolEnd.apply(pool, arguments);\n };\n };\n }\n\n // global export function\n private _patchCreatePoolCluster() {\n return (originalCreatePoolCluster: Function) => {\n const thisPlugin = this;\n return function createPool(_config: string | mysqlTypes.PoolConfig) {\n const cluster = originalCreatePoolCluster(...arguments);\n\n // This is unwrapped on next call after unpatch\n thisPlugin._wrap(\n cluster,\n 'getConnection',\n thisPlugin._patchGetConnection(cluster)\n );\n thisPlugin._wrap(cluster, 'add', thisPlugin._patchAdd(cluster));\n\n return cluster;\n };\n };\n }\n private _patchAdd(cluster: mysqlTypes.PoolCluster) {\n return (originalAdd: Function) => {\n const thisPlugin = this;\n return function add(id: string, config: unknown) {\n // Unwrap if unpatch has been called\n if (!thisPlugin['_enabled']) {\n thisPlugin._unwrap(cluster, 'add');\n return originalAdd.apply(cluster, arguments);\n }\n originalAdd.apply(cluster, arguments);\n const nodes = cluster['_nodes' as keyof mysqlTypes.PoolCluster] as any;\n if (nodes) {\n const nodeId =\n typeof id === 'object'\n ? 'CLUSTER::' + (cluster as any)._lastId\n : String(id);\n\n const pool = nodes[nodeId].pool;\n thisPlugin._setPoolCallbacks(pool, id);\n }\n };\n };\n }\n\n // method on cluster or pool\n private _patchGetConnection(pool: mysqlTypes.Pool | mysqlTypes.PoolCluster) {\n return (originalGetConnection: Function) => {\n const thisPlugin = this;\n\n return function getConnection(\n arg1?: unknown,\n arg2?: unknown,\n arg3?: unknown\n ) {\n // Unwrap if unpatch has been called\n if (!thisPlugin['_enabled']) {\n thisPlugin._unwrap(pool, 'getConnection');\n return originalGetConnection.apply(pool, arguments);\n }\n\n if (arguments.length === 1 && typeof arg1 === 'function') {\n const patchFn = thisPlugin._getConnectionCallbackPatchFn(\n arg1 as getConnectionCallbackType\n );\n return originalGetConnection.call(pool, patchFn);\n }\n if (arguments.length === 2 && typeof arg2 === 'function') {\n const patchFn = thisPlugin._getConnectionCallbackPatchFn(\n arg2 as getConnectionCallbackType\n );\n return originalGetConnection.call(pool, arg1, patchFn);\n }\n if (arguments.length === 3 && typeof arg3 === 'function') {\n const patchFn = thisPlugin._getConnectionCallbackPatchFn(\n arg3 as getConnectionCallbackType\n );\n return originalGetConnection.call(pool, arg1, arg2, patchFn);\n }\n\n return originalGetConnection.apply(pool, arguments);\n };\n };\n }\n\n private _getConnectionCallbackPatchFn(cb: getConnectionCallbackType) {\n const thisPlugin = this;\n const activeContext = context.active();\n return function (\n this: any,\n err: mysqlTypes.MysqlError,\n connection: mysqlTypes.PoolConnection\n ) {\n if (connection) {\n // this is the callback passed into a query\n // no need to unwrap\n if (!isWrapped(connection.query)) {\n thisPlugin._wrap(\n connection,\n 'query',\n thisPlugin._patchQuery(connection)\n );\n }\n }\n if (typeof cb === 'function') {\n context.with(activeContext, cb, this, err, connection);\n }\n };\n }\n\n private _patchQuery(connection: mysqlTypes.Connection | mysqlTypes.Pool) {\n return (originalQuery: Function): mysqlTypes.QueryFunction => {\n const thisPlugin = this;\n\n return function query(\n query: string | mysqlTypes.Query | mysqlTypes.QueryOptions,\n _valuesOrCallback?: unknown[] | mysqlTypes.queryCallback,\n _callback?: mysqlTypes.queryCallback\n ) {\n if (!thisPlugin['_enabled']) {\n thisPlugin._unwrap(connection, 'query');\n return originalQuery.apply(connection, arguments);\n }\n\n const attributes: Attributes = {};\n const { host, port, database, user } = getConfig(connection.config);\n const portNumber = parseInt(port, 10);\n const dbQueryText = getDbQueryText(query);\n if (thisPlugin._dbSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_SYSTEM] = DB_SYSTEM_VALUE_MYSQL;\n attributes[ATTR_DB_CONNECTION_STRING] = getJDBCString(\n host,\n port,\n database\n );\n attributes[ATTR_DB_NAME] = database;\n attributes[ATTR_DB_USER] = user;\n attributes[ATTR_DB_STATEMENT] = dbQueryText;\n }\n if (thisPlugin._dbSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_SYSTEM_NAME] = DB_SYSTEM_NAME_VALUE_MYSQL;\n attributes[ATTR_DB_NAMESPACE] = database;\n attributes[ATTR_DB_QUERY_TEXT] = dbQueryText;\n }\n if (thisPlugin._netSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_NET_PEER_NAME] = host;\n if (!isNaN(portNumber)) {\n attributes[ATTR_NET_PEER_PORT] = portNumber;\n }\n }\n if (thisPlugin._netSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_SERVER_ADDRESS] = host;\n if (!isNaN(portNumber)) {\n attributes[ATTR_SERVER_PORT] = portNumber;\n }\n }\n const span = thisPlugin.tracer.startSpan(getSpanName(query), {\n kind: SpanKind.CLIENT,\n attributes,\n });\n\n if (thisPlugin.getConfig().enhancedDatabaseReporting) {\n let values;\n\n if (Array.isArray(_valuesOrCallback)) {\n values = _valuesOrCallback;\n } else if (arguments[2]) {\n values = [_valuesOrCallback];\n }\n\n span.setAttribute(\n AttributeNames.MYSQL_VALUES,\n getDbValues(query, values)\n );\n }\n\n const cbIndex = Array.from(arguments).findIndex(\n arg => typeof arg === 'function'\n );\n\n const parentContext = context.active();\n\n if (cbIndex === -1) {\n const streamableQuery: mysqlTypes.Query = context.with(\n trace.setSpan(context.active(), span),\n () => {\n return originalQuery.apply(connection, arguments);\n }\n );\n context.bind(parentContext, streamableQuery);\n\n return streamableQuery\n .on('error', err =>\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err.message,\n })\n )\n .on('end', () => {\n span.end();\n });\n } else {\n thisPlugin._wrap(\n arguments,\n cbIndex,\n thisPlugin._patchCallbackQuery(span, parentContext)\n );\n\n return context.with(trace.setSpan(context.active(), span), () => {\n return originalQuery.apply(connection, arguments);\n });\n }\n };\n };\n }\n\n private _patchCallbackQuery(span: Span, parentContext: Context) {\n return (originalCallback: Function) => {\n return function (\n err: mysqlTypes.MysqlError | null,\n results?: any,\n fields?: mysqlTypes.FieldInfo[]\n ) {\n if (err) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err.message,\n });\n }\n span.end();\n return context.with(parentContext, () =>\n originalCallback(...arguments)\n );\n };\n };\n }\n\n private _setPoolCallbacks(pool: mysqlTypes.Pool, id: string) {\n const poolNameOld = id || getPoolNameOld(pool);\n\n pool.on('connection', _connection => {\n this._connCountAdd(1, poolNameOld, 'idle');\n });\n\n pool.on('acquire', _connection => {\n this._connCountAdd(-1, poolNameOld, 'idle');\n this._connCountAdd(1, poolNameOld, 'used');\n });\n\n pool.on('release', _connection => {\n this._connCountAdd(1, poolNameOld, 'idle');\n this._connCountAdd(-1, poolNameOld, 'used');\n });\n }\n}\n"]}
|
package/build/src/version.d.ts
CHANGED
package/build/src/version.js
CHANGED
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
|
|
19
19
|
// this is autogenerated file, see scripts/version-update.js
|
|
20
|
-
exports.PACKAGE_VERSION = '0.
|
|
20
|
+
exports.PACKAGE_VERSION = '0.56.0';
|
|
21
21
|
exports.PACKAGE_NAME = '@opentelemetry/instrumentation-mysql';
|
|
22
22
|
//# sourceMappingURL=version.js.map
|
package/build/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,sCAAsC,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 */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,sCAAsC,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 */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.56.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-mysql';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/instrumentation-mysql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.0",
|
|
4
4
|
"description": "OpenTelemetry instrumentation for `mysql` database client for MySQL",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"types": "build/src/index.d.ts",
|
|
@@ -49,16 +49,16 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@opentelemetry/api": "^1.3.0",
|
|
51
51
|
"@opentelemetry/context-async-hooks": "^2.0.0",
|
|
52
|
-
"@opentelemetry/contrib-test-utils": "^0.
|
|
52
|
+
"@opentelemetry/contrib-test-utils": "^0.57.0",
|
|
53
53
|
"@opentelemetry/sdk-metrics": "^2.0.0",
|
|
54
54
|
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
55
55
|
"mysql": "2.18.1"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@opentelemetry/instrumentation": "^0.
|
|
58
|
+
"@opentelemetry/instrumentation": "^0.210.0",
|
|
59
59
|
"@opentelemetry/semantic-conventions": "^1.33.0",
|
|
60
60
|
"@types/mysql": "2.15.27"
|
|
61
61
|
},
|
|
62
62
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-mysql#readme",
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "c84212cca7f010b80747cccb9942474e0459df6e"
|
|
64
64
|
}
|