@opentelemetry/instrumentation-mysql 0.54.0 → 0.55.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 +31 -15
- package/build/src/instrumentation.d.ts +11 -5
- package/build/src/instrumentation.js +68 -49
- package/build/src/instrumentation.js.map +1 -1
- package/build/src/utils.d.ts +13 -12
- package/build/src/utils.js +10 -32
- package/build/src/utils.js.map +1 -1
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/package.json +5 -12
package/README.md
CHANGED
|
@@ -44,27 +44,43 @@ See [examples/mysql](https://github.com/open-telemetry/opentelemetry-js-contrib/
|
|
|
44
44
|
|
|
45
45
|
### MySQL instrumentation Options
|
|
46
46
|
|
|
47
|
-
| Options
|
|
48
|
-
|
|
|
49
|
-
| [`enhancedDatabaseReporting`](./src/types.ts#L24) | `boolean` | `false` | If true,
|
|
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
|
|
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
|
-
|
|
|
59
|
-
|
|
|
60
|
-
| `db.
|
|
61
|
-
| `db.
|
|
62
|
-
| `db.
|
|
63
|
-
| `db.
|
|
64
|
-
| `db.
|
|
65
|
-
| `db.
|
|
66
|
-
| `net.peer.name`
|
|
67
|
-
| `net.peer.port`
|
|
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
|
+
| Old semconv | Stable semconv | Description |
|
|
80
|
+
| ----------------------------- | -------------- | ----------- |
|
|
81
|
+
| `db.client.connections.usage` | (removed) | The number of connections currently in a given state. See note below. |
|
|
82
|
+
|
|
83
|
+
Note: While `db.client.connections.usage` was replaced with `db.client.connection.count` in the [semconv database migration](https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count), the replacement metric is still unstable, so cannot be enabled via `OTEL_SEMCONV_STABILITY_OPT_IN=database`.
|
|
68
84
|
|
|
69
85
|
## Useful links
|
|
70
86
|
|
|
@@ -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
|
-
|
|
5
|
-
|
|
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
|
|
26
|
+
private _setPoolCallbacks;
|
|
21
27
|
}
|
|
22
28
|
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -18,23 +18,40 @@ 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
|
-
|
|
28
|
-
|
|
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);
|
|
38
|
+
this._updateMetricInstruments();
|
|
32
39
|
}
|
|
33
40
|
_updateMetricInstruments() {
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
if (this._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
|
|
42
|
+
this._connectionsUsageOld = this.meter.createUpDownCounter(semconv_1.METRIC_DB_CLIENT_CONNECTIONS_USAGE, {
|
|
43
|
+
description: 'The number of connections that are currently in state described by the state attribute.',
|
|
44
|
+
unit: '{connection}',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Convenience function for updating the `db.client.connections.usage` metric.
|
|
50
|
+
* The name "count" comes from the eventually replacement for this metric per
|
|
51
|
+
* https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count
|
|
52
|
+
*/
|
|
53
|
+
_connCountAdd(n, poolNameOld, state) {
|
|
54
|
+
this._connectionsUsageOld?.add(n, { state, name: poolNameOld });
|
|
38
55
|
}
|
|
39
56
|
init() {
|
|
40
57
|
return [
|
|
@@ -82,7 +99,7 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
82
99
|
thisPlugin._wrap(pool, 'query', thisPlugin._patchQuery(pool));
|
|
83
100
|
thisPlugin._wrap(pool, 'getConnection', thisPlugin._patchGetConnection(pool));
|
|
84
101
|
thisPlugin._wrap(pool, 'end', thisPlugin._patchPoolEnd(pool));
|
|
85
|
-
thisPlugin.
|
|
102
|
+
thisPlugin._setPoolCallbacks(pool, '');
|
|
86
103
|
return pool;
|
|
87
104
|
};
|
|
88
105
|
};
|
|
@@ -94,15 +111,9 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
94
111
|
const nAll = pool._allConnections.length;
|
|
95
112
|
const nFree = pool._freeConnections.length;
|
|
96
113
|
const nUsed = nAll - nFree;
|
|
97
|
-
const
|
|
98
|
-
thisPlugin.
|
|
99
|
-
|
|
100
|
-
name: poolName,
|
|
101
|
-
});
|
|
102
|
-
thisPlugin._connectionsUsage.add(-nFree, {
|
|
103
|
-
state: 'idle',
|
|
104
|
-
name: poolName,
|
|
105
|
-
});
|
|
114
|
+
const poolNameOld = (0, utils_1.getPoolNameOld)(pool);
|
|
115
|
+
thisPlugin._connCountAdd(-nUsed, poolNameOld, 'used');
|
|
116
|
+
thisPlugin._connCountAdd(-nFree, poolNameOld, 'idle');
|
|
106
117
|
originalPoolEnd.apply(pool, arguments);
|
|
107
118
|
};
|
|
108
119
|
};
|
|
@@ -136,7 +147,7 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
136
147
|
? 'CLUSTER::' + cluster._lastId
|
|
137
148
|
: String(id);
|
|
138
149
|
const pool = nodes[nodeId].pool;
|
|
139
|
-
thisPlugin.
|
|
150
|
+
thisPlugin._setPoolCallbacks(pool, id);
|
|
140
151
|
}
|
|
141
152
|
};
|
|
142
153
|
};
|
|
@@ -191,14 +202,38 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
191
202
|
thisPlugin._unwrap(connection, 'query');
|
|
192
203
|
return originalQuery.apply(connection, arguments);
|
|
193
204
|
}
|
|
205
|
+
const attributes = {};
|
|
206
|
+
const { host, port, database, user } = (0, utils_1.getConfig)(connection.config);
|
|
207
|
+
const portNumber = parseInt(port, 10);
|
|
208
|
+
const dbQueryText = (0, utils_1.getDbQueryText)(query);
|
|
209
|
+
if (thisPlugin._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
|
|
210
|
+
attributes[semconv_1.ATTR_DB_SYSTEM] = semconv_1.DB_SYSTEM_VALUE_MYSQL;
|
|
211
|
+
attributes[semconv_1.ATTR_DB_CONNECTION_STRING] = (0, utils_1.getJDBCString)(host, port, database);
|
|
212
|
+
attributes[semconv_1.ATTR_DB_NAME] = database;
|
|
213
|
+
attributes[semconv_1.ATTR_DB_USER] = user;
|
|
214
|
+
attributes[semconv_1.ATTR_DB_STATEMENT] = dbQueryText;
|
|
215
|
+
}
|
|
216
|
+
if (thisPlugin._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
|
|
217
|
+
attributes[semantic_conventions_1.ATTR_DB_SYSTEM_NAME] = semantic_conventions_1.DB_SYSTEM_NAME_VALUE_MYSQL;
|
|
218
|
+
attributes[semantic_conventions_1.ATTR_DB_NAMESPACE] = database;
|
|
219
|
+
attributes[semantic_conventions_1.ATTR_DB_QUERY_TEXT] = dbQueryText;
|
|
220
|
+
}
|
|
221
|
+
if (thisPlugin._netSemconvStability & instrumentation_1.SemconvStability.OLD) {
|
|
222
|
+
attributes[semconv_1.ATTR_NET_PEER_NAME] = host;
|
|
223
|
+
if (!isNaN(portNumber)) {
|
|
224
|
+
attributes[semconv_1.ATTR_NET_PEER_PORT] = portNumber;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (thisPlugin._netSemconvStability & instrumentation_1.SemconvStability.STABLE) {
|
|
228
|
+
attributes[semantic_conventions_1.ATTR_SERVER_ADDRESS] = host;
|
|
229
|
+
if (!isNaN(portNumber)) {
|
|
230
|
+
attributes[semantic_conventions_1.ATTR_SERVER_PORT] = portNumber;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
194
233
|
const span = thisPlugin.tracer.startSpan((0, utils_1.getSpanName)(query), {
|
|
195
234
|
kind: api_1.SpanKind.CLIENT,
|
|
196
|
-
attributes
|
|
197
|
-
...MySQLInstrumentation.COMMON_ATTRIBUTES,
|
|
198
|
-
...(0, utils_1.getConnectionAttributes)(connection.config),
|
|
199
|
-
},
|
|
235
|
+
attributes,
|
|
200
236
|
});
|
|
201
|
-
span.setAttribute(semconv_1.ATTR_DB_STATEMENT, (0, utils_1.getDbStatement)(query));
|
|
202
237
|
if (thisPlugin.getConfig().enhancedDatabaseReporting) {
|
|
203
238
|
let values;
|
|
204
239
|
if (Array.isArray(_valuesOrCallback)) {
|
|
@@ -248,34 +283,18 @@ class MySQLInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
248
283
|
};
|
|
249
284
|
};
|
|
250
285
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
thisPlugin._connectionsUsage.add(1, {
|
|
256
|
-
state: 'idle',
|
|
257
|
-
name: poolName,
|
|
258
|
-
});
|
|
286
|
+
_setPoolCallbacks(pool, id) {
|
|
287
|
+
const poolNameOld = id || (0, utils_1.getPoolNameOld)(pool);
|
|
288
|
+
pool.on('connection', _connection => {
|
|
289
|
+
this._connCountAdd(1, poolNameOld, 'idle');
|
|
259
290
|
});
|
|
260
|
-
pool.on('acquire',
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
name: poolName,
|
|
264
|
-
});
|
|
265
|
-
thisPlugin._connectionsUsage.add(1, {
|
|
266
|
-
state: 'used',
|
|
267
|
-
name: poolName,
|
|
268
|
-
});
|
|
291
|
+
pool.on('acquire', _connection => {
|
|
292
|
+
this._connCountAdd(-1, poolNameOld, 'idle');
|
|
293
|
+
this._connCountAdd(1, poolNameOld, 'used');
|
|
269
294
|
});
|
|
270
|
-
pool.on('release',
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
name: poolName,
|
|
274
|
-
});
|
|
275
|
-
thisPlugin._connectionsUsage.add(1, {
|
|
276
|
-
state: 'idle',
|
|
277
|
-
name: poolName,
|
|
278
|
-
});
|
|
295
|
+
pool.on('release', _connection => {
|
|
296
|
+
this._connCountAdd(1, poolNameOld, 'idle');
|
|
297
|
+
this._connCountAdd(-1, poolNameOld, 'used');
|
|
279
298
|
});
|
|
280
299
|
}
|
|
281
300
|
}
|
|
@@ -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,CAA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E,QAAQ;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;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,CAA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AAK;wBAC1B,OAAO,EAAE,GAAG,CAAC,OAAO;qBACrB,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"]}
|
package/build/src/utils.d.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
|
24
|
+
export declare function getPoolNameOld(pool: Pool): string;
|
|
24
25
|
//# sourceMappingURL=utils.d.ts.map
|
package/build/src/utils.js
CHANGED
|
@@ -15,37 +15,12 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
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
|
|
36
|
+
* @returns the database query being executed.
|
|
61
37
|
*/
|
|
62
|
-
function
|
|
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.
|
|
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
|
|
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.
|
|
94
|
+
exports.getPoolNameOld = getPoolNameOld;
|
|
117
95
|
//# sourceMappingURL=utils.js.map
|
package/build/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;
|
|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,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"]}
|
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.55.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.55.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.55.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.
|
|
52
|
+
"@opentelemetry/contrib-test-utils": "^0.56.0",
|
|
53
53
|
"@opentelemetry/sdk-metrics": "^2.0.0",
|
|
54
54
|
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
55
|
-
"
|
|
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
58
|
"@opentelemetry/instrumentation": "^0.208.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": "
|
|
63
|
+
"gitHead": "66935ac724cc271f70028035e534d47a4dfbcf12"
|
|
71
64
|
}
|