@opentelemetry/instrumentation-tedious 0.25.0 → 0.27.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
@@ -56,6 +56,13 @@ Attributes collected:
56
56
  | `net.peer.name` | Remote hostname or similar. |
57
57
  | `net.peer.port` | Remote port number. |
58
58
 
59
+ ### Trace Context Propagation
60
+
61
+ Database trace context propagation can be enabled by setting `enableTraceContextPropagation`to `true`.
62
+ This uses the [SET CONTEXT_INFO](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-context-info-transact-sql?view=sql-server-ver16)
63
+ command to set [traceparent](https://www.w3.org/TR/trace-context/#traceparent-header)information
64
+ for the current connection, which results in **an additional round-trip to the database**.
65
+
59
66
  ## Useful links
60
67
 
61
68
  - For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
@@ -1,10 +1,18 @@
1
1
  import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
2
2
  import { TediousInstrumentationConfig } from './types';
3
+ export declare const INJECTED_CTX: unique symbol;
3
4
  export declare class TediousInstrumentation extends InstrumentationBase<TediousInstrumentationConfig> {
4
5
  static readonly COMPONENT = "tedious";
5
6
  constructor(config?: TediousInstrumentationConfig);
6
7
  protected init(): InstrumentationNodeModuleDefinition[];
7
8
  private _patchConnect;
9
+ private _buildTraceparent;
10
+ /**
11
+ * Fire a one-off `SET CONTEXT_INFO @opentelemetry_traceparent` on the same
12
+ * connection. Marks the request with INJECTED_CTX so our patch skips it.
13
+ */
14
+ private _injectContextInfo;
15
+ private _shouldInjectFor;
8
16
  private _patchQuery;
9
17
  private _patchCallbackQuery;
10
18
  }
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.TediousInstrumentation = void 0;
18
+ exports.TediousInstrumentation = exports.INJECTED_CTX = void 0;
19
19
  const api = require("@opentelemetry/api");
20
20
  const events_1 = require("events");
21
21
  const instrumentation_1 = require("@opentelemetry/instrumentation");
@@ -24,6 +24,7 @@ const utils_1 = require("./utils");
24
24
  /** @knipignore */
25
25
  const version_1 = require("./version");
26
26
  const CURRENT_DATABASE = Symbol('opentelemetry.instrumentation-tedious.current-database');
27
+ exports.INJECTED_CTX = Symbol('opentelemetry.instrumentation-tedious.context-info-injected');
27
28
  const PATCHED_METHODS = [
28
29
  'callProcedure',
29
30
  'execSql',
@@ -51,7 +52,7 @@ class TediousInstrumentation extends instrumentation_1.InstrumentationBase {
51
52
  if ((0, instrumentation_1.isWrapped)(ConnectionPrototype[method])) {
52
53
  this._unwrap(ConnectionPrototype, method);
53
54
  }
54
- this._wrap(ConnectionPrototype, method, this._patchQuery(method));
55
+ this._wrap(ConnectionPrototype, method, this._patchQuery(method, moduleExports));
55
56
  }
56
57
  if ((0, instrumentation_1.isWrapped)(ConnectionPrototype.connect)) {
57
58
  this._unwrap(ConnectionPrototype, 'connect');
@@ -81,10 +82,45 @@ class TediousInstrumentation extends instrumentation_1.InstrumentationBase {
81
82
  return original.apply(this, arguments);
82
83
  };
83
84
  }
84
- _patchQuery(operation) {
85
+ _buildTraceparent(span) {
86
+ const sc = span.spanContext();
87
+ return `00-${sc.traceId}-${sc.spanId}-0${Number(sc.traceFlags || api.TraceFlags.NONE).toString(16)}`;
88
+ }
89
+ /**
90
+ * Fire a one-off `SET CONTEXT_INFO @opentelemetry_traceparent` on the same
91
+ * connection. Marks the request with INJECTED_CTX so our patch skips it.
92
+ */
93
+ _injectContextInfo(connection, tediousModule, traceparent) {
94
+ return new Promise(resolve => {
95
+ try {
96
+ const sql = 'set context_info @opentelemetry_traceparent';
97
+ const req = new tediousModule.Request(sql, (_err) => {
98
+ resolve();
99
+ });
100
+ Object.defineProperty(req, exports.INJECTED_CTX, { value: true });
101
+ const buf = Buffer.from(traceparent, 'utf8');
102
+ req.addParameter('opentelemetry_traceparent', tediousModule.TYPES.VarBinary, buf, { length: buf.length });
103
+ connection.execSql(req);
104
+ }
105
+ catch {
106
+ resolve();
107
+ }
108
+ });
109
+ }
110
+ _shouldInjectFor(operation) {
111
+ return (operation === 'execSql' ||
112
+ operation === 'execSqlBatch' ||
113
+ operation === 'callProcedure' ||
114
+ operation === 'execute');
115
+ }
116
+ _patchQuery(operation, tediousModule) {
85
117
  return (originalMethod) => {
86
118
  const thisPlugin = this;
87
119
  function patchedMethod(request) {
120
+ // Skip our own injected request
121
+ if (request?.[exports.INJECTED_CTX]) {
122
+ return originalMethod.apply(this, arguments);
123
+ }
88
124
  if (!(request instanceof events_1.EventEmitter)) {
89
125
  thisPlugin._diag.warn(`Unexpected invocation of patched ${operation} method. Span not recorded`);
90
126
  return originalMethod.apply(this, arguments);
@@ -143,7 +179,18 @@ class TediousInstrumentation extends instrumentation_1.InstrumentationBase {
143
179
  else {
144
180
  thisPlugin._diag.error('Expected request.callback to be a function');
145
181
  }
146
- return api.context.with(api.trace.setSpan(api.context.active(), span), originalMethod, this, ...arguments);
182
+ const runUserRequest = () => {
183
+ return api.context.with(api.trace.setSpan(api.context.active(), span), originalMethod, this, ...arguments);
184
+ };
185
+ const cfg = thisPlugin.getConfig();
186
+ const shouldInject = cfg.enableTraceContextPropagation &&
187
+ thisPlugin._shouldInjectFor(operation);
188
+ if (!shouldInject)
189
+ return runUserRequest();
190
+ const traceparent = thisPlugin._buildTraceparent(span);
191
+ void thisPlugin
192
+ ._injectContextInfo(this, tediousModule, traceparent)
193
+ .finally(runUserRequest);
147
194
  }
148
195
  Object.defineProperty(patchedMethod, 'length', {
149
196
  value: originalMethod.length,
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAC1C,mCAAsC;AACtC,oEAIwC;AACxC,uCASmB;AAGnB,mCAA4C;AAC5C,kBAAkB;AAClB,uCAA0D;AAE1D,MAAM,gBAAgB,GAAG,MAAM,C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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;;AAxKU,wDAAsB","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 DB_SYSTEM_VALUE_MSSQL,\n ATTR_DB_NAME,\n ATTR_DB_SQL_TABLE,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n ATTR_DB_USER,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n} from './semconv';\nimport type * as tedious from 'tedious';\nimport { TediousInstrumentationConfig } from './types';\nimport { getSpanName, once } from './utils';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_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<TediousInstrumentationConfig> {\n static readonly COMPONENT = 'tedious';\n\n constructor(config: TediousInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n protected init() {\n return [\n new InstrumentationNodeModuleDefinition(\n TediousInstrumentation.COMPONENT,\n ['>=1.11.0 <20'],\n (moduleExports: typeof tedious) => {\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: typeof tedious) => {\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\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 [ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_MSSQL,\n [ATTR_DB_NAME]: databaseName,\n [ATTR_NET_PEER_PORT]: this.config?.options?.port,\n [ATTR_NET_PEER_NAME]: this.config?.server,\n // >=4 uses `authentication` object, older versions just userName and password pair\n [ATTR_DB_USER]:\n this.config?.userName ??\n this.config?.authentication?.options?.userName,\n [ATTR_DB_STATEMENT]: sql,\n [ATTR_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,uCASmB;AAGnB,mCAA4C;AAC5C,kBAAkB;AAClB,uCAA0D;AAE1D,MAAM,gBAAgB,GAAG,MAAM,CAC7B,wDAAwD,CACzD,CAAC;AAEW,QAAA,YAAY,GAAG,MAAM,CAChC,6DAA6D,CAC9D,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,eAAe;IACf,SAAS;IACT,cAAc;IACd,cAAc;IACd,SAAS;IACT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QACJ,CAAC,CAAC;IACJ,CAAC;;AAzOU,wDAAsB","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 DB_SYSTEM_VALUE_MSSQL,\n ATTR_DB_NAME,\n ATTR_DB_SQL_TABLE,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n ATTR_DB_USER,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n} from './semconv';\nimport type * as tedious from 'tedious';\nimport { TediousInstrumentationConfig } from './types';\nimport { getSpanName, once } from './utils';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nconst CURRENT_DATABASE = Symbol(\n 'opentelemetry.instrumentation-tedious.current-database'\n);\n\nexport const INJECTED_CTX = Symbol(\n 'opentelemetry.instrumentation-tedious.context-info-injected'\n);\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<TediousInstrumentationConfig> {\n static readonly COMPONENT = 'tedious';\n\n constructor(config: TediousInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n protected init() {\n return [\n new InstrumentationNodeModuleDefinition(\n TediousInstrumentation.COMPONENT,\n ['>=1.11.0 <20'],\n (moduleExports: typeof tedious) => {\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, moduleExports) 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: typeof tedious) => {\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 _buildTraceparent(span: api.Span): string {\n const sc = span.spanContext();\n return `00-${sc.traceId}-${sc.spanId}-0${Number(sc.traceFlags || api.TraceFlags.NONE).toString(16)}`;\n }\n\n /**\n * Fire a one-off `SET CONTEXT_INFO @opentelemetry_traceparent` on the same\n * connection. Marks the request with INJECTED_CTX so our patch skips it.\n */\n private _injectContextInfo(\n connection: any,\n tediousModule: typeof tedious,\n traceparent: string\n ): Promise<void> {\n return new Promise(resolve => {\n try {\n const sql = 'set context_info @opentelemetry_traceparent';\n const req = new tediousModule.Request(sql, (_err: any) => {\n resolve();\n });\n Object.defineProperty(req, INJECTED_CTX, { value: true });\n const buf = Buffer.from(traceparent, 'utf8');\n req.addParameter(\n 'opentelemetry_traceparent',\n (tediousModule as any).TYPES.VarBinary,\n buf,\n { length: buf.length }\n );\n\n connection.execSql(req);\n } catch {\n resolve();\n }\n });\n }\n\n private _shouldInjectFor(operation: string): boolean {\n return (\n operation === 'execSql' ||\n operation === 'execSqlBatch' ||\n operation === 'callProcedure' ||\n operation === 'execute'\n );\n }\n\n private _patchQuery(operation: string, tediousModule: typeof tedious) {\n return (originalMethod: UnknownFunction): UnknownFunction => {\n const thisPlugin = this;\n\n function patchedMethod(this: ApproxConnection, request: ApproxRequest) {\n // Skip our own injected request\n if ((request as any)?.[INJECTED_CTX]) {\n return originalMethod.apply(this, arguments as unknown as any[]);\n }\n\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 [ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_MSSQL,\n [ATTR_DB_NAME]: databaseName,\n [ATTR_NET_PEER_PORT]: this.config?.options?.port,\n [ATTR_NET_PEER_NAME]: this.config?.server,\n // >=4 uses `authentication` object, older versions just userName and password pair\n [ATTR_DB_USER]:\n this.config?.userName ??\n this.config?.authentication?.options?.userName,\n [ATTR_DB_STATEMENT]: sql,\n [ATTR_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 const runUserRequest = () => {\n return api.context.with(\n api.trace.setSpan(api.context.active(), span),\n originalMethod,\n this,\n ...arguments\n );\n };\n\n const cfg = thisPlugin.getConfig();\n const shouldInject =\n cfg.enableTraceContextPropagation &&\n thisPlugin._shouldInjectFor(operation);\n\n if (!shouldInject) return runUserRequest();\n\n const traceparent = thisPlugin._buildTraceparent(span);\n \n void thisPlugin\n ._injectContextInfo(this, tediousModule, traceparent)\n .finally(runUserRequest);\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,3 +1,10 @@
1
1
  import { InstrumentationConfig } from '@opentelemetry/instrumentation';
2
- export type TediousInstrumentationConfig = InstrumentationConfig;
2
+ export interface TediousInstrumentationConfig extends InstrumentationConfig {
3
+ /**
4
+ * If true, injects the current DB span's W3C traceparent into SQL Server
5
+ * session state via `SET CONTEXT_INFO @opentelemetry_traceparent` (varbinary).
6
+ * Off by default to avoid the extra round-trip per request.
7
+ */
8
+ enableTraceContextPropagation?: boolean;
9
+ }
3
10
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","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 { InstrumentationConfig } from '@opentelemetry/instrumentation';\n\nexport type TediousInstrumentationConfig = InstrumentationConfig;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","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 { InstrumentationConfig } from '@opentelemetry/instrumentation';\nexport interface TediousInstrumentationConfig extends InstrumentationConfig {\n /**\n * If true, injects the current DB span's W3C traceparent into SQL Server\n * session state via `SET CONTEXT_INFO @opentelemetry_traceparent` (varbinary).\n * Off by default to avoid the extra round-trip per request.\n */\n enableTraceContextPropagation?: boolean;\n}\n"]}
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.25.0";
1
+ export declare const PACKAGE_VERSION = "0.27.0";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-tedious";
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.25.0';
20
+ exports.PACKAGE_VERSION = '0.27.0';
21
21
  exports.PACKAGE_NAME = '@opentelemetry/instrumentation-tedious';
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,wCAAwC,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.25.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-tedious';\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,wCAAwC,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.27.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-tedious';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-tedious",
3
- "version": "0.25.0",
3
+ "version": "0.27.0",
4
4
  "description": "OpenTelemetry instrumentation for `tedious` database client for Microsoft SQL Server",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -13,8 +13,6 @@
13
13
  "clean": "rimraf build/*",
14
14
  "compile": "tsc -p .",
15
15
  "compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-tedious",
16
- "lint:fix": "eslint . --ext=ts,js,mjs --fix",
17
- "lint": "eslint . --ext=ts,js,mjs",
18
16
  "prepublishOnly": "npm run compile",
19
17
  "tdd": "npm run test -- --watch-extensions ts --watch",
20
18
  "test": "nyc --no-clean mocha 'test/**/*.test.ts'",
@@ -56,22 +54,22 @@
56
54
  "devDependencies": {
57
55
  "@opentelemetry/api": "^1.3.0",
58
56
  "@opentelemetry/context-async-hooks": "^2.0.0",
59
- "@opentelemetry/contrib-test-utils": "^0.53.0",
57
+ "@opentelemetry/contrib-test-utils": "^0.55.0",
60
58
  "@opentelemetry/sdk-trace-base": "^2.0.0",
61
59
  "@types/mocha": "10.0.10",
62
60
  "@types/node": "18.18.14",
63
61
  "cross-env": "7.0.3",
64
62
  "nyc": "17.1.0",
65
63
  "rimraf": "5.0.10",
66
- "semver": "7.7.2",
64
+ "semver": "7.7.3",
67
65
  "tedious": "17.0.0",
68
66
  "test-all-versions": "6.1.0",
69
67
  "typescript": "5.0.4"
70
68
  },
71
69
  "dependencies": {
72
- "@opentelemetry/instrumentation": "^0.206.0",
70
+ "@opentelemetry/instrumentation": "^0.208.0",
73
71
  "@types/tedious": "^4.0.14"
74
72
  },
75
73
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-tedious#readme",
76
- "gitHead": "333e026413f082f90859bb778abf7519fbffa940"
74
+ "gitHead": "94e5b7da4500459e38e8d4dfda93542f22159600"
77
75
  }