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

 

Next Step

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

Was this document helpful?

Would you like to help us improve our documents? Tell us what you think we could do better.


We're sorry to hear that you're not satisfied with the document. We'd love to learn what we could do to improve the experience.


Thanks for taking the time to share your feedback. We'll use your feedback to improve our online help resources.

Shortlink has been copied!