> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js (server-side) SDK observability reference

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

> For the complete documentation index, see [llms.txt](/llms.txt). For the full documentation snapshot, see [llms-full.txt](/llms-full.txt).

## 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.

<Note title="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:
</Note>

| Resource | Location |
| - | - |
| SDK API documentation | [Observability plugin API docs](https://launchdarkly.github.io/observability-sdk/sdk/@launchdarkly/observability-node/) |
| GitHub repository | [@launchdarkly/observability-node](https://github.com/launchdarkly/observability-sdk/tree/main/sdk/%40launchdarkly/observability-node) |
| Sample application | [Example Express app](https://github.com/launchdarkly/observability-sdk/blob/main/e2e/node-plugin-express/README.md) |
| Published module | [npm](https://www.npmjs.com/package/@launchdarkly/observability-node) |

<Warning title="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](/sdk/client-side/javascript) and [JavaScript SDK observability reference](/sdk/observability/javascript).

  To learn more about LaunchDarkly's different SDK types, read [Choosing an SDK type](/sdk/concepts/client-side-server-side).
</Warning>

## Prerequisites and dependencies

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

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

## Get started

Follow these steps to get started:

* [Install the plugin](#install-the-plugin)
* [Initialize the Node.js (server-side) SDK client](#initialize-the-client)
* [Configure the plugin options](#configure-the-plugin-options)
* [Explore supported features](#explore-supported-features)
* [Review observability data in LaunchDarkly](#review-observability-data-in-launchdarkly)

## 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:

<CodeGroup>
  ```bash title="npm, Node.js SDK v9.10+" theme={null}
      npm install @launchdarkly/node-server-sdk
      npm install @launchdarkly/observability-node
  ```

  ```bash title="yarn, Node.js SDK v9.10+" theme={null}
      yarn add @launchdarkly/node-server-sdk
      yarn add @launchdarkly/observability-node
  ```
</CodeGroup>

Then, import the plugin into your code:

<CodeGroup>
  ```js title="Import, Node.js SDK v9.10+" theme={null}
      import { init } from '@launchdarkly/node-server-sdk'
      import { Observability } from "@launchdarkly/observability-node";
  ```
</CodeGroup>

## 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](/sdk/server-side/node-js#initialize-the-client) in the Node.js (server-side) SDK reference guide.

Here's how to initialize the SDK and plugin:

<CodeGroup>
  ```js title="Initialize, Node.js SDK v9.10+" theme={null}
      const client = init(
        'YOUR_SDK_KEY',
        {
          plugins: [
            new Observability(),
          ],
        },
      )
  ```
</CodeGroup>

<Note title="Express.js users should import the observability SDK before importing Express">
  As a best practice, we recommend initializing the SDK as early as possible. Observability auto-instrumentation does not capture anything that initialized before the LaunchDarkly SDK.

  This is especially relevant for Express.js users, who may miss routes or middleware data if Express is imported before the SDK. To address this issue, configure a separate `launchdarkly.ts` file to initialize the SDK with an `import` before importing Express.
</Note>

## 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:

<CodeGroup>
  ```js title="Plugin options, Node.js SDK v9.10+" theme={null}
      const client = init(
        'YOUR_SDK_KEY',
        {
          plugins: [
            new Observability({
              serviceName: 'example-service',
              // we recommend setting serviceVersion to the latest deployed git SHA
              serviceVersion: 'example-sha'
            }),
          ],
        },
      )
  ```
</CodeGroup>

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](/sdk/features/observability-config-server-side).

## Explore supported features

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

* [Configuration for server-side observability](/sdk/features/observability-config-server-side#nodejs-server-side)
* [Errors](/sdk/features/observability-errors#nodejs-server-side)
* [Logs](/sdk/features/observability-logs#nodejs-server-side)
* [Metrics](/sdk/features/observability-metrics#nodejs-server-side)
* [Tracing](/sdk/features/observability-traces#nodejs-server-side)

## 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](/home/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 OpenTelemetry data](/home/metrics/autogen/opentelemetry).
