This is Sample NodeJS App for sending traces to OpenObserve.
- Node.js version 12 or newer. Download the latest version of Node.js here.
- OpenObserve: You can get started with OpenObserve Cloud or a self hosted installation.
- Clone the Repository::
git clone https://github.com/openobserve/sample-tracing-nodejs-javascript
- 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 yourOTLP 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();
- Verify Node installation:
Ensure that Node.js is installed correctly by checking the version
node - v
- Install the dependency packages:
npm install
- 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.
- 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.