@opentelemetry/instrumentation-mysql 0.54.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
@@ -44,27 +44,41 @@ See [examples/mysql](https://github.com/open-telemetry/opentelemetry-js-contrib/
44
44
 
45
45
  ### MySQL instrumentation Options
46
46
 
47
- | Options | Type | Default | Description |
48
- | ------- | ---- | --------| ----------- |
49
- | [`enhancedDatabaseReporting`](./src/types.ts#L24) | `boolean` | `false` | If true, an attribute containing the query's parameters will be attached the spans generated to represent the query |
50
-
47
+ | Options | Type | Default | Description |
48
+ | ------------------------------------------------- | --------- | ------- | ----------- |
49
+ | [`enhancedDatabaseReporting`](./src/types.ts#L24) | `boolean` | `false` | If true, a `db.mysql.values` attribute containing the query's parameters will be add to database spans. Note that this is not an attribute defined in [Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/database/mysql/). |
51
50
 
52
51
  ## Semantic Conventions
53
52
 
54
- This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
53
+ This instrumentation implements Semantic Conventions (semconv) v1.7.0. Since then, networking (in semconv v1.23.1) and database (in semconv v1.33.0) semantic conventions were stabilized. As of `@opentelemetry/instrumentation-mysql@0.55.0` support has been added for migrating to the stable semantic conventions using the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable as follows:
54
+
55
+ 1. Upgrade to the latest version of this instrumentation package.
56
+ 2. Set `OTEL_SEMCONV_STABILITY_OPT_IN=http/dup,database/dup` to emit both old and stable semantic conventions. (The `http` token is used to control the `net.*` attributes, the `database` token to control to `db.*` attributes.)
57
+ 3. Modify alerts, dashboards, metrics, and other processes in your Observability system to use the stable semantic conventions.
58
+ 4. Set `OTEL_SEMCONV_STABILITY_OPT_IN=http,database` to emit only the stable semantic conventions.
59
+
60
+ By default, if `OTEL_SEMCONV_STABILITY_OPT_IN` includes neither of the above tokens, the old v1.7.0 semconv is used.
61
+ The intent is to provide an approximate 6 month time window for users of this instrumentation to migrate to the new database and networking semconv, after which a new minor version will use the new semconv by default and drop support for the old semconv.
62
+ See [the HTTP migration guide](https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/) and the [database migration guide](https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/) for details.
55
63
 
56
64
  Attributes collected:
57
65
 
58
- | Attribute | Short Description |
59
- | ----------------------- | ------------------------------------------------------------------------------ |
60
- | `db.connection_string` | The connection string used to connect to the database. |
61
- | `db.name` | This attribute is used to report the name of the database being accessed. |
62
- | `db.operation` | The name of the operation being executed. |
63
- | `db.statement` | The database statement being executed. |
64
- | `db.system` | An identifier for the database management system (DBMS) product being used. |
65
- | `db.user` | Username for accessing the database. |
66
- | `net.peer.name` | Remote hostname or similar. |
67
- | `net.peer.port` | Remote port number. |
66
+ | Old semconv | Stable semconv | Description |
67
+ | ---------------------- | ---------------- | ----------- |
68
+ | `db.system` | `db.system.name` | 'mssql' (old), 'microsoft.sql_server' (stable) |
69
+ | `db.connection_string` | Removed | The connection string used to connect to the database. |
70
+ | `db.statement` | `db.query.text` | The database query being executed. |
71
+ | `db.user` | Removed | Username for accessing the database. |
72
+ | `db.name` | Removed | Integrated into new `db.namespace`. |
73
+ | (not included) | `db.namespace` | The database associated with the connection, as provided at connection time. (This does not track changes made via `SELECT DATABASE()`.) |
74
+ | `net.peer.name` | `server.address` | Remote hostname or similar. |
75
+ | `net.peer.port` | `server.port` | Remote port number. |
76
+
77
+ Metrics collected:
78
+
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.
80
+
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.
68
82
 
69
83
  ## Useful links
70
84
 
@@ -1,12 +1,18 @@
1
1
  import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
2
2
  import { MySQLInstrumentationConfig } from './types';
3
3
  export declare class MySQLInstrumentation extends InstrumentationBase<MySQLInstrumentationConfig> {
4
- static readonly COMMON_ATTRIBUTES: {
5
- "db.system": "mysql";
6
- };
7
- private _connectionsUsage;
4
+ private _netSemconvStability;
5
+ private _dbSemconvStability;
6
+ private _connectionsUsageOld;
8
7
  constructor(config?: MySQLInstrumentationConfig);
8
+ private _setSemconvStabilityFromEnv;
9
9
  protected _updateMetricInstruments(): void;
10
+ /**
11
+ * Convenience function for updating the `db.client.connections.usage` metric.
12
+ * The name "count" comes from the eventually replacement for this metric per
13
+ * https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count
14
+ */
15
+ private _connCountAdd;
10
16
  protected init(): InstrumentationNodeModuleDefinition[];
11
17
  private _patchCreateConnection;
12
18
  private _patchCreatePool;
@@ -17,6 +23,6 @@ export declare class MySQLInstrumentation extends InstrumentationBase<MySQLInstr
17
23
  private _getConnectionCallbackPatchFn;
18
24
  private _patchQuery;
19
25
  private _patchCallbackQuery;
20
- private _setPoolcallbacks;
26
+ private _setPoolCallbacks;
21
27
  }
22
28
  //# sourceMappingURL=instrumentation.d.ts.map
@@ -18,24 +18,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.MySQLInstrumentation = void 0;
19
19
  const api_1 = require("@opentelemetry/api");
20
20
  const instrumentation_1 = require("@opentelemetry/instrumentation");
21
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
21
22
  const semconv_1 = require("./semconv");
22
23
  const AttributeNames_1 = require("./AttributeNames");
23
24
  const utils_1 = require("./utils");
24
25
  /** @knipignore */
25
26
  const version_1 = require("./version");
26
27
  class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
27
- static COMMON_ATTRIBUTES = {
28
- [semconv_1.ATTR_DB_SYSTEM]: semconv_1.DB_SYSTEM_VALUE_MYSQL,
29
- };
28
+ _netSemconvStability;
29
+ _dbSemconvStability;
30
30
  constructor(config = {}) {
31
31
  super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, config);
32
+ this._setSemconvStabilityFromEnv();
33
+ }
34
+ // Used for testing.
35
+ _setSemconvStabilityFromEnv() {
36
+ this._netSemconvStability = (0, instrumentation_1.semconvStabilityFromStr)('http', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);
37
+ this._dbSemconvStability = (0, instrumentation_1.semconvStabilityFromStr)('database', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);
32
38
  }
33
39
  _updateMetricInstruments() {
34
- this._connectionsUsage = this.meter.createUpDownCounter(semconv_1.METRIC_DB_CLIENT_CONNECTIONS_USAGE, {
40
+ this._connectionsUsageOld = this.meter.createUpDownCounter(semconv_1.METRIC_DB_CLIENT_CONNECTIONS_USAGE, {
35
41
  description: 'The number of connections that are currently in state described by the state attribute.',
36
42
  unit: '{connection}',
37
43
  });
38
44
  }
45
+ /**
46
+ * Convenience function for updating the `db.client.connections.usage` metric.
47
+ * The name "count" comes from the eventually replacement for this metric per
48
+ * https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count
49
+ */
50
+ _connCountAdd(n, poolNameOld, state) {
51
+ this._connectionsUsageOld?.add(n, { state, name: poolNameOld });
52
+ }
39
53
  init() {
40
54
  return [
41
55
  new instrumentation_1.InstrumentationNodeModuleDefinition('mysql', ['>=2.0.0 <3'], (moduleExports) => {
@@ -82,7 +96,7 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
82
96
  thisPlugin._wrap(pool, 'query', thisPlugin._patchQuery(pool));
83
97
  thisPlugin._wrap(pool, 'getConnection', thisPlugin._patchGetConnection(pool));
84
98
  thisPlugin._wrap(pool, 'end', thisPlugin._patchPoolEnd(pool));
85
- thisPlugin._setPoolcallbacks(pool, thisPlugin, '');
99
+ thisPlugin._setPoolCallbacks(pool, '');
86
100
  return pool;
87
101
  };
88
102
  };
@@ -94,15 +108,9 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
94
108
  const nAll = pool._allConnections.length;
95
109
  const nFree = pool._freeConnections.length;
96
110
  const nUsed = nAll - nFree;
97
- const poolName = (0, utils_1.getPoolName)(pool);
98
- thisPlugin._connectionsUsage.add(-nUsed, {
99
- state: 'used',
100
- name: poolName,
101
- });
102
- thisPlugin._connectionsUsage.add(-nFree, {
103
- state: 'idle',
104
- name: poolName,
105
- });
111
+ const poolNameOld = (0, utils_1.getPoolNameOld)(pool);
112
+ thisPlugin._connCountAdd(-nUsed, poolNameOld, 'used');
113
+ thisPlugin._connCountAdd(-nFree, poolNameOld, 'idle');
106
114
  originalPoolEnd.apply(pool, arguments);
107
115
  };
108
116
  };
@@ -136,7 +144,7 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
136
144
  ? 'CLUSTER::' + cluster._lastId
137
145
  : String(id);
138
146
  const pool = nodes[nodeId].pool;
139
- thisPlugin._setPoolcallbacks(pool, thisPlugin, id);
147
+ thisPlugin._setPoolCallbacks(pool, id);
140
148
  }
141
149
  };
142
150
  };
@@ -191,14 +199,38 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
191
199
  thisPlugin._unwrap(connection, 'query');
192
200
  return originalQuery.apply(connection, arguments);
193
201
  }
