openfeature

package
v2.12.0-dev Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package openfeature provides a lightweight bridge between the tracer's early Remote Config subscription and the late-created OpenFeature DatadogProvider.

This package intentionally has minimal dependencies (only internal/remoteconfig) so the tracer can import it without pulling in the OpenFeature SDK or OTel.

Index

Constants

View Source
const (
	// FFEProductName is the RC product name for feature flag evaluation.
	FFEProductName = "FFE_FLAGS"
)

Variables

This section is empty.

Functions

func AddSpanEnrichment added in v2.10.0

func AddSpanEnrichment(key any, eval *FeatureFlagEvaluation)

AddSpanEnrichment records eval in the global span enrichment store.

func AttachCallback

func AttachCallback(cb Callback) bool

AttachCallback wires the given callback to the global RC subscription. If SubscribeRC() was called (i.e. the tracer subscribed), it replays any buffered config and returns true. Otherwise returns false, meaning the caller should fall back to its own RC subscription.

func GetBufferedForTest

func GetBufferedForTest() remoteconfig.ProductUpdate

GetBufferedForTest returns the current buffered update for testing.

func RemoteConfigSourceSelected

func RemoteConfigSourceSelected(cfg *config.Config) bool

RemoteConfigSourceSelected reports whether cfg resolves to SourceRemoteConfig. It lets the tracer decide whether to keep its eager Remote Config subscription without importing this package's full Settings machinery.

func ResetForTest

func ResetForTest()

ResetForTest resets the global rcState for test isolation.

func SetBufferedForTest

func SetBufferedForTest(u remoteconfig.ProductUpdate)

SetBufferedForTest sets a buffered update for testing.

func SetSubscribedForTest

func SetSubscribedForTest(v bool)

SetSubscribedForTest sets the subscribed flag without actually calling Subscribe.

func SubscribeProvider

func SubscribeProvider(cb remoteconfig.ProductCallback) (tracerOwnsSubscription bool, err error)

SubscribeProvider attempts to subscribe a provider callback to RC. It holds the subscription mutex to prevent races with SubscribeRC.

func SubscribeRC

func SubscribeRC() error

SubscribeRC subscribes to the FFE_FLAGS RC product using a forwarding callback. It is called by the tracer during startRemoteConfig() so that FFE_FLAGS is included in the first RC poll.

Types

type Callback

type Callback func(update remoteconfig.ProductUpdate) map[string]rc.ApplyStatus

Callback is a function that processes an RC product update and returns apply statuses. This matches the signature of DatadogProvider.rcCallback.

type FeatureFlagEvaluation added in v2.10.0

type FeatureFlagEvaluation struct {
	FlagKey string
	// SerialId is the optional serial ID from flag metadata. Nil for runtime defaults.
	SerialID *uint32
	// Subject is the targeting key / subject of experiment. Non-empty only when evaluation
	// should be logged (doLog=true).
	Subject string
	// DefaultValue is the default value used. Non-nil only when a runtime default was used.
	DefaultValue any
}

FeatureFlagEvaluation represents a single feature flag evaluation to be recorded in span enrichment.

type Settings

type Settings struct {
	Source Source

	// AgentlessBaseURL is the configured Agentless base URL override.
	// SENSITIVE: may embed credentials; never log.
	AgentlessBaseURL string
	PollInterval     time.Duration
	RequestTimeout   time.Duration

	Site   string
	APIKey string
	Env    string

	// LegacyKeyDecided reports whether DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED
	// was the deciding input for Source.
	LegacyKeyDecided bool
}

Settings is the resolved, ready-to-use configuration for starting a feature-flag delivery source.

func ResolveSettings

func ResolveSettings(cfg *config.Config) Settings

ResolveSettings resolves the feature-flag delivery Settings from cfg.

type Source

type Source int

Source identifies which delivery mechanism feeds feature-flag configuration to the provider.

const (
	// SourceDisabled means no configuration source should be started.
	SourceDisabled Source = iota
	// SourceAgentless means configuration is polled directly from Datadog over HTTPS.
	SourceAgentless
	// SourceRemoteConfig means configuration is delivered through the Agent's Remote Config.
	SourceRemoteConfig
)

type SpanEnrichment added in v2.10.0

type SpanEnrichment struct {
	// contains filtered or unexported fields
}

SpanEnrichment accumulates feature flag evaluations to be encoded as span tags.

SpanEnrichment is not safe for concurrent use on its own. Thread safety is provided externally: every caller must hold the owning span's mu (ddtrace/tracer.Span.mu) before calling any method.

func DrainSpanEnrichment added in v2.10.0

func DrainSpanEnrichment(key any) *SpanEnrichment

DrainSpanEnrichment removes and returns enrichment from the global span enrichment store.

func (*SpanEnrichment) GetSpanTags added in v2.10.0

func (se *SpanEnrichment) GetSpanTags() map[string]string

GetSpanTags returns span tags encoding accumulated feature flag evaluations. The caller must hold the owning span's mu.

Jump to

Keyboard shortcuts

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