Skip to content

Latest commit

 

History

History
81 lines (55 loc) · 2.65 KB

File metadata and controls

81 lines (55 loc) · 2.65 KB

Sample-tracing-nodejs-javascript

This is Sample NodeJS App for sending traces to OpenObserve.

Prerequisites

Getting Started

  1. Clone the Repository::
git clone https://github.com/openobserve/sample-tracing-nodejs-javascript
  1. Make Changes to tracing.js file:

The OTLPTraceExporter sends the captured traces to OpenObserve. Replace url and YOUR_AUTH_TOKEN with your actual HTTP endpoint and authentication token, which you can find in your Data Sources -> Custom -> Traces -> OpenTelemetry -> OTLP HTTP.

Add /v1/traces to your OTLP HTTP endpoint.

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 exporterOptions = {
  url: "url/v1/traces",
  headers: {
    Authorization: "Basic YOUR_AUTH_TOKEN" ,
  },
}

const traceExporter = new OTLPTraceExporter(exporterOptions);
const sdk = new opentelemetry.NodeSDK({
 traceExporter: new opentelemetry.tracing.ConsoleSpanExporter(),
  traceExporter,
  instrumentations: [getNodeAutoInstrumentations()],
  serviceName: "nodejs-javascript-service",
});

sdk.start();
  1. Verify Node installation:

Ensure that Node.js is installed correctly by checking the version

node - v
  1. Install the dependency packages:
npm install
  1. Start the Service and Begin Sending Data to OpenObserve:

Run the application using the following command:

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

App will start on http://localhost:8080 by default.

  1. Validate instrumentation by checking for traces

Applications will not produce traces unless they are being interacted with, and OpenTelemetry will often buffer data before sending. So you need to interact with your application and wait for some time to see your tracing data in OpenObserve.

Refresh page couple of times to get more traces exported.

Traces are captured, you can check these captured traces in the Traces tab.

image