telemetry

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: LGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGlobalLogger

func GetGlobalLogger(component string) zerolog.Logger

GetGlobalLogger returns a component-specific logger using the global console logger.

Types

type Config

type Config struct {
	// Endpoint is the OTLP gRPC collector endpoint, either a bare host:port or a URL with a scheme.
	// The default targets the groundcover sensor inside a Kubernetes cluster. A bare host:port is
	// sent in plaintext unless OTEL_EXPORTER_OTLP_INSECURE says otherwise; an https:// URL enables
	// TLS with the host's root CAs, which is what groundcover's BYOC ingestion endpoint needs.
	// Auth headers such as groundcover's ingestion key come from the standard
	// OTEL_EXPORTER_OTLP_HEADERS variable (for example "apikey=<ingestion-key>"). Setting the
	// variable to an empty string disables tracing; the default is applied in loadConfig because
	// the env parser would otherwise substitute it for an explicitly empty value.
	Endpoint string `env:"OTEL_EXPORTER_OTLP_ENDPOINT"`

	// TracesEndpoint is the signal-specific OTLP endpoint; when set it takes precedence over Endpoint.
	TracesEndpoint string `env:"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"`

	// Insecure selects plaintext gRPC for a bare host:port endpoint. Ignored for URL endpoints,
	// where the scheme decides. Unset keeps the plaintext default.
	Insecure *bool `env:"OTEL_EXPORTER_OTLP_INSECURE"`

	// TracesInsecure is the signal-specific form of Insecure; when set it takes precedence.
	TracesInsecure *bool `env:"OTEL_EXPORTER_OTLP_TRACES_INSECURE"`

	// MetricsEndpoint is the OTLP gRPC endpoint for metrics, in the same forms as Endpoint. Metrics
	// are exported only when it is set. Unlike traces they never fall back to Endpoint: the cardinal
	// operator points Endpoint at a collector that accepts traces only, so falling back would fail
	// every export from operator-managed shards.
	MetricsEndpoint string `env:"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"`

	// MetricsInsecure is the metrics form of TracesInsecure; when set it takes precedence over Insecure.
	MetricsInsecure *bool `env:"OTEL_EXPORTER_OTLP_METRICS_INSECURE"`

	// TraceSampleRate is the sampling rate for traces (0.0 to 1.0).
	TraceSampleRate float64 `env:"OTEL_TRACE_SAMPLE_RATE" envDefault:"1.0"`

	// Log level configuration ("debug", "info", "warn", "error").
	LogLevel string `env:"LOG_LEVEL" envDefault:"info"`

	// Log format configuration ("json", "pretty").
	LogFormat string `env:"LOG_FORMAT" envDefault:"json"`

	// SentryDsn is the Sentry DSN.
	SentryDsn string `env:"SENTRY_DSN"`

	// SentryEnvironment is to determine if shard is running in development or production (DEV/PROD).
	SentryEnvironment string `env:"SENTRY_ENVIRONMENT"`

	// PosthogAPIKey is the PostHog API key.
	PosthogAPIKey string `env:"POSTHOG_API_KEY"`
}

type LogFormat

type LogFormat uint8

LogFormat represents the log output format.

const (
	LogFormatUndefined LogFormat = iota // Used as the zero value
	LogFormatJSON                       // Outputs structured JSON logs
	LogFormatPretty                     // Outputs human-readable console logs
)

func ParseLogFormat

func ParseLogFormat(s string) LogFormat

ParseLogFormat converts a string to LogFormat enum.

func (LogFormat) String

func (f LogFormat) String() string

type Options

type Options struct {
	ServiceName     string // Name of the service for telemetry
	Endpoint        string // OTLP trace endpoint, a bare host:port or a URL with a scheme
	Insecure        bool   // Plaintext gRPC for a bare host:port endpoint; ignored for URLs
	MetricsEndpoint string // OTLP metric endpoint in the same forms; empty disables metrics
	MetricsInsecure bool   // Insecure for MetricsEndpoint
	LogLevel        string
	LogFormat       LogFormat // Log output format
	TraceSampleRate float64

	SentryOptions  sentry.Options
	PosthogOptions posthog.Options
}

type Telemetry

type Telemetry struct {
	Logger zerolog.Logger
	// contains filtered or unexported fields
}

func New

func New(opts Options) (Telemetry, error)

func (*Telemetry) CaptureEvent added in v0.0.5

func (t *Telemetry) CaptureEvent(ctx context.Context, event string, properties map[string]any)

CaptureEvent captures an event and sends it to PostHog.

func (*Telemetry) CaptureException added in v0.0.5

func (t *Telemetry) CaptureException(ctx context.Context, err error)

CaptureException captures an exception and sends it to Sentry.

func (*Telemetry) GetLogger

func (t *Telemetry) GetLogger(component string) zerolog.Logger

GetLogger returns a component-specific logger.

func (*Telemetry) GetLoggerWithTrace

func (t *Telemetry) GetLoggerWithTrace(ctx context.Context, component string) zerolog.Logger

GetLoggerWithTrace returns a component-specific logger enriched with trace context.

func (t *Telemetry) MaxCommandLinks() int

MaxCommandLinks returns the resolved span link limit the tracer provider enforces (OTEL_SPAN_LINK_COUNT_LIMIT, default 128). Callers that pre-cap span links should cap at this value so they never build links the SDK would drop.

func (*Telemetry) RecoverAndFlush added in v0.0.5

func (t *Telemetry) RecoverAndFlush(repanic bool)

RecoverAndFlush recovers from a panic and flushes buffered events to Sentry.

func (*Telemetry) Shutdown

func (t *Telemetry) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the telemetry system.

Directories

Path Synopsis
Package trace is a light wrapper over the OpenTelemetry tracing API, modeled on Sourcegraph's internal/trace: one constructor bound to the global tracer provider and a Trace type that adds error helpers to the span.
Package trace is a light wrapper over the OpenTelemetry tracing API, modeled on Sourcegraph's internal/trace: one constructor bound to the global tracer provider and a Trace type that adds error helpers to the span.

Jump to

Keyboard shortcuts

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