Instrument your Node.js application on a host

Follow the instructions on this page to instrument your Node.js application running on a host, such as a macOS, Windows, or Linux device. Make sure you have already installed the Observe Agent.

  1. Add the OpenTelemetry zero-code instrumentation for Node.js.

    Run the following commands to add zero-code instrumentation for your Node.js application, meaning you don’t have to modify your application’s source code to collect telemetry:

npm install @opentelemetry/sdk-node \
@opentelemetry/api \
@opentelemetry/auto-instrumentations-node \
@opentelemetry/sdk-metrics \
@opentelemetry/sdk-trace-node
  1. Set the following environment variables to configure the Node.js instrumentation. Replace the placeholders such as ${YOUR_SERVICE_NAME} with the actual information from your environment.

export OTEL_SERVICE_NAME=${YOUR_SERVICE_NAME}
export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=${YOUR_APP_ENVIRONMENT}
export OTEL_EXPORTER_OTLP_ENDPOINT=http://${YOUR_OBSERVE_AGENT_ENDPOINT}:4318
  1. Run your instrumented app:

node app.js