Go 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 observability SDKs, implemented as plugins for LaunchDarkly server-side and client-side SDKs, 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 in participating in the Early Access Program for upcoming observability SDKs, sign up here.

Overview

This topic documents how to get started with the LaunchDarkly observability plugin for the Go SDK.

The Go 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/go
Sample applicationExample applications for several frameworks
Published modulepkg.go.dev

Prerequisites and dependencies

This reference guide assumes that you are somewhat familiar with the LaunchDarkly Go SDK.

The observability plugin is compatible with the Go SDK, version 7.11 and later. Using the observability plugin requires Go 1.24.3 or higher.

Get started

Follow these steps to get started:

Install the plugin

LaunchDarkly uses a plugin to the Go SDK to provide observability.

The first step is to make both the SDK and the observability plugin available as dependencies. How you do this depends on what dependency management system you are using:

  • If you are using the standard Go modules system, import the SDK packages in your code and go build will automatically download them. The SDK and its dependencies are modules.
  • Otherwise, use the go get command and specify the SDK version, such as go get github.com/launchdarkly/go-server-sdk/v7 and go get github.com/launchdarkly/observability-sdk/go.

There are several packages that you can import, depending on which features you are using. To work with observability, you need the following:

Go SDK v7.11+
1import (
2 // go-sdk-common/v3/ldcontext defines LaunchDarkly's model for contexts
3 "github.com/launchdarkly/go-sdk-common/v3/ldcontext"
4
5 // go-server-sdk/v7 is the main SDK package - here we are aliasing it to "ld"
6 ld "github.com/launchdarkly/go-server-sdk/v7"
7
8 // go-server-sdk/v7/ldplugins allows you to add plugins to the main SDK
9 "github.com/launchdarkly/go-server-sdk/v7/ldplugins"
10
11 // observability-sdk/go is the observability plugin - here we are aliasing it to "ldobserve"
12 // this package requires go-server-sdk/v7 version 7.11 or later
13 ldobserve "github.com/launchdarkly/observability-sdk/go"
14)

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 Go SDK reference guide.

Here’s how to initialize the SDK and plugin:

Initialize, Go SDK v7.11+
1client, _ := ld.MakeCustomClient("sdk-key-123abc",
2 ld.Config{
3 Plugins: []ldplugins.Plugin{
4 ldobserve.NewObservabilityPlugin()
5 },
6 }, 5*time.Second)

Configure the plugin options

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

Here is an example:

Plugin options, Go SDK v7.11+
1client, _ := ld.MakeCustomClient("sdk-key-123abc",
2 ld.Config{
3 Plugins: []ldplugins.Plugin{
4 ldobserve.NewObservabilityPlugin(
5 ldobserve.WithServiceName("example-service"),
6 ldobserve.WithServiceVersion("example-sha"),
7 ldobserve.WithEnvironment("production")
8 ),
9 },
10 }, 5*time.Second)

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.

Examples using different frameworks

LaunchDarkly provides several examples, each demonstrating the LaunchDarkly Observability plugin with different Go frameworks and libraries:

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 and Metrics autogenerated from OpenTelemetry data.