diff --git a/plugins/node/opentelemetry-instrumentation-cassandra/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-cassandra/src/instrumentation.ts index 0a04570309..6982586ba6 100644 --- a/plugins/node/opentelemetry-instrumentation-cassandra/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-cassandra/src/instrumentation.ts @@ -46,7 +46,7 @@ export class CassandraDriverInstrumentation extends InstrumentationBase { } protected init() { - return new InstrumentationNodeModuleDefinition( + return new InstrumentationNodeModuleDefinition( 'cassandra-driver', supportedVersions, driverModule => { @@ -290,7 +290,7 @@ export class CassandraDriverInstrumentation extends InstrumentationBase { }; } - public startSpan( + private startSpan( { op, query }: { op: string; query?: unknown }, client: CassandraDriver.Client ): Span { diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts index c801d6136b..91de6e7677 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts @@ -34,7 +34,7 @@ const DEFAULT_CONFIG: types.KnexInstrumentationConfig = { maxQueryLength: 1022, }; -export class KnexInstrumentation extends InstrumentationBase { +export class KnexInstrumentation extends InstrumentationBase { constructor(config: types.KnexInstrumentationConfig = {}) { super( `@opentelemetry/instrumentation-${constants.MODULE_NAME}`, @@ -44,7 +44,7 @@ export class KnexInstrumentation extends InstrumentationBase { } init() { - const module = new InstrumentationNodeModuleDefinition( + const module = new InstrumentationNodeModuleDefinition( constants.MODULE_NAME, constants.SUPPORTED_VERSIONS ); diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts index efe4336c29..fde904f2bf 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts @@ -37,9 +37,7 @@ import { VERSION } from './version'; type formatType = typeof mysqlTypes.format; -export class MySQL2Instrumentation extends InstrumentationBase< - typeof mysqlTypes -> { +export class MySQL2Instrumentation extends InstrumentationBase { static readonly COMMON_ATTRIBUTES = { [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MYSQL, }; @@ -50,7 +48,7 @@ export class MySQL2Instrumentation extends InstrumentationBase< protected init() { return [ - new InstrumentationNodeModuleDefinition( + new InstrumentationNodeModuleDefinition( 'mysql2', ['>= 1.4.2 < 3.0'], (moduleExports: any, moduleVersion) => { diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts index 66570bb78e..3091569a40 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts @@ -16,7 +16,23 @@ import { SpanAttributes } from '@opentelemetry/api'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; -import type { Query, QueryOptions } from 'mysql2'; + +/* + Following types declare an expectation on mysql2 types and define a subset we + use in the instrumentation of the types actually defined in mysql2 pacakge + + We need to import them here so that the installing party of the instrumentation + doesn't have to absolutely install the mysql2 package as well - specially + important for auto-loaders and meta-pacakges. +*/ +interface QueryOptions { + sql: string; + values?: any | any[] | { [param: string]: any }; +} + +interface Query { + sql: string; +} interface Config { host?: string; diff --git a/plugins/node/opentelemetry-instrumentation-router/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-router/src/instrumentation.ts index 71f34ccede..125f2e28a8 100644 --- a/plugins/node/opentelemetry-instrumentation-router/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-router/src/instrumentation.ts @@ -33,9 +33,7 @@ import * as utils from './utils'; import AttributeNames from './enums/AttributeNames'; import LayerType from './enums/LayerType'; -export default class RouterInstrumentation extends InstrumentationBase< - typeof Router -> { +export default class RouterInstrumentation extends InstrumentationBase { constructor() { super(`@opentelemetry/instrumentation-${constants.MODULE_NAME}`, VERSION); } @@ -43,7 +41,7 @@ export default class RouterInstrumentation extends InstrumentationBase< private _moduleVersion?: string; init() { - const module = new InstrumentationNodeModuleDefinition( + const module = new InstrumentationNodeModuleDefinition( constants.MODULE_NAME, constants.SUPPORTED_VERSIONS, (moduleExports, moduleVersion) => { @@ -170,7 +168,7 @@ export default class RouterInstrumentation extends InstrumentationBase< const type = layer.method ? LayerType.REQUEST_HANDLER : LayerType.MIDDLEWARE; - const route = utils.getRoute(req); + const route = req.baseUrl + (req.route?.path ?? '') || '/'; const spanName = type === LayerType.REQUEST_HANDLER ? `request handler - ${route}` diff --git a/plugins/node/opentelemetry-instrumentation-router/src/utils.ts b/plugins/node/opentelemetry-instrumentation-router/src/utils.ts index 82159fb5bc..a9811942f2 100644 --- a/plugins/node/opentelemetry-instrumentation-router/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-router/src/utils.ts @@ -16,7 +16,6 @@ import * as constants from './constants'; import * as types from './types'; -import * as Router from 'router'; // Detect whether a function is a router package internal plumming handler export const isInternal = (fn: Function) => { @@ -30,9 +29,6 @@ export const isInternal = (fn: Function) => { return false; }; -export const getRoute = (req: Router.RoutedRequest) => - req.baseUrl + (req.route?.path ?? '') || '/'; - export const renameHttpSpan = ( span?: types.InstrumentationSpan, method?: string,