enhanced open telemetry instrumentation for the `express` web framework
npm install opentelemetry-instrumentation-expressThis module provide enhanced instrumentation for the express web framework.
```
npm install --save opentelemetry-instrumentation-express^4.9.0Supported Versions
This instrumentation supports :
all versions >= 4.9.0 (released 2014) and < 5.0.0 (in alpha).
`js
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { ExpressInstrumentation } = require('opentelemetry-instrumentation-express');
const tracerProvider = new NodeTracerProvider();
tracerProvider.register();
registerInstrumentations({
tracerProvider,
instrumentations: [
new ExpressInstrumentation()
]
});
`
Express instrumentation has few options available to choose from. You can set the following:
| Options | Type | Description |
| --- | --- | --- |
| requestHook | RequestHook (function) | Hook for adding custom attributes before express start handling the request. Receives params: span, { moduleVersion, req, res } |includeHttpAttributes
| | boolean | If set to true, plugin will include semantic http attributes in each express span |
Example: /api/users/:id
Example: /api/users/:id/books/758734 (The :id part was consumed, but the bookid part was not).
, and supply more info about how the app routing works.Example:
/api["/foo", /"bar"] - meaning that the same endpoint is triggered by routes /api/foo and /api/bar.$3
This attribute holds a json stringified map, where the keys are the url path param names, and the values are the matched params from the actual url.Example:
{"id":"1234"}. $3
Set to true when request was not handled by any middleware in express, and got fallback to the default app finalhandler. This can happen if client sent request with invalid path or method (resulting in 404). This can be useful to filter out requests from internet bots which try to call common routes on servers.$3
In case of internal error in instrumentation, this attribute will contain the error description. There are no known valid use cases which are expected to produce this attribute.Difference from @opentelemetry/instrumentation-express
* This instrumentation is focusing on extracting the most accurate and complete
route data, in any valid express edge case. Contrib instrumentation does a good job for common cases, but miss nuances on complex setups.
* This instrumentation create a single span per request. Contrib instrumentation creates span per express Router/Route, which can be useful to observe express internal components, with the cost of more spans in each trace.
* Set few alternatives for route attribute, each with different level of cardinality vs accuracy.
* Allows to set requestHook` for adding custom attributes to span, as well as ability to capture express version into user defined attribute.
---
This extension (and many others) was developed by Aspecto with ❤️