Help us shape the future of Go! Take the 2026 Go Developer Survey

usagemetrics

package
v0.42.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package usagemetrics provides internal usage metrics for tracking usage and adoption.

Index

Constants

View Source
const (

	// EnvVarUsageMetricsEnabled is the environment variable to disable usage metrics
	EnvVarUsageMetricsEnabled = "TOOLHIVE_USAGE_METRICS_ENABLED"
)
View Source
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

func ShouldEnableMetrics(configDisabled bool) bool

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 NewClient

func NewClient(endpoint string) *Client

NewClient creates a new metrics client

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

func NewCollector() (*Collector, error)

NewCollector creates a new metrics collector

func (*Collector) Flush

func (c *Collector) Flush() error

Flush sends the current metrics to the API Checks for midnight boundary crossing and handles daily reset

func (*Collector) GetCurrentCount

func (c *Collector) GetCurrentCount() int64

GetCurrentCount returns the current count (for testing/debugging)

func (*Collector) IncrementToolCall

func (c *Collector) IncrementToolCall()

IncrementToolCall increments the tool call counter atomically

func (*Collector) Shutdown

func (c *Collector) Shutdown(ctx context.Context)

Shutdown performs final flush and stops background goroutines

func (*Collector) Start

func (c *Collector) Start()

Start begins the background goroutine for periodic flush If already started, this is a no-op to prevent goroutine leaks

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) Close

func (m *Middleware) Close() error

Close cleans up any resources

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

Jump to

Keyboard shortcuts

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