launchdarkly

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package launchdarkly evaluates feature flags against LaunchDarkly, by way of OpenFeature.

Choosing it commits a deployment to a LaunchDarkly SDK key and to an *http.Client, which is required rather than optional: the SDK is configured with it, so a nil one is a construction error rather than a default transport.

Construction is a network call

MakeCustomClient blocks until LaunchDarkly has delivered the initial flag payload or InitTimeout — five seconds when unset — elapses. A service that cannot reach LaunchDarkly at startup therefore fails to build its flag manager rather than coming up and answering every flag with its default, which is indistinguishable from the flags being off. The corollary is that this constructor is one of the few in the module that can be slow, and the timeout is the knob for how slow.

WithConfigModifiers reaches ld.Config before the client is built, which is where a caller substitutes the data source — a file-backed or offline one, for instance — for a test or an air-gapped environment.

Evaluation

The five evaluation methods and their circuit-breaker protocol come from featureflags/internal/openfeatureflags, embedded, and are the same code the posthog sibling runs. LaunchDarkly does distinguish a flag it has never heard of from one that is off, so the four typed getters report featureflags.ErrFlagNotFound for a missing key and that outcome scores the breaker a success rather than a failure. CanUseFeature never reports it, for the reason its documentation there gives.

Close is mandatory

Each construction registers a uniquely-named provider in OpenFeature's process-global registry, and that registry has no removal API. Close detaches the registration by replacing it with the no-op provider and then closes the LaunchDarkly client. Skipping it leaks the client — and a service that rebuilds its flag manager on config reload leaks one per cycle, each still holding a LaunchDarkly connection, until the process exits.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingHTTPClient = platformerrors.New("missing HTTP client")
	ErrNilConfig         = platformerrors.New("missing launchdarkly config")
	ErrMissingSDKKey     = platformerrors.New("missing SDK key")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	SDKKey      string        `env:"SDK_KEY"      json:"sdkKey,omitempty"      yaml:"sdkKey,omitempty"`
	InitTimeout time.Duration `env:"INIT_TIMEOUT" json:"initTimeout,omitempty" yaml:"initTimeout,omitempty"`
}

func (*Config) ValidateWithContext

func (cfg *Config) ValidateWithContext(ctx context.Context) error

ValidateWithContext validates the Config.

SDKKey is required: the client cannot reach LaunchDarkly without one, and an empty key would otherwise reach the SDK and report every flag as its default, which is indistinguishable from the flags genuinely being off.

type FeatureFlagManager

type FeatureFlagManager struct {

	// Evaluator is the flag evaluation every OpenFeature-backed provider
	// here does; see featureflags/internal/openfeatureflags. Embedded, so
	// this type still presents the whole featureflags.FeatureFlagManager
	// surface.
	openfeatureflags.Evaluator
	// contains filtered or unexported fields
}

FeatureFlagManager is the LaunchDarkly featureflags.FeatureFlagManager implementation, by way of OpenFeature. It is exported, and returned by NewFeatureFlagManager, so a caller who has chosen LaunchDarkly can depend on that choice rather than on the interface every flag backend shares.

func NewFeatureFlagManager

func NewFeatureFlagManager(cfg *Config, httpClient *http.Client, circuitBreaker circuitbreaking.CircuitBreaker, opts ...Option) (*FeatureFlagManager, error)

NewFeatureFlagManager constructs a LaunchDarkly FeatureFlagManager backed by OpenFeature.

func (*FeatureFlagManager) Close

func (f *FeatureFlagManager) Close() error

Close closes the LaunchDarkly client and detaches it from OpenFeature's process-global provider registry.

Each construction registers a uniquely-named provider in that registry, which has no removal API — so without the swap below, every reload cycle left another registration holding a reference to a client that had just been closed, and the process accumulated them until it exited. Replacing the registration with the no-op provider releases the client; the (small, clientless) map entry itself is not removable and is left behind.

type Option

type Option func(*options)

Option configures the FeatureFlagManager this package constructs. The zero configuration works: an absent logger logs nowhere, an absent tracer provider traces nowhere, and an absent metrics provider records nothing.

func WithConfigModifiers

func WithConfigModifiers(configModifiers ...func(ld.Config) ld.Config) Option

WithConfigModifiers appends functions that transform the LaunchDarkly client config before the client is built. Modifiers accumulate across repeated uses of this option and run in the order provided.

func WithLogger

func WithLogger(logger logging.Logger) Option

WithLogger attaches a logger.

func WithMetricsProvider

func WithMetricsProvider(metricsProvider metrics.Provider) Option

WithMetricsProvider attaches a metrics provider.

func WithTracerProvider

func WithTracerProvider(tracerProvider tracing.Provider) Option

WithTracerProvider attaches a tracer provider, enabling spans on every evaluation.

Jump to

Keyboard shortcuts

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