diff --git a/package-lock.json b/package-lock.json index 70e9e172c7..937656d458 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35297,14 +35297,14 @@ "dependencies": { "@opentelemetry/core": "^1.8.0", "@opentelemetry/instrumentation": "^0.45.1", - "@opentelemetry/semantic-conventions": "^1.0.0", - "@types/express": "4.17.18" + "@opentelemetry/semantic-conventions": "^1.0.0" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", + "@types/express": "4.17.18", "@types/mocha": "7.0.2", "@types/node": "18.6.5", "@types/sinon": "10.0.18", diff --git a/plugins/node/opentelemetry-instrumentation-express/README.md b/plugins/node/opentelemetry-instrumentation-express/README.md index 6eba2b6c67..70aa928230 100644 --- a/plugins/node/opentelemetry-instrumentation-express/README.md +++ b/plugins/node/opentelemetry-instrumentation-express/README.md @@ -79,6 +79,14 @@ Express instrumentation has few options available to choose from. You can set th - `info: ExpressRequestInfo` containing the incoming Express.js request, the current route handler creating a span and `ExpressLayerType` - the type of the handling layer. - `defaultName: string` - original name proposed by the instrumentation. +`requestHook` is invoked with 2 arguments: + +- `span: Span` - the span associated with the express request. +- `info: ExpressRequestInfo` containing the incoming Express.js request, the current route handler creating a span and `ExpressLayerType` - the type of the handling layer. + +NOTE: `ExpressRequestInfo.request` is typed as `any`. If you want type support make sure you have `@types/express` installed then you can use `ExpressRequestInfo` + + #### Ignore a whole Express route In order to ignore whole traces that represent a given Express route, use diff --git a/plugins/node/opentelemetry-instrumentation-express/package.json b/plugins/node/opentelemetry-instrumentation-express/package.json index 9106594094..fd1d0163c4 100644 --- a/plugins/node/opentelemetry-instrumentation-express/package.json +++ b/plugins/node/opentelemetry-instrumentation-express/package.json @@ -49,6 +49,7 @@ "@opentelemetry/context-async-hooks": "^1.8.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", + "@types/express": "4.17.18", "@types/mocha": "7.0.2", "@types/node": "18.6.5", "@types/sinon": "10.0.18", @@ -64,8 +65,7 @@ "dependencies": { "@opentelemetry/core": "^1.8.0", "@opentelemetry/instrumentation": "^0.45.1", - "@opentelemetry/semantic-conventions": "^1.0.0", - "@types/express": "4.17.18" + "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express#readme" } diff --git a/plugins/node/opentelemetry-instrumentation-express/src/types.ts b/plugins/node/opentelemetry-instrumentation-express/src/types.ts index a6d376face..8d1732833c 100644 --- a/plugins/node/opentelemetry-instrumentation-express/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-express/src/types.ts @@ -14,15 +14,15 @@ * limitations under the License. */ -import type { Request } from 'express'; import { Span } from '@opentelemetry/api'; import { InstrumentationConfig } from '@opentelemetry/instrumentation'; import { ExpressLayerType } from './enums/ExpressLayerType'; export type IgnoreMatcher = string | RegExp | ((name: string) => boolean); -export type ExpressRequestInfo = { - request: Request; +export type ExpressRequestInfo = { + /** An express request object */ + request: T; route: string; layerType: ExpressLayerType; }; @@ -36,6 +36,7 @@ export type SpanNameHook = ( defaultName: string ) => string; + /** * Function that can be used to add custom attributes to the current span or the root span on * a Express request @@ -47,7 +48,7 @@ export interface ExpressRequestCustomAttributeFunction { } /** - * Options available for the Express Instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-Instrumentation-express#express-Instrumentation-options)) + * Options available for the Express Instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express#express-instrumentation-options)) */ export interface ExpressInstrumentationConfig extends InstrumentationConfig { /** Ignore specific based on their name */