Node.js

StackState Kubernetes Troubleshooting

Automatic instrumentation

Automatic instrumentation for Node.js is done by including the automatic instrumentation Javascript libraries with your application. A wide range of libraries and frameworks is supported.

Automatic instrumentation does not require any modifications of the application. To set it up follow these steps:

  1. Add the Open Telemetry instrumentation SDK to your application:

npm install --save @opentelemetry/api
npm install --save @opentelemetry/auto-instrumentations-node
  1. Update the command that starts your application to load the SDK, either by updating the docker image entry point or command or by updating the command in the Kubernetes manifest for your application. Add --require @opentelemetry/auto-instrumentations-node/register:

node --require @opentelemetry/auto-instrumentations-node/register app.js
  1. Deploy your application with the extra environment variables to configure the service name and exporter endpoint.

  2. Verify StackState is receiving traces and/or metrics

For more details please refer to the Open Telemetry documentation.

The auto instrumentation configured via environment variables only supports traces until this Open Telemetry issue is resolved. To enable metrics from the automatic instrumentation code changes are needed. Please follow the instructions in the Open Telemetry documentation to make these changes.

Manual instrumentation

Manual instrumentation can be used when you need metrics, traces or logs from parts of the code that are not supported by the auto instrumentation. For example unsupported libraries, in-house code or business-level metrics.

To capture that data you need to modify your application.

  1. Include the Open Telemetry SDK as a dependency

  2. Add code to your application to capture metrics, spans or logs where needed

There is detailed documentation for this on the Open Telemetry Javascript SDK doc pages.

Make sure you use the OTLP exporter and configure the exporter endpoint correctly from the code. See also the Open Telemetry documentation. Assuming you set up the exporter as documented the endpoint that needs to be configured is http://opentelemetry-collector.open-telemetry.svc.cluster.local:4317, using gRPC. See also gRPC vs HTTP in case gRPC is problematic.

Last updated