otel

package
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: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSampler

func DefaultSampler(ratio int) bool

DefaultSampler determines if an item should be sampled based on the sampling ratio. This function is not used for any purpose requiring cryptographic security.

func GetLogger

func GetLogger() log.Logger

GetLogger returns the current logger instance. The result of this function should not be cached unless the caller is sure that OTLP has been started.

func GetMeter

func GetMeter() metric.Meter

GetMeter returns the current meter instance. The result of this function should not be cached unless the caller is sure that OTLP has been started.

func GetTracer

func GetTracer() trace.Tracer

GetTracer returns the current tracer instance. The result of this function should not be cached unless the caller is sure that OTLP has been started.

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 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 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 SetConfig

func SetConfig(conf Config)

SetConfig sets the configuration for the OTLP provider. The configuration must be set before calling StartOTLP.

func SetSamplingConfig

func SetSamplingConfig(config *gql.GetSamplingConfigResponse)

SetSamplingConfig sets the sampling configuration for the custom sampler. This function is called when the sampling configuration is received from the LaunchDarkly API.

func Shutdown

func Shutdown()

Shutdown flushes pending data and shuts down the OTLP instances.

func StartOTLP

func StartOTLP() error

StartOTLP configures otel to send data to the LaunchDarkly OTLP endpoints. Under ideal use this function is called once at startup. The Shutdown function should be called when the application is shutting down to ensure delivery of any pending events.

Types

type Config

type Config struct {
	OtlpEndpoint       string
	ResourceAttributes []attribute.KeyValue
	Sampler            sdktrace.Sampler
}

Config contains the configuration for the OTLP provider.

type CustomSampler

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

CustomSampler is a custom sampler that uses sampling configuration to determine if a span should be sampled

func NewCustomSampler

func NewCustomSampler(sampler SamplerFunc) *CustomSampler

NewCustomSampler creates a new CustomSampler with the given sampler function

func (*CustomSampler) IsSamplingEnabled

func (cs *CustomSampler) IsSamplingEnabled() bool

IsSamplingEnabled returns true if sampling is enabled

func (*CustomSampler) SampleLog

func (cs *CustomSampler) SampleLog(record sdklog.Record) LogSamplingResult

SampleLog samples a log record based on the sampling configuration

func (*CustomSampler) SampleSpan

func (cs *CustomSampler) SampleSpan(span ReadonlySpanSubset) SamplingResult

SampleSpan samples a span based on the sampling configuration

func (*CustomSampler) SetConfig

SetConfig sets the sampling configuration

type ExportSampler

type ExportSampler interface {
	// SampleSpan samples a span and returns the result
	SampleSpan(span ReadonlySpanSubset) SamplingResult
	// SampleLog samples a log record and returns the result
	SampleLog(record sdklog.Record) LogSamplingResult
	// IsSamplingEnabled returns true if sampling is enabled
	IsSamplingEnabled() bool
	// SetConfig sets the sampling configuration
	SetConfig(config *gql.GetSamplingConfigSamplingSamplingConfig)
}

ExportSampler defines the interface for export samplers

type LogSamplingResult

type LogSamplingResult struct {
	// Sample indicates whether the span/log should be sampled
	Sample bool
	// Attributes contains additional attributes to add to the span/log
	Attributes []log.KeyValue
}

LogSamplingResult represents the result of sampling a log record

type ReadonlySpanSubset

type ReadonlySpanSubset interface {
	// Events returns all the events that occurred within in the spans
	// lifetime.
	Events() []trace.Event
	// Name returns the name of the span.
	Name() string
	// Attributes returns the defining attributes of the span.
	// The order of the returned attributes is not guaranteed to be stable across invocations.
	Attributes() []attribute.KeyValue
}

ReadonlySpanSubset implements the components of the trace.ReadonlySpan that are needed for sampling. The trace.ReadonlySpan interface cannot be directly implemented, because it contains a `private()` method. So we define this subset so we can make instances in unit tests.

type SamplerFunc

type SamplerFunc func(ratio int) bool

SamplerFunc is a function type for sampling decisions

type SamplingResult

type SamplingResult struct {
	// Sample indicates whether the span/log should be sampled
	Sample bool
	// Attributes contains additional attributes to add to the span/log
	Attributes []attribute.KeyValue
}

SamplingResult represents the result of sampling a span or log

Jump to

Keyboard shortcuts

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