otlp

package
v1.3.6 Latest Latest
Warning

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

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

Documentation

Overview

Package otlp implements a minimal OTLP/HTTP log exporter for audit events. It is configured entirely through the standard OTEL_* environment variables (https://opentelemetry.io/docs/specs/otel/protocol/exporter/) and supports only the http/protobuf transport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRetryAfter added in v1.3.6

func ParseRetryAfter(v string) time.Duration

ParseRetryAfter handles both delta-seconds and HTTP-date forms. Exported for reuse by the policy-fetch retry loop in cmd, which faces the same header from the same SaaS.

Types

type Config

type Config struct {
	Endpoint      string            // final URL with /v1/logs path already applied
	Headers       map[string]string // extra HTTP headers for each export request
	Timeout       time.Duration     // per-attempt HTTP timeout
	Compression   string            // "gzip" or "none"
	ServiceName   string            // resource service.name
	ResourceAttrs map[string]string // parsed OTEL_RESOURCE_ATTRIBUTES (excluding service.name)
}

Config is the resolved OTLP/HTTP exporter configuration.

func ConfigFromEnv

func ConfigFromEnv(getenv func(string) string) (cfg Config, enabled bool, err error)

ConfigFromEnv resolves the exporter configuration from OTEL_* environment variables via getenv (pass os.Getenv outside tests). It returns enabled == false when no OTLP endpoint is configured; an error means an endpoint was configured but unusable, in which case export stays disabled.

type Exporter

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

Exporter batches audit events and ships them to an OTLP/HTTP logs endpoint. It implements events.EventSink; Consume never blocks — events are dropped when the queue is full or after shutdown.

func New

func New(cfg Config, version string, logger *slog.Logger) *Exporter

New creates an exporter and starts its background worker.

func NewFromEnv

func NewFromEnv(version string, logger *slog.Logger) (*Exporter, error)

NewFromEnv builds an exporter from the standard OTEL_* environment variables. It returns (nil, nil) when no OTLP endpoint is configured and (nil, err) when the configuration is present but unusable.

func (*Exporter) Consume

func (e *Exporter) Consume(ev events.AuditEvent)

Consume implements events.EventSink. It never blocks: when the queue is full or the exporter has been shut down, the event is counted as dropped. The mutex makes the closed check and the send atomic with respect to Shutdown closing the queue (a bare closed-flag check would race and panic on send-to-closed-channel); it is only ever held for a non-blocking send.

func (*Exporter) Endpoint

func (e *Exporter) Endpoint() string

Endpoint returns the resolved OTLP logs endpoint URL.

func (*Exporter) Shutdown

func (e *Exporter) Shutdown(ctx context.Context) error

Shutdown stops the worker and flushes any queued events, bounded by ctx.

Jump to

Keyboard shortcuts

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