@opentelemetry/instrumentation-tedious 0.6.1 → 0.6.2

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
@@ -17,7 +17,7 @@ npm install --save @opentelemetry/instrumentation-tedious
17
17
 
18
18
  ## Supported Versions
19
19
 
20
- - `>=1.11.0`
20
+ - `>=1.11.0 <=15`
21
21
 
22
22
  ## Usage
23
23
 
@@ -43,7 +43,7 @@ class TediousInstrumentation extends instrumentation_1.InstrumentationBase {
43
43
  }
44
44
  init() {
45
45
  return [
46
- new instrumentation_1.InstrumentationNodeModuleDefinition(TediousInstrumentation.COMPONENT, ['*'], (moduleExports, moduleVersion) => {
46
+ new instrumentation_1.InstrumentationNodeModuleDefinition(TediousInstrumentation.COMPONENT, ['>=1.11.0 <=15'], (moduleExports, moduleVersion) => {
47
47
  this._diag.debug(`Patching tedious@${moduleVersion}`);
48
48
  const ConnectionPrototype = moduleExports.Connection.prototype;
49
49
  for (const method of PATCHED_METHODS) {
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAC1C,mCAAsC;AACtC,oEAIwC;AACxC,8EAG6C;AAG7C,mCAA4C;AAC5C,uCAAoC;AAEpC,MAAM,gBAAgB,GAAG,MAAM,CAC7B,wDAAwD,CACzD,CAAC;AACF,MAAM,eAAe,GAAG;IACtB,eAAe;IACf,SAAS;IACT,cAAc;IACd,cAAc;IACd,SAAS;IACT,SAAS;CACV,CAAC;AAcF,SAAS,WAAW,CAAyB,YAAoB;IAC/D,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,EAAE;QAC5C,KAAK,EAAE,YAAY;QACnB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;AACL,CAAC;AAED,MAAa,sBAAuB,SAAQ,qCAE3C;IAGC,YAAY,MAAq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BACL,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;iBACtE;gBAED,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CACrB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,EAC7C,cAAc,EACd,IAAI,EACJ,GAAG,SAAS,CACb,CAAC;YACJ,CAAC;YAED,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,QAAQ,EAAE;gBAC7C,KAAK,EAAE,cAAc,CAAC,MAAM;gBAC5B,QAAQ,EAAE,KAAK;aAChB,CAAC,CAAC;YAEH,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC;IACJ,CAAC;IAEO,mBAAmB,CAAC,OAAiB;QAC3C,OAAO,CAAC,gBAA0B,EAAE,EAAE;YACpC,OAAO,UAEL,GAA6B,EAC7B,QAAiB,EACjB,IAAU;gBAEV,OAAO,CAAC,GAAG,CAAC,CAAC;gBACb,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YACjD,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;;AA/KH,wDAgLC;AA7KiB,gCAAS,GAAG,SAAS,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\nimport * as api from '@opentelemetry/api';\nimport { EventEmitter } from 'events';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n} from '@opentelemetry/instrumentation';\nimport {\n DbSystemValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport type * as tedious from 'tedious';\nimport { TediousInstrumentationConfig } from './types';\nimport { getSpanName, once } from './utils';\nimport { VERSION } from './version';\n\nconst CURRENT_DATABASE = Symbol(\n 'opentelemetry.instrumentation-tedious.current-database'\n);\nconst PATCHED_METHODS = [\n 'callProcedure',\n 'execSql',\n 'execSqlBatch',\n 'execBulkLoad',\n 'prepare',\n 'execute',\n];\n\ntype UnknownFunction = (...args: any[]) => any;\ntype ApproxConnection = EventEmitter & {\n [CURRENT_DATABASE]: string;\n config: any;\n};\ntype ApproxRequest = EventEmitter & {\n sqlTextOrProcedure: string | undefined;\n callback: any;\n table: string | undefined;\n parametersByName: any;\n};\n\nfunction setDatabase(this: ApproxConnection, databaseName: string) {\n Object.defineProperty(this, CURRENT_DATABASE, {\n value: databaseName,\n writable: true,\n });\n}\n\nexport class TediousInstrumentation extends InstrumentationBase<\n typeof tedious\n> {\n static readonly COMPONENT = 'tedious';\n\n constructor(config?: TediousInstrumentationConfig) {\n super('@opentelemetry/instrumentation-tedious', VERSION, config);\n }\n\n protected init() {\n return [\n new InstrumentationNodeModuleDefinition<typeof tedious>(\n TediousInstrumentation.COMPONENT,\n ['*'],\n (moduleExports: any, moduleVersion) => {\n this._diag.debug(`Patching tedious@${moduleVersion}`);\n\n const ConnectionPrototype: any = moduleExports.Connection.prototype;\n for (const method of PATCHED_METHODS) {\n if (isWrapped(ConnectionPrototype[method])) {\n this._unwrap(ConnectionPrototype, method);\n }\n this._wrap(\n ConnectionPrototype,\n method,\n this._patchQuery(method) as any\n );\n }\n\n if (isWrapped(ConnectionPrototype.connect)) {\n this._unwrap(ConnectionPrototype, 'connect');\n }\n this._wrap(ConnectionPrototype, 'connect', this._patchConnect);\n\n return moduleExports;\n },\n (moduleExports: any) => {\n if (moduleExports === undefined) return;\n const ConnectionPrototype: any = moduleExports.Connection.prototype;\n for (const method of PATCHED_METHODS) {\n this._unwrap(ConnectionPrototype, method);\n }\n this._unwrap(ConnectionPrototype, 'connect');\n }\n ),\n ];\n }\n\n private _patchConnect(original: UnknownFunction): UnknownFunction {\n return function patchedConnect(this: ApproxConnection) {\n setDatabase.call(this, this.config?.options?.database);\n\n // remove the listener first in case it's already added\n this.removeListener('databaseChange', setDatabase);\n this.on('databaseChange', setDatabase);\n\n this.once('end', () => {\n this.removeListener('databaseChange', setDatabase);\n });\n return original.apply(this, arguments as unknown as any[]);\n };\n }\n\n private _patchQuery(operation: string) {\n return (originalMethod: UnknownFunction): UnknownFunction => {\n const thisPlugin = this;\n this._diag.debug(\n `TediousInstrumentation: patched Connection.prototype.${operation}`\n );\n\n function patchedMethod(this: ApproxConnection, request: ApproxRequest) {\n if (!(request instanceof EventEmitter)) {\n thisPlugin._diag.warn(\n `Unexpected invocation of patched ${operation} method. Span not recorded`\n );\n return originalMethod.apply(this, arguments as unknown as any[]);\n }\n let procCount = 0;\n let statementCount = 0;\n const incrementStatementCount = () => statementCount++;\n const incrementProcCount = () => procCount++;\n const databaseName = this[CURRENT_DATABASE];\n const sql = (request => {\n // Required for <11.0.9\n if (\n request.sqlTextOrProcedure === 'sp_prepare' &&\n request.parametersByName?.stmt?.value\n ) {\n return request.parametersByName.stmt.value;\n }\n return request.sqlTextOrProcedure;\n })(request);\n\n const span = thisPlugin.tracer.startSpan(\n getSpanName(operation, databaseName, sql, request.table),\n {\n kind: api.SpanKind.CLIENT,\n attributes: {\n [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MSSQL,\n [SemanticAttributes.DB_NAME]: databaseName,\n [SemanticAttributes.NET_PEER_PORT]: this.config?.options?.port,\n [SemanticAttributes.NET_PEER_NAME]: this.config?.server,\n // >=4 uses `authentication` object, older versions just userName and password pair\n [SemanticAttributes.DB_USER]:\n this.config?.userName ??\n this.config?.authentication?.options?.userName,\n [SemanticAttributes.DB_STATEMENT]: sql,\n [SemanticAttributes.DB_SQL_TABLE]: request.table,\n },\n }\n );\n\n const endSpan = once((err?: any) => {\n request.removeListener('done', incrementStatementCount);\n request.removeListener('doneInProc', incrementStatementCount);\n request.removeListener('doneProc', incrementProcCount);\n request.removeListener('error', endSpan);\n this.removeListener('end', endSpan);\n\n span.setAttribute('tedious.procedure_count', procCount);\n span.setAttribute('tedious.statement_count', statementCount);\n if (err) {\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: err.message,\n });\n }\n span.end();\n });\n\n request.on('done', incrementStatementCount);\n request.on('doneInProc', incrementStatementCount);\n request.on('doneProc', incrementProcCount);\n request.once('error', endSpan);\n this.on('end', endSpan);\n\n if (typeof request.callback === 'function') {\n thisPlugin._wrap(\n request,\n 'callback',\n thisPlugin._patchCallbackQuery(endSpan)\n );\n } else {\n thisPlugin._diag.error('Expected request.callback to be a function');\n }\n\n return api.context.with(\n api.trace.setSpan(api.context.active(), span),\n originalMethod,\n this,\n ...arguments\n );\n }\n\n Object.defineProperty(patchedMethod, 'length', {\n value: originalMethod.length,\n writable: false,\n });\n\n return patchedMethod;\n };\n }\n\n private _patchCallbackQuery(endSpan: Function) {\n return (originalCallback: Function) => {\n return function (\n this: any,\n err: Error | undefined | null,\n rowCount?: number,\n rows?: any\n ) {\n endSpan(err);\n return originalCallback.apply(this, arguments);\n };\n };\n }\n}\n"]}
1
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAC1C,mCAAsC;AACtC,oEAIwC;AACxC,8EAG6C;AAG7C,mCAA4C;AAC5C,uCAAoC;AAEpC,MAAM,gBAAgB,GAAG,MAAM,CAC7B,wDAAwD,CACzD,CAAC;AACF,MAAM,eAAe,GAAG;IACtB,eAAe;IACf,SAAS;IACT,cAAc;IACd,cAAc;IACd,SAAS;IACT,SAAS;CACV,CAAC;AAcF,SAAS,WAAW,CAAyB,YAAoB;IAC/D,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,EAAE;QAC5C,KAAK,EAAE,YAAY;QACn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AAC,KAAK,CACd,OAAO,EACP,UAAU,EACV,UAAU,CAAC,mBAAmB,CAAC,OAAO,CAAC,CACxC,CAAC;iBACH;qBAAM;oBACL,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;iBACtE;gBAED,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CACrB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,EAC7C,cAAc,EACd,IAAI,EACJ,GAAG,SAAS,CACb,CAAC;YACJ,CAAC;YAED,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,QAAQ,EAAE;gBAC7C,KAAK,EAAE,cAAc,CAAC,MAAM;gBAC5B,QAAQ,EAAE,KAAK;aAChB,CAAC,CAAC;YAEH,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC;IACJ,CAAC;IAEO,mBAAmB,CAAC,OAAiB;QAC3C,OAAO,CAAC,gBAA0B,EAAE,EAAE;YACpC,OAAO,UAEL,GAA6B,EAC7B,QAAiB,EACjB,IAAU;gBAEV,OAAO,CAAC,GAAG,CAAC,CAAC;gBACb,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YACjD,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;;AA/KH,wDAgLC;AA7KiB,gCAAS,GAAG,SAAS,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\nimport * as api from '@opentelemetry/api';\nimport { EventEmitter } from 'events';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n} from '@opentelemetry/instrumentation';\nimport {\n DbSystemValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport type * as tedious from 'tedious';\nimport { TediousInstrumentationConfig } from './types';\nimport { getSpanName, once } from './utils';\nimport { VERSION } from './version';\n\nconst CURRENT_DATABASE = Symbol(\n 'opentelemetry.instrumentation-tedious.current-database'\n);\nconst PATCHED_METHODS = [\n 'callProcedure',\n 'execSql',\n 'execSqlBatch',\n 'execBulkLoad',\n 'prepare',\n 'execute',\n];\n\ntype UnknownFunction = (...args: any[]) => any;\ntype ApproxConnection = EventEmitter & {\n [CURRENT_DATABASE]: string;\n config: any;\n};\ntype ApproxRequest = EventEmitter & {\n sqlTextOrProcedure: string | undefined;\n callback: any;\n table: string | undefined;\n parametersByName: any;\n};\n\nfunction setDatabase(this: ApproxConnection, databaseName: string) {\n Object.defineProperty(this, CURRENT_DATABASE, {\n value: databaseName,\n writable: true,\n });\n}\n\nexport class TediousInstrumentation extends InstrumentationBase<\n typeof tedious\n> {\n static readonly COMPONENT = 'tedious';\n\n constructor(config?: TediousInstrumentationConfig) {\n super('@opentelemetry/instrumentation-tedious', VERSION, config);\n }\n\n protected init() {\n return [\n new InstrumentationNodeModuleDefinition<typeof tedious>(\n TediousInstrumentation.COMPONENT,\n ['>=1.11.0 <=15'],\n (moduleExports: any, moduleVersion) => {\n this._diag.debug(`Patching tedious@${moduleVersion}`);\n\n const ConnectionPrototype: any = moduleExports.Connection.prototype;\n for (const method of PATCHED_METHODS) {\n if (isWrapped(ConnectionPrototype[method])) {\n this._unwrap(ConnectionPrototype, method);\n }\n this._wrap(\n ConnectionPrototype,\n method,\n this._patchQuery(method) as any\n );\n }\n\n if (isWrapped(ConnectionPrototype.connect)) {\n this._unwrap(ConnectionPrototype, 'connect');\n }\n this._wrap(ConnectionPrototype, 'connect', this._patchConnect);\n\n return moduleExports;\n },\n (moduleExports: any) => {\n if (moduleExports === undefined) return;\n const ConnectionPrototype: any = moduleExports.Connection.prototype;\n for (const method of PATCHED_METHODS) {\n this._unwrap(ConnectionPrototype, method);\n }\n this._unwrap(ConnectionPrototype, 'connect');\n }\n ),\n ];\n }\n\n private _patchConnect(original: UnknownFunction): UnknownFunction {\n return function patchedConnect(this: ApproxConnection) {\n setDatabase.call(this, this.config?.options?.database);\n\n // remove the listener first in case it's already added\n this.removeListener('databaseChange', setDatabase);\n this.on('databaseChange', setDatabase);\n\n this.once('end', () => {\n this.removeListener('databaseChange', setDatabase);\n });\n return original.apply(this, arguments as unknown as any[]);\n };\n }\n\n private _patchQuery(operation: string) {\n return (originalMethod: UnknownFunction): UnknownFunction => {\n const thisPlugin = this;\n this._diag.debug(\n `TediousInstrumentation: patched Connection.prototype.${operation}`\n );\n\n function patchedMethod(this: ApproxConnection, request: ApproxRequest) {\n if (!(request instanceof EventEmitter)) {\n thisPlugin._diag.warn(\n `Unexpected invocation of patched ${operation} method. Span not recorded`\n );\n return originalMethod.apply(this, arguments as unknown as any[]);\n }\n let procCount = 0;\n let statementCount = 0;\n const incrementStatementCount = () => statementCount++;\n const incrementProcCount = () => procCount++;\n const databaseName = this[CURRENT_DATABASE];\n const sql = (request => {\n // Required for <11.0.9\n if (\n request.sqlTextOrProcedure === 'sp_prepare' &&\n request.parametersByName?.stmt?.value\n ) {\n return request.parametersByName.stmt.value;\n }\n return request.sqlTextOrProcedure;\n })(request);\n\n const span = thisPlugin.tracer.startSpan(\n getSpanName(operation, databaseName, sql, request.table),\n {\n kind: api.SpanKind.CLIENT,\n attributes: {\n [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MSSQL,\n [SemanticAttributes.DB_NAME]: databaseName,\n [SemanticAttributes.NET_PEER_PORT]: this.config?.options?.port,\n [SemanticAttributes.NET_PEER_NAME]: this.config?.server,\n // >=4 uses `authentication` object, older versions just userName and password pair\n [SemanticAttributes.DB_USER]:\n this.config?.userName ??\n this.config?.authentication?.options?.userName,\n [SemanticAttributes.DB_STATEMENT]: sql,\n [SemanticAttributes.DB_SQL_TABLE]: request.table,\n },\n }\n );\n\n const endSpan = once((err?: any) => {\n request.removeListener('done', incrementStatementCount);\n request.removeListener('doneInProc', incrementStatementCount);\n request.removeListener('doneProc', incrementProcCount);\n request.removeListener('error', endSpan);\n this.removeListener('end', endSpan);\n\n span.setAttribute('tedious.procedure_count', procCount);\n span.setAttribute('tedious.statement_count', statementCount);\n if (err) {\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: err.message,\n });\n }\n span.end();\n });\n\n request.on('done', incrementStatementCount);\n request.on('doneInProc', incrementStatementCount);\n request.on('doneProc', incrementProcCount);\n request.once('error', endSpan);\n this.on('end', endSpan);\n\n if (typeof request.callback === 'function') {\n thisPlugin._wrap(\n request,\n 'callback',\n thisPlugin._patchCallbackQuery(endSpan)\n );\n } else {\n thisPlugin._diag.error('Expected request.callback to be a function');\n }\n\n return api.context.with(\n api.trace.setSpan(api.context.active(), span),\n originalMethod,\n this,\n ...arguments\n );\n }\n\n Object.defineProperty(patchedMethod, 'length', {\n value: originalMethod.length,\n writable: false,\n });\n\n return patchedMethod;\n };\n }\n\n private _patchCallbackQuery(endSpan: Function) {\n return (originalCallback: Function) => {\n return function (\n this: any,\n err: Error | undefined | null,\n rowCount?: number,\n rows?: any\n ) {\n endSpan(err);\n return originalCallback.apply(this, arguments);\n };\n };\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.6.1";
1
+ export declare const VERSION = "0.6.2";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -17,5 +17,5 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.VERSION = '0.6.1';
20
+ exports.VERSION = '0.6.2';
21
21
  //# 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,OAAO,GAAG,OAAO,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 VERSION = '0.6.1';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,OAAO,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 VERSION = '0.6.2';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-tedious",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "OpenTelemetry instrumentation for `tedious`",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -49,23 +49,23 @@
49
49
  "devDependencies": {
50
50
  "@opentelemetry/api": "^1.3.0",
51
51
  "@opentelemetry/context-async-hooks": "^1.8.0",
52
- "@opentelemetry/contrib-test-utils": "^0.34.1",
52
+ "@opentelemetry/contrib-test-utils": "^0.34.2",
53
53
  "@opentelemetry/sdk-trace-base": "^1.8.0",
54
54
  "@types/mocha": "7.0.2",
55
- "@types/node": "18.16.19",
55
+ "@types/node": "18.6.5",
56
56
  "mocha": "7.2.0",
57
57
  "nyc": "15.1.0",
58
- "rimraf": "5.0.1",
59
- "tedious": "14.1.0",
58
+ "rimraf": "5.0.5",
59
+ "tedious": "15.1.3",
60
60
  "test-all-versions": "5.0.1",
61
61
  "ts-mocha": "10.0.0",
62
62
  "typescript": "4.4.4"
63
63
  },
64
64
  "dependencies": {
65
- "@opentelemetry/instrumentation": "^0.41.2",
65
+ "@opentelemetry/instrumentation": "^0.44.0",
66
66
  "@opentelemetry/semantic-conventions": "^1.0.0",
67
- "@types/tedious": "^4.0.6"
67
+ "@types/tedious": "^4.0.10"
68
68
  },
69
69
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-tedious#readme",
70
- "gitHead": "b3d30afe7376760d211b20c4fb45988ac58c1d85"
70
+ "gitHead": "a8c225d2febcac561a70ca586d3efd5a84f9f3fa"
71
71
  }