Help Docs

Instrument Node.js application for OpenTelemetry

To monitor your Node.js application with Site24x7 OpenTelemetry, follow the steps below.

Step 1:
Install the auto-instrumentation package from OpenTelemetry.

npm install @opentelemetry/auto-instrumentations-node

Step 2: Setup
Create a file with the tracing setup code shown below.

/* tracing.js */
// Require dependencies
const opentelemetry = require("@opentelemetry/sdk-node");
const { getNodeAutoInstrumentations } = require("@opentelemetry/auto-instrumentations-node");
const { diag, DiagConsoleLogger, DiagLogLevel } = require('@opentelemetry/api');// For troubleshooting, set the log level to DiagLogLevel.DEBUG
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
const collectorOptions = {
url: 'https://otel.site24x7rum.com:4318/v1/traces',
headers: {
'api-key': <license.key>
}, 
concurrencyLimit: 10, // an optional limit on pending requests
serviceName: "<service_name>"
};const sdk = new opentelemetry.NodeSDK({
traceExporter: new OTLPTraceExporter(collectorOptions),
instrumentations: [getNodeAutoInstrumentations()]
});
sdk.start()
Note

The setup and configuration should happen before the application code.

Step 3: Run the application
To use the tracing configuration, run your application with the —require flag.

For example:

node --require './tracing.js' app.js

You are all set. Now the agent will start sending the performance metrics to your Site24x7 web client portal.

Was this document helpful?

Shortlink has been copied!