Node.js (server-side) SDK observability reference

The LaunchDarkly observability features are available for early access

Observability features in the LaunchDarkly UI are publicly available in early access.

The SDK observability plugins are designed for use with the in-app observability features. They are currently in available in Early Access and APIs are subject to change until a 1.x version is released.

If you are interested participating in the Early Access Program for upcoming observability plugins for additional SDKs, sign up here.

Overview

This topic documents how to get started with the LaunchDarkly observability plugin for the Node.js (server-side) SDK.

The Node.js (server-side) SDK supports the observability plugin for error monitoring, logging, and tracing.

SDK quick links

LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:

ResourceLocation
SDK API documentationObservability plugin API docs
GitHub repository@launchdarkly/observability-node
Published modulenpm
For use in server-side applications only

The observability-node plugin is intended for use in multi-user Node.js server applications. If you want to set up LaunchDarkly in JavaScript in a browser environment, read the JavaScript SDK reference and JavaScript SDK observability reference.

To learn more about LaunchDarkly’s different SDK types, read Client-side, server-side, and edge SDKs.

Prerequisites and dependencies

This reference guide assumes that you are somewhat familiar with the LaunchDarkly Node.js (server-side) SDK.

The observability plugin is compatible with the Node.js (server-side) SDK, version 9.10.0 and later.

Get started

Follow these steps to get started:

Install the plugin

LaunchDarkly uses a plugin to the Node.js (server-side) SDK to provide observability.

The first step is to make both the SDK and the observability plugins available as dependencies.

Here’s how:

$npm install @launchdarkly/node-server-sdk
>npm install @launchdarkly/observability-node

Then, import the plugin into your code:

Import, Node.js SDK v9.10+
1import { init } from '@launchdarkly/node-server-sdk'
2import Observability, {LDObserve } from '@launchdarkly/observability-node'

Initialize the client

Next, initialize the SDK and the plugin.

To initialize, you need your LaunchDarkly environment’s SDK key. This authorizes your application to connect to a particular environment within LaunchDarkly. To learn more, read Initialize the client in the Node.js (server-side) SDK reference guide.

Here’s how to initialize the SDK and plugin:

Initialize, Node.js SDK v9.10+
1const client = init(
2 'sdk-key-123abc',
3 {
4 plugins: [
5 new Observability(),
6 ],
7 },
8)

Configure the plugin options

You can configure options for the observability plugin when you initialize the SDK. The plugin constructor takes an optional object with the configuration details.

Here is an example:

Plugin options, Node.js SDK v9.10+
1const client = init(
2 'sdk-key-123abc',
3 {
4 plugins: [
5 new Observability({
6 serviceName: 'example-service',
7 // we recommend setting serviceVersion to the latest deployed git SHA
8 serviceVersion: 'example-sha',
9 environment: 'production'
10 }
11 }),
12 ],
13 },
14)

For more information on plugin options, as well as how they interact with environment variables and existing OpenTelemetry configuration, read Configuration for server-side observability.

Explore supported features

The observability plugins supports the following features. After the SDK and plugins are initialized, you can access these from within your application:

Review observability data in LaunchDarkly

After you initialize the SDK and observability plugin, your application automatically starts sending observability data back to LaunchDarkly in the form of custom events. You can review this information in the LaunchDarkly user interface. To learn how, read Observability.

Specifically, the observability data includes events that LaunchDarkly uses to automatically create the following metrics:

  • User HTTP error rate (OpenTelemetry)
  • User HTTP 5XX response rate (OpenTelemetry)
  • User non-HTTP exception rate (OpenTelemetry)
  • Average, P95, and P99 request latency (OpenTelemetry)

To learn more, read Metrics autogenerated from server-side SDKs using OpenTelemetry.