Skip to content

Every thing you need to copypasta to get started with OpenTelemetry for NodeJS.

Notifications You must be signed in to change notification settings

tedsuo/otel-node-basics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenTelemetry Node Basics

Hello there! You've found one of my OpenTelemetry playgrounds. This example contains everything you need to know to use the OpenTelemetry Javascript Tracing API when running in Node:

  • Initialization: How to start and shutdown cleanly.
  • Tracer methods: getTracer, getCurrentSpan, startSpan, and withSpan.
  • Span methods: setAttribute, addEvent, recordException, setStatus, and end.

This example uses OpenTelemetry JS v0.12 and Lightstep as the backend. It contains heavily commented examples of every pattern needed to trace your code with OpenTelemetry.

Relevant handy links:

Installation

npm i express
npm i lightstep-opentelemetry-launcher-node

Since we’re connecting to Lightstep, we’re using the Lightstep Distro of OpenTelemetry, the OpenTelemetry Launchers. If you're interested in details about Distros, you can read about their origins here.

I also recommend turning on the debug logs, to get a sense of what OpenTelemetry is doing.

export OTEL_LOG_LEVEL=debug

Configuration

The only required configuration to set your access token. You can find it under "settings" in your lightstep account. Hit the copy button, then open server_init.js and client_init.js and paste that giant thing where it says

Running

Run the traced entry points in two terminals:

node server_init.js
node client_init.js

About

Every thing you need to copypasta to get started with OpenTelemetry for NodeJS.

Resources

Stars

Watchers

Forks