202
+ const attributes = {};
203
+ const { host, port, database, user } = (0, utils_1.getConfig)(connection.config);
204
+ const portNumber = parseInt(port, 10);
205
+ const dbQueryText = (0, utils_1.getDbQueryText)(query);
206
+ if (thisPlugin._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
207
+ attributes[semconv_1.ATTR_DB_SYSTEM] = semconv_1.DB_SYSTEM_VALUE_MYSQL;
208
+ attributes[semconv_1.ATTR_DB_CONNECTION_STRING] = (0, utils_1.getJDBCString)(host, port, database);
209
+ attributes[semconv_1.ATTR_DB_NAME] = database;
210
+ attributes[semconv_1.ATTR_DB_USER] = user;
211
+ attributes[semconv_1.ATTR_DB_STATEMENT] = dbQueryText;
212
+ }
213
+ if (thisPlugin._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
214
+ attributes[semantic_conventions_1.ATTR_DB_SYSTEM_NAME] = semantic_conventions_1.DB_SYSTEM_NAME_VALUE_MYSQL;
215
+ attributes[semantic_conventions_1.ATTR_DB_NAMESPACE] = database;
216
+ attributes[semantic_conventions_1.ATTR_DB_QUERY_TEXT] = dbQueryText;
217
+ }
218
+ if (thisPlugin._netSemconvStability & instrumentation_1.SemconvStability.OLD) {
219
+ attributes[semconv_1.ATTR_NET_PEER_NAME] = host;
220
+ if (!isNaN(portNumber)) {
221
+ attributes[semconv_1.ATTR_NET_PEER_PORT] = portNumber;
222
+ }
223
+ }
224
+ if (thisPlugin._netSemconvStability & instrumentation_1.SemconvStability.STABLE) {
225
+ attributes[semantic_conventions_1.ATTR_SERVER_ADDRESS] = host;
226
+ if (!isNaN(portNumber)) {
227
+ attributes[semantic_conventions_1.ATTR_SERVER_PORT] = portNumber;
228
+ }
229
+ }
194
230
  const span = thisPlugin.tracer.startSpan((0, utils_1.getSpanName)(query), {
195
231
  kind: api_1.SpanKind.CLIENT,
196
- attributes: {
197
- ...MySQLInstrumentation.COMMON_ATTRIBUTES,
198
- ...(0, utils_1.getConnectionAttributes)(connection.config),
199
- },
232
+ attributes,
200
233
  });
