ObserveNow
...
Integrations
Applications

Javascript (Node.JS and Browser)

NodeJS Metrics Instrumentation

Instrumenting your app

Please follow the steps outlined in the following documents:

Setting the POD annotations

Once your application is emitting metrics, your POD in K8s will need to be annotated to enable the agent to scrape the metrics. Following are the relevant annotations:

YAML


Node.JS Tracing Instrumentation

OpenTelemetry is the recommended approach to instrument for tracing. Please follow the instructions in the following document to instrument your Node application:

When your tracing.js file (from above) is created, make sure to edit the traceExporter: to export using the Zipkin exporter to this location:

JS


The Zipkin URL above (http://otel collector.devopsnow.svc.cluster.local:9411) is available on all your clusters to which you installed the OpsVerse agent

This will allow the Node app to emit spans which will be collected by the OpenTelemetry collector installed as part of the OpsVerse agent and forwarded to the tracing backend.

Trace context (TraceId, SpanId and TraceFlags) injection into logs

It is very simple to configure traceId, spanId, and trace flags data injection into user logs in JavaScript applications. Based on the logging framework that is in use, follow the below mentioned steps to print the trace_id to the logs:

Winston

The following steps can be followed to to inject trace context with winston logger with OpenTelemetry instrumentation:

Step 1: Install the following dependency.

Shell


Step 2: Add the following block of code where OpenTelemetry JS instrumentation is configured (usually tracing.js file).

JS


The examples below apply to OpenTelemetry JS instrumentation version 0.23.0 or above.

More information available here.

Bunyan

The following steps can be followed to to inject trace context with bunyan logger with OpenTelemetry instrumentation:

Step 1: Install the following dependency.

Shell


Step 2: Add the following block of code where OpenTelemetry JS instrumentation is configured (usually tracing.js file).

JS


Pino

The following steps can be followed to to inject trace context with pino logger with OpenTelemetry instrumentation:

Step 1: Install the following dependency.

Shell


Step 2: Add the following block of code where OpenTelemetry JS instrumentation is configured (usually tracing.js file).

Text


Custom logger

In the case of custom loggers, the most important thing is to know how to obtain the traceId, spanId, and trace flag. Follow the steps below:

Step 1: Install the following dependency.

Shell


Step 2: Extract the trace context (traceId, spanId, and trace flag) using the following snippet:

JS


Example usage:

JS


Browser Tracing Instrumentation

OpenTelemetry is the recommended approach to instrument for tracing. Please follow the instructions in the following document to instrument your HTML/JS browser application:

To start emitting spans to your observability backend, your document-load.js file (from above) should look like the following to export in Zipkin format to a TBA trace proxy host:

Text


This will allow your browser app to emit events to a proxy collector (which validates events are coming from your whitelisted URLs) directly to your Jaeger collector (https://<jaeger-collector-host>/api/v2/spans). There are processors running on the collector that will generate the RUM metrics.