@opentelemetry/instrumentation-mysql2
Advanced tools
Comparing version 0.45.0 to 0.45.1
@@ -26,2 +26,3 @@ "use strict"; | ||
const version_1 = require("./version"); | ||
const supportedVersions = ['>=1.4.2 <4']; | ||
class MySQL2Instrumentation extends instrumentation_1.InstrumentationBase { | ||
@@ -32,21 +33,42 @@ constructor(config = {}) { | ||
init() { | ||
let format; | ||
function setFormatFunction(moduleExports) { | ||
if (!format && moduleExports.format) { | ||
format = moduleExports.format; | ||
} | ||
} | ||
const patch = (ConnectionPrototype) => { | ||
if ((0, instrumentation_1.isWrapped)(ConnectionPrototype.query)) { | ||
this._unwrap(ConnectionPrototype, 'query'); | ||
} | ||
this._wrap(ConnectionPrototype, 'query', this._patchQuery(format, false)); | ||
if ((0, instrumentation_1.isWrapped)(ConnectionPrototype.execute)) { | ||
this._unwrap(ConnectionPrototype, 'execute'); | ||
} | ||
this._wrap(ConnectionPrototype, 'execute', this._patchQuery(format, true)); | ||
}; | ||
const unpatch = (ConnectionPrototype) => { | ||
this._unwrap(ConnectionPrototype, 'query'); | ||
this._unwrap(ConnectionPrototype, 'execute'); | ||
}; | ||
return [ | ||
new instrumentation_1.InstrumentationNodeModuleDefinition('mysql2', ['>=1.4.2 <4'], (moduleExports) => { | ||
const ConnectionPrototype = (0, utils_1.getConnectionPrototypeToInstrument)(moduleExports.Connection); | ||
if ((0, instrumentation_1.isWrapped)(ConnectionPrototype.query)) { | ||
this._unwrap(ConnectionPrototype, 'query'); | ||
} | ||
this._wrap(ConnectionPrototype, 'query', this._patchQuery(moduleExports.format, false)); | ||
if ((0, instrumentation_1.isWrapped)(ConnectionPrototype.execute)) { | ||
this._unwrap(ConnectionPrototype, 'execute'); | ||
} | ||
this._wrap(ConnectionPrototype, 'execute', this._patchQuery(moduleExports.format, true)); | ||
new instrumentation_1.InstrumentationNodeModuleDefinition('mysql2', supportedVersions, (moduleExports) => { | ||
setFormatFunction(moduleExports); | ||
return moduleExports; | ||
}, (moduleExports) => { | ||
if (moduleExports === undefined) | ||
return; | ||
const ConnectionPrototype = moduleExports.Connection.prototype; | ||
this._unwrap(ConnectionPrototype, 'query'); | ||
this._unwrap(ConnectionPrototype, 'execute'); | ||
}), | ||
}, () => { }, [ | ||
new instrumentation_1.InstrumentationNodeModuleFile('mysql2/promise.js', supportedVersions, (moduleExports) => { | ||
setFormatFunction(moduleExports); | ||
return moduleExports; | ||
}, () => { }), | ||
new instrumentation_1.InstrumentationNodeModuleFile('mysql2/lib/connection.js', supportedVersions, (moduleExports) => { | ||
const ConnectionPrototype = (0, utils_1.getConnectionPrototypeToInstrument)(moduleExports); | ||
patch(ConnectionPrototype); | ||
return moduleExports; | ||
}, (moduleExports) => { | ||
if (moduleExports === undefined) | ||
return; | ||
const ConnectionPrototype = (0, utils_1.getConnectionPrototypeToInstrument)(moduleExports); | ||
unpatch(ConnectionPrototype); | ||
}), | ||
]), | ||
]; | ||
@@ -53,0 +75,0 @@ } |
import { Attributes } from '@opentelemetry/api'; | ||
import type * as mysqlTypes from 'mysql2'; | ||
declare type formatType = typeof mysqlTypes.format; | ||
interface QueryOptions { | ||
@@ -29,3 +31,3 @@ sql: string; | ||
*/ | ||
export declare function getDbStatement(query: string | Query | QueryOptions, format: (sql: string, values: any[], stringifyObjects?: boolean, timeZone?: string) => string, values?: any[]): string; | ||
export declare function getDbStatement(query: string | Query | QueryOptions, format?: formatType, values?: any[]): string; | ||
/** | ||
@@ -32,0 +34,0 @@ * The span name SHOULD be set to a low cardinality value |
@@ -65,2 +65,5 @@ "use strict"; | ||
function getDbStatement(query, format, values) { | ||
if (!format) { | ||
return typeof query === 'string' ? query : query.sql; | ||
} | ||
if (typeof query === 'string') { | ||
@@ -67,0 +70,0 @@ return values ? format(query, values) : query; |
@@ -1,3 +0,3 @@ | ||
export declare const PACKAGE_VERSION = "0.45.0"; | ||
export declare const PACKAGE_VERSION = "0.45.1"; | ||
export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-mysql2"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,4 +20,4 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.PACKAGE_VERSION = '0.45.0'; | ||
exports.PACKAGE_VERSION = '0.45.1'; | ||
exports.PACKAGE_NAME = '@opentelemetry/instrumentation-mysql2'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-mysql2", | ||
"version": "0.45.0", | ||
"version": "0.45.1", | ||
"description": "OpenTelemetry instrumentation for `mysql2` database client for MySQL", | ||
@@ -66,3 +66,3 @@ "main": "build/src/index.js", | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql2#readme", | ||
"gitHead": "3ef5205e5353010184c69ff7b9f0f4830f0932de" | ||
"gitHead": "b641e1bd77fa1c7b0949e5d938c0952b88f42753" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
60852
423