Documentation
¶
Overview ¶
Package metrics provides shared histogram bucket presets and label-key constants for OpenTelemetry metrics across the ToolHive ecosystem.
This package provides construction helpers only. Importing it registers no instruments and emits no metrics; consumers (the ToolHive proxy, vMCP, and the registry) use it to build their own instruments consistently.
Bucket Presets ¶
Three histogram bucket presets cover fast HTTP calls, MCP/proxy operations, and long-running operations such as sync, reconcile, or composite-tool execution. This package does not construct meters or instruments; callers import go.opentelemetry.io/otel and go.opentelemetry.io/otel/metric themselves and pass a preset's boundaries when constructing a histogram:
meter := otel.Meter("stacklok.toolhive.proxy")
histogram, err := meter.Float64Histogram(
"stacklok.toolhive.proxy.request.duration",
metric.WithExplicitBucketBoundaries(metrics.BucketsFastHTTP()...),
)
Label Keys ¶
Canonical label-key constants ensure every consumer spells the same concept the same way. As with the bucket presets, callers attach these to their own OTel instruments via go.opentelemetry.io/otel/attribute:
counter.Add(ctx, 1, metric.WithAttributes(
attribute.String(metrics.LabelOutcome, "success"),
))
This package exports only canonical common keys: concepts more than one component emits and that a cross-component dashboard joins or groups on. Component-local keys used by a single emitter are not exported here; they are defined by that component.
Stability ¶
This package is Alpha stability. The API may change without notice. See the toolhive-core README for stability level definitions.
Index ¶
Constants ¶
const ( // LabelMCPServer identifies the upstream MCP server. LabelMCPServer = "mcp_server" // LabelOutcome carries the result of an operation. Its value is one of // "success", "error", or "rejected". LabelOutcome = "outcome" // LabelMCPMethod identifies the MCP method invoked. LabelMCPMethod = "mcp_method" // LabelToolName identifies the tool invoked. LabelToolName = "tool_name" // LabelCompositeTool identifies a vMCP composite tool. LabelCompositeTool = "composite_tool" // LabelTransport identifies the transport used (e.g. stdio, sse, http). LabelTransport = "transport" // LabelErrorType carries the failure classification on a Stacklok-authored // metric (coexists with semconv error.type on OTel semconv metrics). LabelErrorType = "error_type" )
Canonical label-key constants for Stacklok-authored metrics (RFC §3.3 label dictionary). One key per concept, snake_case, no boolean-typed keys.
This set is scoped to canonical common keys only: concepts more than one component emits and that a cross-component dashboard joins or groups on. Component-local keys used by only one emitter (e.g. operator reconcile's "phase", the circuit breaker's "from"/"to", the registry's "source") are defined by the emitting component, not exported here.
Variables ¶
This section is empty.
Functions ¶
func BucketsFastHTTP ¶
func BucketsFastHTTP() []float64
BucketsFastHTTP returns the histogram bucket boundaries, in seconds, for fast HTTP-class measurements (RFC §3.3: 0.005-10).
func BucketsLongRunning ¶
func BucketsLongRunning() []float64
BucketsLongRunning returns the histogram bucket boundaries, in seconds, for long-running measurements such as sync, reconcile, or composite-tool durations (RFC §3.3: 0.1-300).
func BucketsMCPProxy ¶
func BucketsMCPProxy() []float64
BucketsMCPProxy returns the histogram bucket boundaries, in seconds, for MCP/proxy operation measurements (RFC §3.3: 0.01-300).
Types ¶
This section is empty.