Skip to content

Commit

Permalink
docs: Document how to ignore Express routes (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods authored Aug 29, 2022
1 parent 6684b56 commit 11ab701
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions plugins/node/opentelemetry-instrumentation-express/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,32 @@ 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 or undefined when renaming the root HTTP instrumentation span.
- `defaultName: string` - original name proposed by the instrumentation.

#### Ignore a whole Express route

In order to ignore whole traces that represent a given Express route, use
the `ignoreIncomingRequestHook` option from
`@opentelemetry/instrumentation-http` against the route path. Ideally, this
shouldn't be necessary since spans should a have low cardinality and minimize
interaction between instrumentation libraies but
`@opentelemetry/instrumentation-express` renames the root span from
`@opentelemetry/instrumentation-http` in order to get things in order.

```js
registerInstrumentations({
instrumentations: [
// Express instrumentation expects HTTP layer to be instrumented
new HttpInstrumentation({
ignoreIncomingRequestHook(req) {
// Ignore spans from static assets.
const isStaticAsset = !!req.url.match(/^\/static\/.*$/);
return isStaticAsset;
}
}),
new ExpressInstrumentation(),
],
});
```

#### Using `requestHook`

Instrumentation configuration accepts a custom "hook" function which will be called for every instrumented Express layer involved in a request. Custom attributes can be set on the span or run any custom logic per layer.
Expand Down

0 comments on commit 11ab701

Please sign in to comment.