Skip to content

Commit

Permalink
feat: support mysql2 v1 (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
nozik committed Feb 18, 2022
1 parent 1f68004 commit d3883d3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
14 changes: 10 additions & 4 deletions plugins/node/opentelemetry-instrumentation-mysql2/.tav.yml
@@ -1,6 +1,12 @@
mysql2:
versions: 2.*
commands: npm run test
- versions: 2.*
commands: npm run test

# Fix missing `test-utils` package
pretest: npm run --prefix ../../../ lerna:link
# Fix missing `test-utils` package
pretest: npm run --prefix ../../../ lerna:link
- versions: 1.4.2 || 1.5.0 || 1.5.1 || 1.5.2 || 1.5.3 || 1.6.0 || 1.6.3 || 1.6.4 || 1.6.5 || 1.7.0
# Skip v1.6.2, which is broken
commands: npm run test

# Fix missing `test-utils` package
pretest: npm run --prefix ../../../ lerna:link
Expand Up @@ -20,7 +20,7 @@ npm install --save @opentelemetry/instrumentation-mysql2

## Supported Versions

- `2.x`
- `>= 1.4.2, < 3.0`

## Usage

Expand Down
Expand Up @@ -52,12 +52,15 @@
"@opentelemetry/contrib-test-utils": "^0.29.0",
"@opentelemetry/sdk-trace-base": "1.0.1",
"@types/mocha": "7.0.2",
"@types/mysql2": "github:types/mysql2",
"@types/node": "16.11.21",
"@types/semver": "7.3.8",
"gts": "3.1.0",
"mocha": "7.2.0",
"mysql2": "2.3.0",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"semver": "7.3.5",
"test-all-versions": "5.0.1",
"ts-mocha": "8.0.0",
"typescript": "4.3.5"
Expand Down
Expand Up @@ -49,7 +49,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<
return [
new InstrumentationNodeModuleDefinition<typeof mysqlTypes>(
'mysql2',
['2.*'],
['>= 1.4.2 < 3.0'],
(moduleExports: any, moduleVersion) => {
api.diag.debug(`Patching mysql@${moduleVersion}`);

Expand Down
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import * as semver from 'semver';
import { context, trace, SpanStatusCode } from '@opentelemetry/api';
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
Expand Down Expand Up @@ -669,5 +670,5 @@ function assertSpan(
function isPoolClusterEndIgnoreCallback() {
// Since v2.2.0 `end` function respect callback
// https://github.com/sidorares/node-mysql2/commit/1481015626e506754adc4308e5508356a3a03aa0
return ['2.0.0', '2.0.1', '2.0.2', '2.1.0'].includes(LIB_VERSION);
return semver.lt(LIB_VERSION, '2.2.0');
}

0 comments on commit d3883d3

Please sign in to comment.