ldobserve

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

README

LaunchDarkly Observability SDK for Go

Actions Status

Early Access Preview️

NB: APIs are subject to change until a 1.x version is released.

Install

go get github.com/launchdarkly/observability-sdk/go

Install the plugin when configuring your LaunchDarkly SDK.

import (
	ld "github.com/launchdarkly/go-server-sdk/v7"
	"github.com/launchdarkly/go-server-sdk/v7/ldplugins"
	ldobserve "github.com/launchdarkly/observability-sdk/go"
)

func main() {
	client, _ := ld.MakeCustomClient(os.Getenv("LAUNCHDARKLY_SDK_KEY"),
		ld.Config{
			Plugins: []ldplugins.Plugin{
				ldobserve.NewObservabilityPlugin(
					ldobserve.WithEnvironment("test"),
					ldobserve.WithServiceName("go-plugin-example"),
					ldobserve.WithServiceVersion(version.Commit),
				),
			},
		}, 5*time.Second)

		// Implementation specific code.
}

Example applications are available here: https://github.com/launchdarkly/observability-sdk/tree/main/e2e/go-plugin

LaunchDarkly overview

LaunchDarkly is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. Get started using LaunchDarkly today!

Twitter Follow

Contributing

We encourage pull requests and other contributions from the community. Check out our contributing guidelines for instructions on how to contribute to this SDK.

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out our documentation for a complete list.
  • Explore LaunchDarkly

Documentation

Overview

package ldobserve provides LaunchDarkly observability functionality for Go applications.

This package is currently in early access preview. APIs are subject to change until a 1.x version is released.

Package ldobserve contains an AI SDK suitable for usage with generative AI applications.

Index

Constants

Version is the current version string of the observability package. This is updated by our release scripts.

Variables

This section is empty.

Functions

func EndSpan

func EndSpan(span trace.Span)

EndSpan is used to end a span. The span will include a stack trace when this function is used to end the span.

func RecordCount

func RecordCount(ctx context.Context, name string, value int64, tags ...attribute.KeyValue)

RecordCount is used to record arbitrary counts in your golang backend.

func RecordError

func RecordError(ctx context.Context, err error, tags ...attribute.KeyValue) context.Context

RecordError is used to record an error in the current span. If there is an active recording span, then the error is recorded in the span. If there is no active recording span, then a new span is created and the error is recorded in it. If this function starts a span, then that span will be ended after the error is recorded.

func RecordHistogram

func RecordHistogram(ctx context.Context, name string, value float64, tags ...attribute.KeyValue)

RecordHistogram is used to record arbitrary histograms in your golang backend.

func RecordLog

func RecordLog(ctx context.Context, record log.Record, tags ...log.KeyValue) error

RecordLog is used to record arbitrary logs in your golang backend.

func RecordMetric

func RecordMetric(ctx context.Context, name string, value float64, tags ...attribute.KeyValue)

RecordMetric is used to record arbitrary metrics in your golang backend.

func Shutdown

func Shutdown()

Shutdown stops the observability plugin. It is recommended to call this function when the application is shutting down.

func Start

func Start() error

Start starts the observability plugin, when the plugin is configured with WithManualStart.

func StartSpan

func StartSpan(
	ctx context.Context,
	name string,
	opts []trace.SpanStartOption,
	tags ...attribute.KeyValue,
) (context.Context, trace.Span)

StartSpan is used to start a new span. To start a span with a specific timestamp, use the trace.WithTimestamp option.

Types

type ObservabilityPlugin

type ObservabilityPlugin struct {
	ldplugins.Unimplemented
	// contains filtered or unexported fields
}

ObservabilityPlugin represents the LaunchDarkly observability plugin.

func NewObservabilityPlugin

func NewObservabilityPlugin(opts ...Option) *ObservabilityPlugin

NewObservabilityPlugin creates a new observability plugin with the given configuration.

func (ObservabilityPlugin) GetHooks

GetHooks returns the hooks for the observability plugin.

func (ObservabilityPlugin) Metadata

func (p ObservabilityPlugin) Metadata() ldplugins.Metadata

Metadata returns the metadata for the observability plugin.

func (ObservabilityPlugin) Register

Register registers the observability plugin with the LaunchDarkly client.

type Option

type Option func(*observabilityConfig)

Option is a function that configures the observability plugin.

func WithBackendURL

func WithBackendURL(backendURL string) Option

WithBackendURL sets the backend URL for the observability plugin.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the context for the observability plugin. Cancelling the provided context will stop the observability plugin. Calling the Shutdown function is recommended and provides a greater level of control.

func WithDebug

func WithDebug() Option

WithDebug enables debug mode for the observability plugin. This is for use debugging the plugin itself, but should not be needed in regular use.

func WithEnvironment

func WithEnvironment(environment string) Option

WithEnvironment sets the environment for the observability plugin.

func WithManualStart

func WithManualStart() Option

WithManualStart indicates that the observability plugin should not start automatically. Instead, the plugin should be started manually by calling the Start function.

func WithOTLPEndpoint

func WithOTLPEndpoint(otlpEndpoint string) Option

WithOTLPEndpoint sets the OTLP endpoint for the observability plugin.

func WithSamplingRateMap added in v0.2.1

func WithSamplingRateMap(rates map[trace.SpanKind]float64) Option

WithSamplingRateMap sets the sampling rate for each span kind. This setting can influence the quality of metrics used for experiments and guarded releases and should only be adjusted with consultation. If the sampling rate is specified for the SpanKindUnspecified kind, then that rate will be used for any span kind for which a rate is not specified.

func WithServiceName

func WithServiceName(serviceName string) Option

WithServiceName sets the service name for the observability plugin.

func WithServiceVersion

func WithServiceVersion(serviceVersion string) Option

WithServiceVersion sets the service version for the observability plugin.

Directories

Path Synopsis
internal
gql

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL