telemetry

package
v0.0.0-...-7924dbb Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OtelConfigSet contains all configuration flags for OpenTelemetry telemetry
	OtelConfigSet = config.New("otel")
	// EnabledFlag controls whether OpenTelemetry telemetry is enabled
	EnabledFlag = OtelConfigSet.Bool("otel.enabled", false, "Enable OpenTelemetry telemetry")
	// EndpointFlag specifies the OTLP collector endpoint
	EndpointFlag = OtelConfigSet.String("otel.endpoint", "localhost:4318", "OpenTelemetry collector endpoint (OTLP HTTP)")
	// ServiceNameFlag specifies the service name for traces
	ServiceNameFlag = OtelConfigSet.String("otel.service-name", mechanus.SERVICE_NAME, "Service name for OpenTelemetry traces")
	// InsecureFlag controls whether to use insecure connection to OTLP collectorSERVICE_NAME
	InsecureFlag = OtelConfigSet.Bool("otel.insecure", true, "Use insecure connection to OTLP collector")
)

Functions

func SetupLogging

func SetupLogging(exporter *otlploghttp.Exporter, res *resource.Resource) *sdklog.LoggerProvider

SetupLogging creates and configures the OpenTelemetry log provider

func SetupTracing

func SetupTracing(exporter *otlptrace.Exporter, res *resource.Resource) *sdktrace.TracerProvider

func SpanLogger

func SpanLogger(ctx context.Context, name string, attributes ...attribute.KeyValue) (context.Context, trace.Span, *log.Logger)

SpanLogger starts a new span and returns a context containing the span and a SpanLogger

func TraceGRPCMiddleware

func TraceGRPCMiddleware(cfg *Config) connect.Interceptor

TraceGRPCMiddleware returns a Connect interceptor that adds OpenTelemetry telemetry to gRPC requests

func TraceHttpMiddleware

func TraceHttpMiddleware(cfg *Config, next http.Handler) http.Handler

TraceHttpMiddleware wraps an HTTP handler with OpenTelemetry instrumentation

func WrapLoggerWithOtel

func WrapLoggerWithOtel(logger *log.Logger)

WrapLoggerWithOtel wraps the charm.sh logger with an OpenTelemetry bridge. This intercepts log calls and forwards them to OpenTelemetry while maintaining the original logging behavior. Since charm.sh logger implements slog.Handler, we wrap it and set it as the default slog handler.

Types

type Config

type Config struct {
	Enabled     bool
	Endpoint    string
	ServiceName string
	Insecure    bool
}

Config holds the OpenTelemetry configuration

func GetConfig

func GetConfig() *Config

GetConfig returns the current telemetry configuration

type Manager

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

Manager handles the lifecycle of the OpenTelemetry providers

func NewManager

func NewManager() *Manager

NewManager creates a new telemetry manager

func Setup

func Setup(ctx context.Context, cfg *Config) (*Manager, error)

Setup initializes OpenTelemetry telemetry with the given configuration

func (*Manager) AfterInitialize

func (m *Manager) AfterInitialize(ctx context.Context) error

AfterInitialize is called during the initialization phase

func (*Manager) AfterShutDown

func (m *Manager) AfterShutDown(ctx context.Context) error

AfterShutDown is called after shutdown completes

func (*Manager) BeforeShutdown

func (m *Manager) BeforeShutdown(ctx context.Context) error

BeforeShutdown is called before shutdown begins

func (*Manager) SetExporter

func (m *Manager) SetExporter(exporter *otlptrace.Exporter)

func (*Manager) SetLogExporter

func (m *Manager) SetLogExporter(exporter *otlploghttp.Exporter)

func (*Manager) SetLogProvider

func (m *Manager) SetLogProvider(provider *sdklog.LoggerProvider)

func (*Manager) SetTraceProvider

func (m *Manager) SetTraceProvider(provider *sdktrace.TracerProvider)

func (*Manager) ShutdownCleanup

func (m *Manager) ShutdownCleanup(ctx context.Context) error

ShutdownCleanup performs final cleanup

type OtelLogHandler

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

OtelLogHandler is a slog.Handler that forwards log entries to OpenTelemetry. It wraps the original charm.sh logger handler to maintain existing functionality while also sending logs to the OpenTelemetry collector.

func NewOtelLogHandler

func NewOtelLogHandler(original slog.Handler) *OtelLogHandler

NewOtelLogHandler creates a new handler that forwards logs to both the original handler and OpenTelemetry.

func (*OtelLogHandler) Enabled

func (h *OtelLogHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled returns true if the handler is enabled for the given level.

func (*OtelLogHandler) Handle

func (h *OtelLogHandler) Handle(ctx context.Context, record slog.Record) error

Handle forwards the log record to both the original handler and OpenTelemetry.

func (*OtelLogHandler) WithAttrs

func (h *OtelLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new handler with the given attributes added.

func (*OtelLogHandler) WithGroup

func (h *OtelLogHandler) WithGroup(name string) slog.Handler

WithGroup returns a new handler with the given group added.

Jump to

Keyboard shortcuts

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