OpenObserve Docs
IngestionTraces

Node.js Distributed Tracing - OpenTelemetry APM

Updated View MarkdownOpen in ChatGPTOpen in Claude

Setup distributed tracing for your Node.js application using OpenTelemetry for Node.js application performance monitoring (APM) and trace ingestion. Check sample configuration on how to setup OpenTelemetry traces for Node.js applications.

Clone


git clone https://github.com/openobserve/sample-tracing-nodejs-javascript

If you don't have node.js installed, please install it and then follow below steps.

Open tracing.js file from that repository. and make changes to the highlighted lines below


const opentelemetry = require("@opentelemetry/sdk-node");
const {
  getNodeAutoInstrumentations,
} = require("@opentelemetry/auto-instrumentations-node");
const { diag, DiagConsoleLogger, DiagLogLevel } = require("@opentelemetry/api");
const {
  OTLPTraceExporter,
} = require("@opentelemetry/exporter-trace-otlp-http");

// For troubleshooting, set the log level to DiagLogLevel.DEBUG
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);

const sdk = new opentelemetry.NodeSDK({
  // traceExporter: new opentelemetry.tracing.ConsoleSpanExporter(),
  traceExporter: new OTLPTraceExporter({
    url: "https://api.openobserve.ai/api/default/v1/traces",
    headers: {
      Authorization: "Authorization",
    },
  }),
  instrumentations: [getNodeAutoInstrumentations()],
  serviceName: "nodejs-javascript-service",
});

sdk.start();

## Set up credentials

You will get url and Authorization key from the OpenTelemetry ingestion settings.

Replace the url and Authorization key in the tracing.js file.

Set up the service/application

Run commands


npm install

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

The server is now running on 8080, navigate to http://localhost


Refresh page couple of times to get more traces exported.

Traces Sample Configration

Traces are captured, you can check these captured traces in the Traces view

Traces page with spans from the sample services

Filter traces with your service name nodejs-javascript-service

Spans filtered by service_name nodejs-javascript-service

Click on any trace to check trace data

Trace details in the Waterfall view

Trace can have multiple spans, each span represents single operation or task within that trace. Click on any span to check span details.

Span details panel with the span attributes

Was this page helpful?

On this page