Documentation
¶
Overview ¶
Package telemetry provides Prometheus metrics collection and monitoring functionality for the Bifrost HTTP service. It includes middleware for HTTP request tracking and a plugin for tracking upstream provider metrics.
Package telemetry provides Prometheus metrics collection and monitoring functionality for the Bifrost HTTP service. This file contains the setup and configuration for Prometheus metrics collection, including HTTP middleware and metric definitions.
Index ¶
- Constants
- func InitPrometheusMetrics(labels []string)
- func PrometheusMiddleware(handler fasthttp.RequestHandler) fasthttp.RequestHandler
- type ContextKey
- type PrometheusPlugin
- func (p *PrometheusPlugin) Cleanup() error
- func (p *PrometheusPlugin) GetName() string
- func (p *PrometheusPlugin) PostHook(ctx *context.Context, result *schemas.BifrostResponse, ...) (*schemas.BifrostResponse, *schemas.BifrostError, error)
- func (p *PrometheusPlugin) PreHook(ctx *context.Context, req *schemas.BifrostRequest) (*schemas.BifrostRequest, *schemas.PluginShortCircuit, error)
Constants ¶
const (
PluginName = "telemetry"
)
Variables ¶
This section is empty.
Functions ¶
func InitPrometheusMetrics ¶
func InitPrometheusMetrics(labels []string)
func PrometheusMiddleware ¶
func PrometheusMiddleware(handler fasthttp.RequestHandler) fasthttp.RequestHandler
PrometheusMiddleware wraps a FastHTTP handler to collect Prometheus metrics. It tracks:
- Total number of requests
- Request duration
- Request and response sizes
- HTTP status codes
- Bifrost upstream requests and errors
Types ¶
type ContextKey ¶ added in v1.2.3
type ContextKey string
ContextKey is a custom type for prometheus context keys to prevent collisions
type PrometheusPlugin ¶
type PrometheusPlugin struct { // Metrics are defined using promauto for automatic registration UpstreamRequestsTotal *prometheus.CounterVec UpstreamLatency *prometheus.HistogramVec SuccessRequestsTotal *prometheus.CounterVec ErrorRequestsTotal *prometheus.CounterVec InputTokensTotal *prometheus.CounterVec OutputTokensTotal *prometheus.CounterVec CacheHitsTotal *prometheus.CounterVec CostTotal *prometheus.CounterVec // contains filtered or unexported fields }
PrometheusPlugin implements the schemas.Plugin interface for Prometheus metrics. It tracks metrics for upstream provider requests, including:
- Total number of requests
- Request latency
- Error counts
func Init ¶ added in v1.2.3
func Init(pricingManager *pricing.PricingManager, logger schemas.Logger) *PrometheusPlugin
NewPrometheusPlugin creates a new PrometheusPlugin with initialized metrics.
func (*PrometheusPlugin) Cleanup ¶
func (p *PrometheusPlugin) Cleanup() error
func (*PrometheusPlugin) GetName ¶
func (p *PrometheusPlugin) GetName() string
GetName returns the name of the plugin.
func (*PrometheusPlugin) PostHook ¶
func (p *PrometheusPlugin) PostHook(ctx *context.Context, result *schemas.BifrostResponse, bifrostErr *schemas.BifrostError) (*schemas.BifrostResponse, *schemas.BifrostError, error)
PostHook calculates duration and records upstream metrics for successful requests. It records:
- Request latency
- Total request count
func (*PrometheusPlugin) PreHook ¶
func (p *PrometheusPlugin) PreHook(ctx *context.Context, req *schemas.BifrostRequest) (*schemas.BifrostRequest, *schemas.PluginShortCircuit, error)
PreHook records the start time of the request in the context. This time is used later in PostHook to calculate request duration.