Documentation
¶
Index ¶
- Variables
- func ContainsCredential(s string) bool
- func NewTraceLogHandler(inner slog.Handler) slog.Handler
- func ScrubCredentials(s string) string
- type Runtime
- func (r *Runtime) Enabled() bool
- func (r *Runtime) MakeWriteSpanHook() func(batchSize int) func(error)
- func (r *Runtime) PrometheusHandler() http.Handler
- func (r *Runtime) RecordProviderRequest(ctx context.Context, provider string, model string, orgID string, ...)
- func (r *Runtime) RecordProxyRequest(ctx context.Context, provider, model, orgID, workspaceID, path string, ...)
- func (r *Runtime) RecordTraceEnqueued()
- func (r *Runtime) RecordTraceFlush(batchSize int, duration time.Duration)
- func (r *Runtime) RecordTraceQueueDrop(provider, model, orgID, workspaceID, path string, status int)
- func (r *Runtime) RecordTraceWriteFailure(operation string, failedCount int, errorClass string, store string)
- func (r *Runtime) RecordTraceWritten(count int)
- func (r *Runtime) RegisterTraceQueueCapacityGauge(capacityFn func() int)
- func (r *Runtime) RegisterTraceQueueDepthGauge(queueLenFn func() int)
- func (r *Runtime) Shutdown(ctx context.Context) error
- func (r *Runtime) SpanEnrichmentMiddleware(next http.Handler) http.Handler
- func (r *Runtime) StartTraceEnqueueSpan(ctx context.Context, provider string, model string, orgID string, ...) (context.Context, func(accepted bool))
- func (r *Runtime) WrapAuthMiddleware(next http.Handler) http.Handler
- func (r *Runtime) WrapHTTPHandler(next http.Handler) http.Handler
- func (r *Runtime) WrapHTTPTransport(base http.RoundTripper) http.RoundTripper
- func (r *Runtime) WrapRouteSpan(next http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
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).
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
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
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
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) MakeWriteSpanHook ¶ added in v1.1.8
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
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
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
RecordTraceWritten increments a counter for traces successfully persisted.
func (*Runtime) RegisterTraceQueueCapacityGauge ¶ added in v1.1.8
RegisterTraceQueueCapacityGauge registers an async gauge that reports the trace write queue capacity each collection cycle.
func (*Runtime) RegisterTraceQueueDepthGauge ¶ added in v1.1.8
RegisterTraceQueueDepthGauge registers an async gauge that reports the current trace write queue depth each collection cycle.
func (*Runtime) SpanEnrichmentMiddleware ¶
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
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 ¶
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.