Recording metrics

Overview

The observability plugin provides different functions depending on what kind of data you want to record.

The recorded data is available as an $ld:telemetry:metric event. To learn more, read Metrics autogenerated from observability events.

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

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

Here are the options for recording metrics:

1const onClick = () => {
2 const start = Date.now();
3 doInterestingWork();
4 const elapsed = Date.now() - start;
5 LDObserve.recordGauge({name: "elapsedTimeMs", value: elapsed});
6};

To learn more, read Observe.

React Web

To record metrics with the React Web SDK, follow the example for JavaScript.

Vue

To record metrics with the Vue 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)

To record a metric, first create the metric within your application. The Metric interface includes a name, value, and optional tags. For example, you might create a metric for a point-in-time measurement, such as the current CPU utilization percentage, or for a counter, such as the number of cache hits.

Values with the same metric name and attributes are aggregated using the OpenTelemetry SDK. To learn more, read the OTel documentation on the Metrics Data Model.

Create OTel metric
1const metric = {
2 name: "exampleMetric",
3 value: 42
4}

Here are the options for recording metrics:

1 LDObserve.recordMetric(metric);

To learn more, read Observe.