Help us shape the future of Go! Take the 2026 Go Developer Survey

telemetry

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package telemetry configures OpenTelemetry metrics and traces for AFI processes. Instrumentation uses the OTel API only; exporters are OTLP and optional Prometheus scrape.

Index

Constants

View Source
const (
	AttrModality     = "afi.modality"
	AttrOutcome      = "afi.outcome"
	AttrProviderType = "afi.provider_type"
	AttrOrgID        = "afi.org_id"
	AttrRouteModel   = "afi.route_model"
	AttrTokenType    = "afi.token_type"
	AttrStatusClass  = "http.status_class"
)

Attr keys used across AFI instrumentation (low cardinality on metrics).

View Source
const (
	OutcomeOK    = "ok"
	OutcomeError = "error"
	OutcomeQuota = "quota"
	OutcomeAuth  = "auth"
	OutcomeDeny  = "deny"
)

Outcomes for afi.gateway.requests.

Variables

This section is empty.

Functions

func HTTPClient

func HTTPClient(timeout time.Duration) *http.Client

HTTPClient returns an *http.Client whose transport propagates W3C trace context.

func HTTPHandler

func HTTPHandler(h http.Handler, operation string) http.Handler

HTTPHandler wraps h with OTel HTTP server instrumentation.

func Meter

func Meter(name string) metric.Meter

Meter returns a named meter from the global provider.

func MountMetrics

func MountMetrics(mux *http.ServeMux, handler http.Handler)

MountMetrics registers /metrics when handler is non-nil.

func Tracer

func Tracer(name string) trace.Tracer

Tracer returns a named tracer from the global provider.

func WrapTransport

func WrapTransport(base http.RoundTripper) http.RoundTripper

WrapTransport returns an instrumented RoundTripper.

Types

type ControlPlaneMetrics

type ControlPlaneMetrics struct {
	Requests          metric.Int64Counter
	Duration          metric.Float64Histogram
	SpokeUsageReports metric.Int64Counter
	SpokeUsageTokens  metric.Int64Counter
}

ControlPlaneMetrics holds control-plane HTTP instruments.

func NewControlPlaneMetrics

func NewControlPlaneMetrics() (*ControlPlaneMetrics, error)

NewControlPlaneMetrics creates CP instruments.

func (*ControlPlaneMetrics) Record

func (c *ControlPlaneMetrics) Record(ctx context.Context, route, statusClass string, seconds float64)

Record records a CP HTTP request.

func (*ControlPlaneMetrics) RecordSpokeUsage added in v0.3.0

func (c *ControlPlaneMetrics) RecordSpokeUsage(ctx context.Context, region, status, modality string, prompt, completion int64)

RecordSpokeUsage records an observed spoke usage report (no DB write).

type GatewayMetrics

type GatewayMetrics struct {
	Requests         metric.Int64Counter
	RequestDuration  metric.Float64Histogram
	UpstreamDuration metric.Float64Histogram
	Tokens           metric.Int64Counter
	QuotaRejections  metric.Int64Counter
	// contains filtered or unexported fields
}

GatewayMetrics holds gateway instruments.

func NewGatewayMetrics

func NewGatewayMetrics() (*GatewayMetrics, error)

NewGatewayMetrics creates instruments on the global meter provider.

func (*GatewayMetrics) RecordRequest

func (g *GatewayMetrics) RecordRequest(ctx context.Context, modality, outcome string, seconds float64)

RecordRequest increments request counters and duration.

func (*GatewayMetrics) RecordTokens

func (g *GatewayMetrics) RecordTokens(ctx context.Context, modality string, prompt, completion int64)

RecordTokens increments token counters.

func (*GatewayMetrics) RecordUpstream

func (g *GatewayMetrics) RecordUpstream(ctx context.Context, modality, providerType string, seconds float64)

RecordUpstream records upstream call duration.

func (*GatewayMetrics) SetSnapshotVersion

func (g *GatewayMetrics) SetSnapshotVersion(v int64)

SetSnapshotVersion updates the observable gauge.

type Provider

type Provider struct {
	TracerProvider *sdktrace.TracerProvider
	MeterProvider  *sdkmetric.MeterProvider
	MetricsHandler http.Handler // non-nil when Prometheus scrape is enabled
	// contains filtered or unexported fields
}

Provider holds initialized OTel providers and an optional Prometheus scrape handler.

func Init

func Init(ctx context.Context, cfg *kernel.Config, serviceName string) (*Provider, error)

Init configures global TracerProvider and MeterProvider from kernel telemetry config. serviceName is used when cfg.Telemetry.ServiceName is empty (e.g. "afi-gateway"). When telemetry is disabled, returns a no-op Provider and nil error.

func (*Provider) Shutdown

func (p *Provider) Shutdown(ctx context.Context) error

Shutdown flushes and stops exporters.

type WorkerMetrics

type WorkerMetrics struct {
	UsageProcessed          metric.Int64Counter
	UsageErrors             metric.Int64Counter
	PlatformEventsPublished metric.Int64Counter
	ProcessDuration         metric.Float64Histogram
}

WorkerMetrics holds worker outbox instruments.

func NewWorkerMetrics

func NewWorkerMetrics() (*WorkerMetrics, error)

NewWorkerMetrics creates worker instruments.

Jump to

Keyboard shortcuts

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