Documentation
¶
Overview ¶
Package usagemetrics provides internal usage metrics for tracking usage and adoption.
Index ¶
Constants ¶
const (
// EnvVarUsageMetricsEnabled is the environment variable to disable usage metrics
EnvVarUsageMetricsEnabled = "TOOLHIVE_USAGE_METRICS_ENABLED"
)
const (
// MiddlewareType is the type identifier for usage metrics middleware
MiddlewareType = "usagemetrics"
)
Variables ¶
This section is empty.
Functions ¶
func CreateMiddleware ¶
func CreateMiddleware(config *types.MiddlewareConfig, runner types.MiddlewareRunner) error
CreateMiddleware is the factory function for creating usage metrics middleware
func ShouldEnableMetrics ¶
ShouldEnableMetrics returns true if metrics collection should be enabled Checks: CI detection > Config disable > Environment variable > Default (true) If either config or env var explicitly disables metrics, they stay disabled
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends usage metrics to the API
func (*Client) SendMetrics ¶
func (c *Client) SendMetrics(instanceID string, record MetricRecord) error
SendMetrics sends the metrics record to the API
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector manages tool call counting and reporting
func NewCollector ¶
NewCollector creates a new metrics collector
func (*Collector) Flush ¶
Flush sends the current metrics to the API Checks for midnight boundary crossing and handles daily reset
func (*Collector) GetCurrentCount ¶
GetCurrentCount returns the current count (for testing/debugging)
func (*Collector) IncrementToolCall ¶
func (c *Collector) IncrementToolCall()
IncrementToolCall increments the tool call counter atomically
type MetricRecord ¶
type MetricRecord struct {
Count int64 `json:"count"`
Timestamp string `json:"timestamp"` // ISO 8601 format in UTC (e.g., "2025-01-01T23:50:00Z")
}
MetricRecord is the payload sent to the metrics API
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware implements the types.Middleware interface
func (*Middleware) Handler ¶
func (m *Middleware) Handler() types.MiddlewareFunction
Handler returns the middleware function
type MiddlewareParams ¶
type MiddlewareParams struct {
}
MiddlewareParams represents the parameters for usage metrics middleware