NPM package which provides advanced automatic instrumentation for
Node.js http
and https
modules
on top of OpenTelemetry @opentelemetry/instrumentation-http
instrumentation module.
To install the package, you can use NPM (or Yarn):
npm install --save otel-instrumentation-http-plus
Note: Requires @opentelemetry/api
version 1.0.0
+ and @opentelemetry/instrumentation-http
version 0.30.0
+ installed.
You need to import/require HttpPlusInstrumentation
first
and then register HttpPlusInstrumentation
instance through registerInstrumentations
method
provided by the instrumentation API ('@opentelemetry/instrumentation'
) as shown below:
const { HttpPlusInstrumentation } = require('otel-instrumentation-http-plus');
const {
ConsoleSpanExporter,
NodeTracerProvider,
SimpleSpanProcessor,
} = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();
registerInstrumentations({
instrumentations: [new HttpPlusInstrumentation({
// Put options here. See "Configuration" section below for more details
})],
});
In addition to base OpenTelemetry HTTP instrumentation options here, OpenTelemetry HTTP Instrumentation Plus also provides the following options to configure:
Options | Type | Default Value | Description |
---|---|---|---|
captureRequestBody |
boolean |
false |
Enables capturing HTTP request body |
maxRequestBodySize |
number |
4096 (4 KB ) |
Sets maximum size limit for HTTP request body to be captured |
captureResponseBody |
boolean |
false |
Enables capturing HTTP response body |
maxResponseBodySize |
number |
4096 (4 KB ) |
Sets maximum size limit for HTTP response body to be captured |
maxResponseBodySize |
number |
4096 (4 KB ) |
Sets maximum size limit for HTTP response body to be captured |
traceNetworkOperations |
boolean |
false |
Enables tracing network timings by creating spans for the following traced network operations - DNS Lookup - TCP Connect - TLS Handshake - TTFB (Time To First Byte) - Content Transfer |
traceNetworkOperations |
boolean |
false |
Enables tracing network timings by creating spans for the following traced network operations - DNS Lookup - TCP Connect - TLS Handshake - TTFB (Time To First Byte) - Content Transfer |
requestBodyMaskHook |
HttpRequestBodyMaskFunction |
- | Function for masking traced HTTP request body (for ex. deleting or hiding sensitive fields) |
responseBodyMaskHook |
HttpResponseBodyMaskFunction |
- | Function for masking traced HTTP response body (for ex. deleting or hiding sensitive fields) |
You can find examples under examples
directory.
To be able to run the example, you can run the following command:
npm run example
- Support masking for captured HTTP request and/or response bodies by configured ignored keys (without custom function implementation)
Please use GitHub Issues for any bug report, feature request and support.
If you would like to contribute, please
- Fork the repository on GitHub and clone your fork.
- Create a branch for your changes and make your changes on it.
- Send a pull request by explaining clearly what is your contribution.
Tip: Please check the existing pull requests for similar contributions and consider submit an issue to discuss the proposed feature before writing code.
Licensed under MIT License.