observability

package
v1.1.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JWTPattern = regexp.MustCompile(`(?i)eyj[a-z0-9_-]{8,}\.[a-z0-9_-]{8,}\.[a-z0-9_-]{8,}`)

JWTPattern matches JWT-like tokens (three base64url segments separated by dots). Shared between telemetry credential scrubbing and PII redaction in trace body capture (cmd/ongoingai/trace_capture.go).

View Source
var TokenPrefixPattern = regexp.MustCompile(`(?i)\b(?:sk|pk|rk|xox[baprs]|gh[pousr]|pat)_[a-z0-9_-]{8,}\b`)

TokenPrefixPattern matches common API key prefix formats: sk_, pk_, rk_, xox*_, ghp/gho/ghu/ghs/ghr_, pat_. Shared between telemetry credential scrubbing and PII redaction in trace body capture (cmd/ongoingai/trace_capture.go).

Functions

func ContainsCredential added in v1.1.8

func ContainsCredential(s string) bool

ContainsCredential reports whether s matches any known credential pattern. Short strings (< 8 chars) are skipped as a fast path since no credential pattern can match a string that short.

func NewTraceLogHandler added in v1.1.8

func NewTraceLogHandler(inner slog.Handler) slog.Handler

NewTraceLogHandler returns an slog.Handler that injects trace_id and span_id attributes from the context's active span into each log record. If inner is nil, slog.Default().Handler() is used.

func ScrubCredentials added in v1.1.8

func ScrubCredentials(s string) string

ScrubCredentials replaces all detected credential patterns in s with [CREDENTIAL_REDACTED]. If no patterns match, s is returned unchanged with no allocation.

Types

type Runtime

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

Runtime exposes OpenTelemetry HTTP wrappers and gateway metric hooks.

func Setup

func Setup(ctx context.Context, cfg config.OTelConfig, serviceVersion string, logger *slog.Logger) (*Runtime, error)

Setup initializes OpenTelemetry providers and runtime hooks.

func (*Runtime) Enabled

func (r *Runtime) Enabled() bool

Enabled reports whether OpenTelemetry instrumentation is active.

func (*Runtime) MakeWriteSpanHook added in v1.1.8

func (r *Runtime) MakeWriteSpanHook() func(batchSize int) func(error)

MakeWriteSpanHook returns a function suitable for WriterMetrics.OnWriteStart. Each invocation starts a top-level gateway.trace.write span and returns an end function the writer calls after the storage write completes.

func (*Runtime) PrometheusHandler added in v1.1.8

func (r *Runtime) PrometheusHandler() http.Handler

PrometheusHandler returns the HTTP handler for Prometheus metric scraping, or nil when Prometheus export is not enabled.

func (*Runtime) RecordProviderRequest added in v1.1.8

func (r *Runtime) RecordProviderRequest(
	ctx context.Context,
	provider string,
	model string,
	orgID string,
	workspaceID string,
	path string,
	statusCode int,
	durationMS int64,
)

RecordProviderRequest records a single upstream provider request with its status code and latency. The context carries the active span for exemplar attachment on histogram data points (metrics→traces correlation).

func (*Runtime) RecordProxyRequest added in v1.1.8

func (r *Runtime) RecordProxyRequest(ctx context.Context, provider, model, orgID, workspaceID, path string, statusCode int, durationMS int64)

RecordProxyRequest records a proxy request with tenant-scoped attributes. The context carries the active span for exemplar attachment on histogram data points (metrics→traces correlation).

func (*Runtime) RecordTraceEnqueued added in v1.1.8

func (r *Runtime) RecordTraceEnqueued()

RecordTraceEnqueued increments a counter when a trace is successfully enqueued.

func (*Runtime) RecordTraceFlush added in v1.1.8

func (r *Runtime) RecordTraceFlush(batchSize int, duration time.Duration)

RecordTraceFlush records a batch flush event with its size and duration.

func (*Runtime) RecordTraceQueueDrop

func (r *Runtime) RecordTraceQueueDrop(provider, model, orgID, workspaceID, path string, status int)

RecordTraceQueueDrop increments a counter when the async trace queue is full.

func (*Runtime) RecordTraceWriteFailure

func (r *Runtime) RecordTraceWriteFailure(operation string, failedCount int, errorClass string, store string)

RecordTraceWriteFailure increments a counter for dropped trace records.

func (*Runtime) RecordTraceWritten added in v1.1.8

func (r *Runtime) RecordTraceWritten(count int)

RecordTraceWritten increments a counter for traces successfully persisted.

func (*Runtime) RegisterTraceQueueCapacityGauge added in v1.1.8

func (r *Runtime) RegisterTraceQueueCapacityGauge(capacityFn func() int)

RegisterTraceQueueCapacityGauge registers an async gauge that reports the trace write queue capacity each collection cycle.

func (*Runtime) RegisterTraceQueueDepthGauge added in v1.1.8

func (r *Runtime) RegisterTraceQueueDepthGauge(queueLenFn func() int)

RegisterTraceQueueDepthGauge registers an async gauge that reports the current trace write queue depth each collection cycle.

func (*Runtime) Shutdown

func (r *Runtime) Shutdown(ctx context.Context) error

Shutdown flushes and stops OpenTelemetry providers.

func (*Runtime) SpanEnrichmentMiddleware

func (r *Runtime) SpanEnrichmentMiddleware(next http.Handler) http.Handler

SpanEnrichmentMiddleware adds gateway attributes and stable error status on 5xx responses.

func (*Runtime) StartTraceEnqueueSpan added in v1.1.8

func (r *Runtime) StartTraceEnqueueSpan(
	ctx context.Context,
	provider string,
	model string,
	orgID string,
	workspaceID string,
	path string,
) (context.Context, func(accepted bool))

StartTraceEnqueueSpan starts a gateway.trace.enqueue span as a child of the provided context. The returned function must be called to end the span, passing whether the enqueue was accepted.

func (*Runtime) WrapAuthMiddleware added in v1.1.8

func (r *Runtime) WrapAuthMiddleware(next http.Handler) http.Handler

WrapAuthMiddleware wraps an auth handler with a gateway.auth child span. The span records whether the auth check allowed or denied the request.

func (*Runtime) WrapHTTPHandler

func (r *Runtime) WrapHTTPHandler(next http.Handler) http.Handler

WrapHTTPHandler wraps an inbound HTTP handler with OpenTelemetry spans.

func (*Runtime) WrapHTTPTransport

func (r *Runtime) WrapHTTPTransport(base http.RoundTripper) http.RoundTripper

WrapHTTPTransport wraps an outbound HTTP transport with OpenTelemetry spans.

func (*Runtime) WrapRouteSpan added in v1.1.8

func (r *Runtime) WrapRouteSpan(next http.Handler) http.Handler

WrapRouteSpan wraps a proxy handler with a gateway.route child span. The provider and prefix are inferred from the request path.

Jump to

Keyboard shortcuts

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