OpenTelemetry JS SDK

How to have Node.js, Typescript, Javascript applications using the OpenTelemetry JS SDK report data to Lumigo

Have you considered using the Lumigo OpenTelemetry Distro for Node.js?

The Lumigo OpenTelemetry Distro for Node.js packages the upstream OpenTelemetry JS SDK, a number of functionalities from the opentelemetry-js-contrib repository, together with a lot of additional automation, no-code capabilities and automated quality-assurance.

Overview

The steps to make a Node.js or Typescript application report tracing data to Lumigo are a mix of programmatic setup and environment-based configuration.

This documentation does not cover how to add instrumentation to your Node.js or Typescript code, but pointers are provided in the "What's Next" section at the end of the page.

Initialize the OpenTelemetry JS SDK

Assuming the following exporter setup in your Node.js application using the upstream OpenTelemetry JS SDK:

// tracing.js

'use strict'

import { Resource } from '@opentelemetry/resources';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-otlp-http';

// Important: Consider to set up the right OpenTelemetry Resource Detectors for
// the computing platform your application runs on!
const provider = new NodeTracerProvider(resource=Resource.create());
const exporter = new OTLPTraceExporter(collectorOptions);
provider.addSpanProcessor(new BatchSpanProcessor(exporter));

provider.register();

// Once you set the environment variables OTEL_EXPORTER_OTLP_ENDPOINT and
// OTEL_EXPORTER_OTLP_HEADERS, you are good to go! Enjoy Lumigo!

📘

Do not hard-code the Lumigo token in your application

Although the OTLPTraceExporter would allow you to pass the Authorization header as a literal, we strongly advise not to hard-code the Lumigo token in the code of your application. Consider using the OTEL_EXPORTER_OTLP_HEADERS environment variable, or at least passing the Lumigo token as its own environment variable, and interpolate the header string you pass to OTLPTraceExporter.

Configure the OpenTelemetry JS SDK

The @opentelemetry/exporter-otlp-http package of the OpenTelemetry JS SDK can be connected to Lumigo using the following environment variables:

Environment variableValue
OTEL_EXPORTER_OTLP_ENDPOINThttps://ga-otlp.lumigo-tracer-edge.golumigo.com
OTEL_EXPORTER_OTLP_HEADERSAuthorization=LumigoToken <token>

Replace <token> with your Lumigo token, which is available in Settings -> Tracing -> Manual tracing, see the Lumigo Tokens documentation.

📘

Resource Attributes are very important!

When you instantiate the TracerProvider, you can pass it a Resource, which contains attributes that describe the your Python application and the platform on which it runs. See the Supported Semantic Conventions page for a list of endorsed Resource Detectors that will provide data useful for your experience of using Lumigo.