Recording traces

Overview

This topic explains how to record traces through the SDK observability plugin.

You can view all traces sent to LaunchDarkly under Traces in the LaunchDarkly user interface. To learn more, read Traces.

Details about each SDK’s configuration are available in the SDK-specific sections below:

Client-side SDKs

This feature is available in the observability plugin for the following client-side SDKs:

JavaScript

The observability plugin provides two options for starting new spans:

  • startSpan() ends the span automatically after the callback function completes, whether it returns normally or throws an error
  • startManualSpan() ends the span when you call span.end()

To start a new span:

1// This span ends automatically after the callback completes
2LDObserve.startSpan('fetchData', (span) => {
3 // Your code here
4});

To learn more, read startSpan and startManualSpan.

React Web

To start new spans with the React Web SDK, follow the example for JavaScript.

Vue

To start new spans with the React Web SDK, follow the example for JavaScript.

Server-side SDKs

This feature is available in the observability plugin for the following server-side SDKs:

Node.js (server-side)

The Node.js (server-side) SDK’s observability plugin uses the OpenTelemetry Tracing API to work with spans.

Additionally, it provides the following functions for working with spans:

  • setAttributes() sets attributes on the active span
  • startWithHeaders() starts a span with information from the request headers
  • runWithHeaders() runs a callback with information from the request headers and returns the result

Here’s an example:

Example: Starting and running a span
1app.get("/start-span-example", (req: Request, res: Response) => {
2 const {span} = LDObserve.startWithHeaders('example-span-a', req.headers);
3
4 LDObserve.setAttributes({
5 "example-attribute": "example-value",
6 });
7
8 res.send("Hello World");
9 span.end();
10});
11
12app.get("/run-span-example", async (req: Request, res: Response) => {
13 await LDObserve.runWithHeaders('example-span-b', req.headers, (span) => {
14 LDObserve.setAttributes({
15 "example-attribute": "example-value",
16 });
17
18 res.send("Hello World");
19 });
20});

To learn more, read Observe.