telemetry

package module
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: Apache-2.0 Imports: 12 Imported by: 2

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

View Source
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

PostHook calculates duration and records upstream metrics for successful requests. It records:

  • Request latency
  • Total request count

func (*PrometheusPlugin) PreHook

PreHook records the start time of the request in the context. This time is used later in PostHook to calculate request duration.

Jump to

Keyboard shortcuts

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