201
- span.setAttribute(semconv_1.ATTR_DB_STATEMENT, (0, utils_1.getDbStatement)(query));
202
234
  if (thisPlugin.getConfig().enhancedDatabaseReporting) {
203
235
  let values;
204
236
  if (Array.isArray(_valuesOrCallback)) {
@@ -248,34 +280,18 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
248
280
  };
249
281
  };
250
282
  }
251
- _setPoolcallbacks(pool, thisPlugin, id) {
252
- //TODO:: use semantic convention
253
- const poolName = id || (0, utils_1.getPoolName)(pool);
254
- pool.on('connection', connection => {
255
- thisPlugin._connectionsUsage.add(1, {
256
- state: 'idle',
257
- name: poolName,
258
- });
283
+ _setPoolCallbacks(pool, id) {
284
+ const poolNameOld = id || (0, utils_1.getPoolNameOld)(pool);
285
+ pool.on('connection', _connection => {
286
+ this._connCountAdd(1, poolNameOld, 'idle');
259
287
  });
260
- pool.on('acquire', connection => {
261
- thisPlugin._connectionsUsage.add(-1, {
262
- state: 'idle',
263
- name: poolName,
264
- });
265
- thisPlugin._connectionsUsage.add(1, {
266
- state: 'used',
267
- name: poolName,
268
- });
288
+ pool.on('acquire', _connection => {
289
+ this._connCountAdd(-1, poolNameOld, 'idle');
290
+ this._connCountAdd(1, poolNameOld, 'used');
269
291
  });
270
- pool.on('release', connection => {
271
- thisPlugin._connectionsUsage.add(-1, {
272
- state: 'used',
273
- name: poolName,
274
- });
275
- thisPlugin._connectionsUsage.add(1, {
276
- state: 'idle',
277
- name: poolName,
278
- });
292
+ pool.on('release', _connection => {
293
+ this._connCountAdd(1, poolNameOld, 'idle');
294
+ this._connCountAdd(-1, poolNameOld, 'used');
279
295
  });
280
296
  }
281
297
  }
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAO4B;AAC5B,oEAIwC;AACxC,uCAKmB;AAEnB,qDAAkD;AAElD,mCAMiB;AACjB,kBAAkB;AAClB,uCAA0D;AAQ1D,MAAa,oBAAqB,SAAQ,qCAA+C;IACvF,MAAM,CAAU,iBAAiB,GAAG;QAClC,CAAC,wBAAc,CAAC,EAAE,+BAAqB;KACxC,CAAC;IAGF,YAAY,SAAqC,EAAE;QACjD,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAEkB,wBAAwB;QACzC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,KAAK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;aACf,CAAC,CAAC;YACH,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,EAAE;gBAClC,KAAK,EAAE,MAAM;gBACb,IAAI,EAAE,QAAQ;aACf,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;;AApXU,oDAAoB","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} from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n} from '@opentelemetry/instrumentation';\nimport {\n DB_SYSTEM_VALUE_MYSQL,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\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 getConnectionAttributes,\n getDbStatement,\n getDbValues,\n getSpanName,\n getPoolName,\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 static readonly COMMON_ATTRIBUTES = {\n [ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_MYSQL,\n };\n private declare _connectionsUsage: UpDownCounter;\n\n constructor(config: MySQLInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n protected override _updateMetricInstruments() {\n this._connectionsUsage = 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 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, thisPlugin, '');\n\n return pool;\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 poolName = getPoolName(pool);\n thisPlugin._connectionsUsage.add(-nUsed, {\n state: 'used',\n name: poolName,\n });\n thisPlugin._connectionsUsage.add(-nFree, {\n state: 'idle',\n name: poolName,\n });\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, thisPlugin, 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 span = thisPlugin.tracer.startSpan(getSpanName(query), {\n kind: SpanKind.CLIENT,\n attributes: {\n ...MySQLInstrumentation.COMMON_ATTRIBUTES,\n ...getConnectionAttributes(connection.config),\n },\n });\n\n span.setAttribute(ATTR_DB_STATEMENT, getDbStatement(query));\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 private _setPoolcallbacks(\n pool: mysqlTypes.Pool,\n thisPlugin: MySQLInstrumentation,\n id: string\n ) {\n //TODO:: use semantic convention\n const poolName = id || getPoolName(pool);\n\n pool.on('connection', connection => {\n thisPlugin._connectionsUsage.add(1, {\n state: 'idle',\n name: poolName,\n });\n });\n\n pool.on('acquire', connection => {\n thisPlugin._connectionsUsage.add(-1, {\n state: 'idle',\n name: poolName,\n });\n thisPlugin._connectionsUsage.add(1, {\n state: 'used',\n name: poolName,\n });\n });\n\n pool.on('release', connection => {\n thisPlugin._connectionsUsage.add(-1, {\n state: 'used',\n name: poolName,\n });\n thisPlugin._connectionsUsage.add(1, {\n state: 'idle',\n name: poolName,\n });\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,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;IACJ,CAAC;IAEkB,wBAAwB;QACzC,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CACxD,4CAAkC,EAClC;YACE,WAAW,EACT,yFAAyF;YAC3F,IAAI,EAAE,cAAc;SACrB,CACF,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACK,aAAa,CAAC,CAAS,EAAE,WAAmB,EAAE,KAAa;QACjE,IAAI,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,EAAE,E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,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;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"]}
@@ -1,24 +1,25 @@
1
- import { Attributes } from '@opentelemetry/api';
2
- import type { ConnectionConfig, PoolActualConfig, Query, QueryOptions } from 'mysql';
3
- import type * as mysqlTypes from 'mysql';
1
+ import type { Pool, Query, QueryOptions } from 'mysql';
2
+ export declare function getConfig(config: any): {
3
+ host: any;
4
+ port: any;
5
+ database: any;
6
+ user: any;
7
+ };
8
+ export declare function getJDBCString(host: string | undefined, port: number | undefined, database: string | undefined): string;
4
9
  /**
5
- * Get an Attributes map from a mysql connection config object
6
- *
7
- * @param config ConnectionConfig
8
- */
9
- export declare function getConnectionAttributes(config: ConnectionConfig | PoolActualConfig): Attributes;
10
- /**
11
- * @returns the database statement being executed.
10
+ * @returns the database query being executed.
12
11
  */
13
- export declare function getDbStatement(query: string | Query | QueryOptions): string;
12
+ export declare function getDbQueryText(query: string | Query | QueryOptions): string;
14
13
  export declare function getDbValues(query: string | Query | QueryOptions, values?: any[]): string;
15
14
  /**
16
15
  * The span name SHOULD be set to a low cardinality value
17
16
  * representing the statement executed on the database.
18
17
  *
18
+ * TODO: revisit span name based on https://github.com/open-telemetry/semantic-conventions/blob/v1.33.0/docs/database/database-spans.md#name
19
+ *
19
20
  * @returns SQL statement without variable arguments or SQL verb
20
21
  */
21
22
  export declare function getSpanName(query: string | Query | QueryOptions): string;
22
23
  export declare function arrayStringifyHelper(arr: Array<unknown> | undefined): string;
23
- export declare function getPoolName(pool: mysqlTypes.Pool): string;
24
+ export declare function getPoolNameOld(pool: Pool): string;
24
25
  //# sourceMappingURL=utils.d.ts.map
@@ -15,37 +15,12 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getPoolName = exports.arrayStringifyHelper = exports.getSpanName = exports.getDbValues = exports.getDbStatement = exports.getConnectionAttributes = void 0;
19
- const semconv_1 = require("./semconv");
20
- /**
21
- * Get an Attributes map from a mysql connection config object
22
- *
23
- * @param config ConnectionConfig
24
- */
25
- function getConnectionAttributes(config) {
26
- const { host, port, database, user } = getConfig(config);
27
- const portNumber = parseInt(port, 10);
28
- if (!isNaN(portNumber)) {
29
- return {
30
- [semconv_1.ATTR_NET_PEER_NAME]: host,
31
- [semconv_1.ATTR_NET_PEER_PORT]: portNumber,
32
- [semconv_1.ATTR_DB_CONNECTION_STRING]: getJDBCString(host, port, database),
33
- [semconv_1.ATTR_DB_NAME]: database,
34
- [semconv_1.ATTR_DB_USER]: user,
35
- };
36
- }
37
- return {
38
- [semconv_1.ATTR_NET_PEER_NAME]: host,
39
- [semconv_1.ATTR_DB_CONNECTION_STRING]: getJDBCString(host, port, database),
40
- [semconv_1.ATTR_DB_NAME]: database,
41
- [semconv_1.ATTR_DB_USER]: user,
42
- };
43
- }
44
- exports.getConnectionAttributes = getConnectionAttributes;
18
+ exports.getPoolNameOld = exports.arrayStringifyHelper = exports.getSpanName = exports.getDbValues = exports.getDbQueryText = exports.getJDBCString = exports.getConfig = void 0;
45
19
  function getConfig(config) {
46
20
  const { host, port, database, user } = (config && config.connectionConfig) || config || {};
47
21
  return { host, port, database, user };
48
22
  }
23
+ exports.getConfig = getConfig;
49
24
  function getJDBCString(host, port, database) {
50
25
  let jdbcString = `jdbc:mysql://${host || 'localhost'}`;
51
26
  if (typeof port === 'number') {
@@ -56,10 +31,11 @@ function getJDBCString(host, port, database) {
56
31
  }
57
32
  return jdbcString;
58
33
  }
34
+ exports.getJDBCString = getJDBCString;
59
35
  /**
60
- * @returns the database statement being executed.
36
+ * @returns the database query being executed.
61
37
  */
62
- function getDbStatement(query) {
38
+ function getDbQueryText(query) {
63
39
  if (typeof query === 'string') {
64
40
  return query;
65
41
  }
@@ -67,7 +43,7 @@ function getDbStatement(query) {
67
43
  return query.sql;
68
44
  }
69
45
  }
70
- exports.getDbStatement = getDbStatement;
46
+ exports.getDbQueryText = getDbQueryText;
71
47
  function getDbValues(query, values) {
72
48
  if (typeof query === 'string') {
73
49
  return arrayStringifyHelper(values);
@@ -83,6 +59,8 @@ exports.getDbValues = getDbValues;
83
59
  * The span name SHOULD be set to a low cardinality value
84
60
  * representing the statement executed on the database.
85
61
  *
62
+ * TODO: revisit span name based on https://github.com/open-telemetry/semantic-conventions/blob/v1.33.0/docs/database/database-spans.md#name
63
+ *
86
64
  * @returns SQL statement without variable arguments or SQL verb
87
65
  */
88
66
  function getSpanName(query) {
@@ -101,7 +79,7 @@ function arrayStringifyHelper(arr) {
101
79
  return '';
102
80
  }
103
81
  exports.arrayStringifyHelper = arrayStringifyHelper;
104
- function getPoolName(pool) {
82
+ function getPoolNameOld(pool) {
105
83
  const c = pool.config.connectionConfig;
106
84
  let poolName = '';
107
85
  poolName += c.host ? `host: '${c.host}', ` : '';
@@ -113,5 +91,5 @@ function getPoolName(pool) {
113
91
  }
114
92
  return poolName.trim();
115
93
  }
116
- exports.getPoolName = getPoolName;
94
+ exports.getPoolNameOld = getPoolNameOld;
117
95
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAGH,uCAMmB;AASnB;;;;GAIG;AACH,SAAgB,uBAAuB,CACrC,MAA2C;IAE3C,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IACzD,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;QACtB,OAAO;YACL,CAAC,4BAAkB,CAAC,EAAE,IAAI;YAC1B,CAAC,4BAAkB,CAAC,EAAE,UAAU;YAChC,CAAC,mCAAyB,CAAC,EAAE,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC;YAChE,CAAC,sBAAY,CAAC,EAAE,QAAQ;YACxB,CAAC,sBAAY,CAAC,EAAE,IAAI;SACrB,CAAC;KACH;IACD,OAAO;QACL,CAAC,4BAAkB,CAAC,EAAE,IAAI;QAC1B,CAAC,mCAAyB,CAAC,EAAE,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC;QAChE,CAAC,sBAAY,CAAC,EAAE,QAAQ;QACxB,CAAC,sBAAY,CAAC,EAAE,IAAI;KACrB,CAAC;AACJ,CAAC;AApBD,0DAoBC;AAED,SAAS,SAAS,CAAC,MAAW;IAC5B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,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* 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 { Attributes } from '@opentelemetry/api';\nimport {\n ATTR_DB_CONNECTION_STRING,\n ATTR_DB_NAME,\n ATTR_DB_USER,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n} from './semconv';\nimport type {\n ConnectionConfig,\n PoolActualConfig,\n Query,\n QueryOptions,\n} from 'mysql';\nimport type * as mysqlTypes from 'mysql';\n\n/**\n * Get an Attributes map from a mysql connection config object\n *\n * @param config ConnectionConfig\n */\nexport function getConnectionAttributes(\n config: ConnectionConfig | PoolActualConfig\n): Attributes {\n const { host, port, database, user } = getConfig(config);\n const portNumber = parseInt(port, 10);\n if (!isNaN(portNumber)) {\n return {\n [ATTR_NET_PEER_NAME]: host,\n [ATTR_NET_PEER_PORT]: portNumber,\n [ATTR_DB_CONNECTION_STRING]: getJDBCString(host, port, database),\n [ATTR_DB_NAME]: database,\n [ATTR_DB_USER]: user,\n };\n }\n return {\n [ATTR_NET_PEER_NAME]: host,\n [ATTR_DB_CONNECTION_STRING]: getJDBCString(host, port, database),\n [ATTR_DB_NAME]: database,\n [ATTR_DB_USER]: user,\n };\n}\n\nfunction getConfig(config: any) {\n const { host, port, database, user } =\n (config && config.connectionConfig) || config || {};\n return { host, port, database, user };\n}\n\nfunction getJDBCString(\n host: string | undefined,\n port: number | undefined,\n database: string | undefined\n) {\n let jdbcString = `jdbc:mysql://${host || 'localhost'}`;\n\n if (typeof port === 'number') {\n jdbcString += `:${port}`;\n }\n\n if (typeof database === 'string') {\n jdbcString += `/${database}`;\n }\n\n return jdbcString;\n}\n\n/**\n * @returns the database statement being executed.\n */\nexport function getDbStatement(query: string | Query | QueryOptions): string {\n if (typeof query === 'string') {\n return query;\n } else {\n return query.sql;\n }\n}\n\nexport function getDbValues(\n query: string | Query | QueryOptions,\n values?: any[]\n): string {\n if (typeof query === 'string') {\n return arrayStringifyHelper(values);\n } else {\n // According to https://github.com/mysqljs/mysql#performing-queries\n // The values argument will override the values in the option object.\n return arrayStringifyHelper(values || query.values);\n }\n}\n\n/**\n * The span name SHOULD be set to a low cardinality value\n * representing the statement executed on the database.\n *\n * @returns SQL statement without variable arguments or SQL verb\n */\nexport function getSpanName(query: string | Query | QueryOptions): string {\n const rawQuery = typeof query === 'object' ? query.sql : query;\n // Extract the SQL verb\n const firstSpace = rawQuery?.indexOf(' ');\n if (typeof firstSpace === 'number' && firstSpace !== -1) {\n return rawQuery?.substring(0, firstSpace);\n }\n return rawQuery;\n}\n\nexport function arrayStringifyHelper(arr: Array<unknown> | undefined): string {\n if (arr) return `[${arr.toString()}]`;\n return '';\n}\n\nexport function getPoolName(pool: mysqlTypes.Pool): string {\n const c = pool.config.connectionConfig;\n let poolName = '';\n poolName += c.host ? `host: '${c.host}', ` : '';\n poolName += c.port ? `port: ${c.port}, ` : '';\n poolName += c.database ? `database: '${c.database}', ` : '';\n poolName += c.user ? `user: '${c.user}'` : '';\n if (!c.user) {\n poolName = poolName.substring(0, poolName.length - 2); //omit last comma\n }\n return poolName.trim();\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH,SAAgB,SAAS,CAAC,MAAW;IACnC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAClC,CAAC,MAAM,IAAI,MAAM,CAAC,gBAAgB,CAAC,IAAI,MAAM,IAAI,EAAE,CAAC;IACtD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AACxC,CAAC;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IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AARD,kCAQC;AAED,SAAgB,oBAAoB,CAAC,GAA+B;IAClE,IAAI,GAAG;QAAE,OAAO,IAAI,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC;IACtC,OAAO,EAAE,CAAC;AACZ,CAAC;AAHD,oDAGC;AAED,SAAgB,cAAc,CAAC,IAAU;IACvC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;IACvC,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,QAAQ,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAChD,QAAQ,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,QAAQ,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;QACX,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB;KACzE;IACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAXD,wCAWC","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 type { Pool, Query, QueryOptions } from 'mysql';\n\nexport function getConfig(config: any) {\n const { host, port, database, user } =\n (config && config.connectionConfig) || config || {};\n return { host, port, database, user };\n}\n\nexport function getJDBCString(\n host: string | undefined,\n port: number | undefined,\n database: string | undefined\n) {\n let jdbcString = `jdbc:mysql://${host || 'localhost'}`;\n\n if (typeof port === 'number') {\n jdbcString += `:${port}`;\n }\n\n if (typeof database === 'string') {\n jdbcString += `/${database}`;\n }\n\n return jdbcString;\n}\n\n/**\n * @returns the database query being executed.\n */\nexport function getDbQueryText(query: string | Query | QueryOptions): string {\n if (typeof query === 'string') {\n return query;\n } else {\n return query.sql;\n }\n}\n\nexport function getDbValues(\n query: string | Query | QueryOptions,\n values?: any[]\n): string {\n if (typeof query === 'string') {\n return arrayStringifyHelper(values);\n } else {\n // According to https://github.com/mysqljs/mysql#performing-queries\n // The values argument will override the values in the option object.\n return arrayStringifyHelper(values || query.values);\n }\n}\n\n/**\n * The span name SHOULD be set to a low cardinality value\n * representing the statement executed on the database.\n *\n * TODO: revisit span name based on https://github.com/open-telemetry/semantic-conventions/blob/v1.33.0/docs/database/database-spans.md#name\n *\n * @returns SQL statement without variable arguments or SQL verb\n */\nexport function getSpanName(query: string | Query | QueryOptions): string {\n const rawQuery = typeof query === 'object' ? query.sql : query;\n // Extract the SQL verb\n const firstSpace = rawQuery?.indexOf(' ');\n if (typeof firstSpace === 'number' && firstSpace !== -1) {\n return rawQuery?.substring(0, firstSpace);\n }\n return rawQuery;\n}\n\nexport function arrayStringifyHelper(arr: Array<unknown> | undefined): string {\n if (arr) return `[${arr.toString()}]`;\n return '';\n}\n\nexport function getPoolNameOld(pool: Pool): string {\n const c = pool.config.connectionConfig;\n let poolName = '';\n poolName += c.host ? `host: '${c.host}', ` : '';\n poolName += c.port ? `port: ${c.port}, ` : '';\n poolName += c.database ? `database: '${c.database}', ` : '';\n poolName += c.user ? `user: '${c.user}'` : '';\n if (!c.user) {\n poolName = poolName.substring(0, poolName.length - 2); //omit last comma\n }\n return poolName.trim();\n}\n"]}
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.54.0";
1
+ export declare const PACKAGE_VERSION = "0.56.0";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-mysql";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -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.54.0';
20
+ exports.PACKAGE_VERSION = '0.56.0';
21
21
  exports.PACKAGE_NAME = '@opentelemetry/instrumentation-mysql';
22
22
  //# sourceMappingURL=version.js.map
@@ -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.54.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-mysql';\n"]}
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.54.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,23 +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.55.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
- "@types/mocha": "10.0.10",
56
- "@types/node": "18.18.14",
57
- "@types/sinon": "17.0.4",
58
- "cross-env": "7.0.3",
59
- "mysql": "2.18.1",
60
- "nyc": "17.1.0",
61
- "rimraf": "5.0.10",
62
- "sinon": "15.2.0",
63
- "typescript": "5.0.4"
55
+ "mysql": "2.18.1"
64
56
  },
65
57
  "dependencies": {
66
- "@opentelemetry/instrumentation": "^0.208.0",
58
+ "@opentelemetry/instrumentation": "^0.210.0",
59
+ "@opentelemetry/semantic-conventions": "^1.33.0",
67
60
  "@types/mysql": "2.15.27"
68
61
  },
69
62
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-mysql#readme",
70
- "gitHead": "94e5b7da4500459e38e8d4dfda93542f22159600"
63
+ "gitHead": "c84212cca7f010b80747cccb9942474e0459df6e"
71
64
  }