cloudflare-log-collector

telemetry

import "github.com/afreidah/cloudflare-log-collector/internal/telemetry"

Index

Constants

const (
    // TracerName identifies spans created by this service.
    TracerName = "cloudflare-log-collector"
)

Variables

var (
    AttrDataset    = attribute.Key("cflog.dataset")
    AttrEventCount = attribute.Key("cflog.event_count")
)

Version of the service for trace metadata. Set at build time via -ldflags “-X github.com/afreidah/cloudflare-log-collector/internal/telemetry.Version=…”

var Version = "dev"

func InitTracer

func InitTracer(ctx context.Context, cfg config.TracingConfig) (func(context.Context) error, error)

InitTracer initializes the OpenTelemetry tracer with OTLP export. Returns a shutdown function that should be called on service termination to flush spans.

func StartClientSpan

func StartClientSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartClientSpan creates a span with SpanKindClient for outbound service calls. Client spans are required for Tempo’s service graph to detect service-to-service edges.

func StartSpan

func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartSpan creates a new span with the given name and attributes.

func Tracer

func Tracer() trace.Tracer

Tracer returns the global tracer for this service.

type TraceHandler

TraceHandler wraps an slog.Handler and injects OpenTelemetry trace context (trace_id, span_id) into every log record that has an active span.

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

func NewTraceHandler

func NewTraceHandler(inner slog.Handler) *TraceHandler

NewTraceHandler creates a handler that injects trace context into log records before delegating to the inner handler.

func (*TraceHandler) Enabled

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

Enabled delegates to the inner handler.

func (*TraceHandler) Handle

func (h *TraceHandler) Handle(ctx context.Context, r slog.Record) error

Handle adds trace_id and span_id attributes if the context carries an active span, then delegates to the inner handler.

func (*TraceHandler) WithAttrs

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

WithAttrs returns a new TraceHandler wrapping the inner handler with attrs.

func (*TraceHandler) WithGroup

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

WithGroup returns a new TraceHandler wrapping the inner handler with a group.

Generated by gomarkdoc