Documentation
¶
Index ¶
- func ConfigureLogger(cfg Config)
- func Ctx(ctx context.Context) *zerolog.Logger
- func Debug() *zerolog.Event
- func EndSpan(span trace.Span, err error)
- func Error() *zerolog.Event
- func ExtractContext(ctx context.Context, headers map[string][]string) context.Context
- func Info() *zerolog.Event
- func InitLogger(opts LoggerOptions)
- func InjectContext(ctx context.Context, headers map[string][]string) map[string][]string
- func Logger() zerolog.Logger
- func MessagingOperationProcess() attribute.KeyValue
- func MessagingOperationPublish() attribute.KeyValue
- func MessagingSubject(subject string) attribute.KeyValue
- func MessagingSystem() attribute.KeyValue
- func SetExitFunc(fn func(int))
- func SetGlobal(t *Telemetry)
- func SetLogger(l zerolog.Logger)
- func Warn() *zerolog.Event
- func WrapContext(ctx context.Context, l *Telemetry) context.Context
- type AttrCache
- type Config
- type FastCounter
- type FastGauge
- type FastHistogram
- type FatalEvent
- type HistogramOpt
- type LoggerOptions
- type MonitorConfig
- type Registry
- func (r *Registry) AttrCache() *AttrCache
- func (r *Registry) Counter(name string, opts ...metric.Int64CounterOption) (*FastCounter, error)
- func (r *Registry) Gauge(name string, opts ...metric.Int64GaugeOption) (*FastGauge, error)
- func (r *Registry) Histogram(name string, opts ...metric.Float64HistogramOption) (*FastHistogram, error)
- type TelConfig
- type Telemetry
- func (t *Telemetry) Config() Config
- func (t *Telemetry) Meter(ins string, opts ...metric.MeterOption) metric.Meter
- func (t *Telemetry) Registry() *Registry
- func (t *Telemetry) Shutdown(ctx context.Context) error
- func (t *Telemetry) Start(ctx context.Context) error
- func (t *Telemetry) StartSpan(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func (t *Telemetry) Tracer(name string) trace.Tracer
- type Timer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigureLogger ¶
func ConfigureLogger(cfg Config)
ConfigureLogger applies Config.LogLevel / LogEncode to the process logger. Call once at process startup before concurrent logging (not from NewWithConfig).
func ExtractContext ¶
ExtractContext reads trace context from a string header map.
func InitLogger ¶
func InitLogger(opts LoggerOptions)
InitLogger configures structured logging. Safe to call at startup (and again to reconfigure).
func InjectContext ¶
InjectContext writes trace context into a string header map.
Example ¶
ExampleInjectContext demonstrates W3C trace context propagation via headers.
headers := InjectContext(context.Background(), map[string][]string{})
_ = ExtractContext(context.Background(), headers)
func MessagingSubject ¶
MessagingSubject returns a messaging destination attribute for NATS spans.
func MessagingSystem ¶
func SetExitFunc ¶
func SetExitFunc(fn func(int))
SetExitFunc overrides the function called after Fatal logs (for tests).
Types ¶
type AttrCache ¶
type AttrCache struct {
// contains filtered or unexported fields
}
AttrCache interns attribute sets and metric options for hot-path label reuse. Entries are sharded by subject hash; each shard is a lock-free CoW map.
func (*AttrCache) SetDetector ¶
func (c *AttrCache) SetDetector(d *cardinalityDetector)
SetDetector wires optional cardinality observation into the hot path.
func (*AttrCache) SubjectRecordOpts ¶
func (c *AttrCache) SubjectRecordOpts(subject string) []metric.RecordOption
type Config ¶
type Config struct {
MonitorConfig
TelConfig
Service string `env:"TEL_SERVICE_NAME"`
Namespace string `env:"NAMESPACE" envDefault:"default"`
Environment string `env:"DEPLOY_ENVIRONMENT" envDefault:"dev"`
Version string `env:"VERSION" envDefault:"dev"`
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
LogEncode string `env:"LOG_ENCODE" envDefault:"json"`
Debug bool `env:"DEBUG" envDefault:"false"`
}
Config holds process-wide telemetry settings. Embedded configs stay first (embeddedstructfieldcheck); fieldalignment is excluded for this file in .golangci.yml and make align.
goalign:ignore
func DefaultConfig ¶
func DefaultConfig() Config
func DefaultDebugConfig ¶
func DefaultDebugConfig() Config
type FastCounter ¶
type FastCounter struct {
// contains filtered or unexported fields
}
func (*FastCounter) AddWith ¶
func (c *FastCounter) AddWith(ctx context.Context, n int64, subject string)
func (*FastCounter) WithAttrs ¶
func (c *FastCounter) WithAttrs(attrs attribute.Set) *FastCounter
type FastGauge ¶
type FastGauge struct {
// contains filtered or unexported fields
}
func (*FastGauge) RecordWith ¶
type FastHistogram ¶
type FastHistogram struct {
// contains filtered or unexported fields
}
func (*FastHistogram) RecordWith ¶
func (h *FastHistogram) RecordWith(ctx context.Context, value float64, subject string)
func (*FastHistogram) WithAttrs ¶
func (h *FastHistogram) WithAttrs(attrs attribute.Set) *FastHistogram
type FatalEvent ¶
type FatalEvent struct {
// contains filtered or unexported fields
}
FatalEvent mirrors zerolog's chainable API but exits via SetExitFunc instead of os.Exit directly.
func Fatal ¶
func Fatal() *FatalEvent
Fatal logs at fatal level and invokes the configured exit function (default os.Exit).
func (*FatalEvent) Err ¶
func (f *FatalEvent) Err(err error) *FatalEvent
func (*FatalEvent) Msg ¶
func (f *FatalEvent) Msg(msg string)
func (*FatalEvent) Msgf ¶
func (f *FatalEvent) Msgf(format string, v ...any)
func (*FatalEvent) Str ¶
func (f *FatalEvent) Str(key, val string) *FatalEvent
type HistogramOpt ¶
type MonitorConfig ¶
type MonitorConfig struct {
MonitorAddr string `env:"MONITOR_ADDR" envDefault:"0.0.0.0:8011"`
Enable bool `env:"MONITOR_ENABLE" envDefault:"true"`
}
MonitorConfig holds health/stats monitor settings.
goalign:ignore
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Counter ¶
func (r *Registry) Counter(name string, opts ...metric.Int64CounterOption) (*FastCounter, error)
func (*Registry) Histogram ¶
func (r *Registry) Histogram(name string, opts ...metric.Float64HistogramOption) (*FastHistogram, error)
type TelConfig ¶
type TelConfig struct {
Address string `env:"TEL_COLLECTOR_GRPC_ADDR" envDefault:"127.0.0.1:4317"`
ServerName string `env:"TEL_COLLECTOR_TLS_SERVER_NAME"`
Raw struct {
CA []byte `env:"OTEL_COLLECTOR_TLS_CA_CERT"`
Cert []byte `env:"OTEL_COLLECTOR_TLS_CLIENT_CERT"`
Key []byte `env:"OTEL_COLLECTOR_TLS_CLIENT_KEY"`
}
BucketView []HistogramOpt
Metrics struct {
CardinalityDetector struct {
MaxCardinality int `env:"METRICS_CARDINALITY_DETECTOR_MAX_CARDINALITY" envDefault:"100"`
MaxInstruments int `env:"METRICS_CARDINALITY_DETECTOR_MAX_INSTRUMENTS" envDefault:"500"`
DiagnosticInterval time.Duration `env:"METRICS_CARDINALITY_DETECTOR_DIAGNOSTIC_INTERVAL" envDefault:"10m"`
Enable bool `env:"METRICS_CARDINALITY_DETECTOR_ENABLE" envDefault:"true"`
}
EnableRetry bool `env:"METRICS_ENABLE_RETRY" envDefault:"false"`
}
MetricsPeriodicIntervalSec int `env:"TEL_METRIC_PERIODIC_INTERVAL_SEC" envDefault:"15"`
// ExportIntervalSec overrides MetricsPeriodicIntervalSec when > 0 (OTLP push cadence).
ExportIntervalSec int `env:"TEL_EXPORT_INTERVAL_SEC" envDefault:"0"`
WithInsecure bool `env:"TEL_EXPORTER_WITH_INSECURE" envDefault:"true"`
Enable bool `env:"TEL_ENABLE" envDefault:"true"`
WithCompression bool `env:"TEL_ENABLE_COMPRESSION" envDefault:"true"`
Traces struct {
Enable bool `env:"TEL_TRACES_ENABLE" envDefault:"true"`
}
}
TelConfig holds OTLP export and related collector settings.
goalign:ignore
type Telemetry ¶
type Telemetry struct {
// contains filtered or unexported fields
}
Telemetry is the process-wide metrics/traces runtime. Telemetry is the process-wide metrics/traces runtime.
goalign:ignore
func NewWithConfig ¶
func NewWithTracerProvider ¶
func NewWithTracerProvider(cfg Config, provider trace.TracerProvider) *Telemetry
NewWithTracerProvider wires a custom tracer provider (useful in tests and custom setups).
func (*Telemetry) Shutdown ¶
Shutdown flushes exporters and releases resources. Safe to call after Start, and again after a subsequent Start (restart-safe; not sync.Once).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
Basic example: tel lifecycle and low-allocation metrics.
|
Basic example: tel lifecycle and low-allocation metrics. |
|
internal
|
|
|
bytesconv
Package bytesconv provides zero-allocation string↔[]byte conversions.
|
Package bytesconv provides zero-allocation string↔[]byte conversions. |