monitoring

package
v0.11.2-0...-3fb1738 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetricPrefix = "capabilities_v2"

	ActionCountMetric    = MetricPrefix + "_action_count"
	ActionDurationMetric = MetricPrefix + "_action_duration"

	OutcomeSuccess = "success"
	OutcomeError   = "error"

	LabelOutcome         = "outcome"
	LabelMethod          = "method"
	LabelChainFamilyName = "chain_family_name"
	LabelChainID         = "chain_id"
	LabelNetworkName     = "network_name"
	LabelNetworkNameFull = "network_name_full"
	LabelWorkflowDonID   = "workflow_don_id"
	LabelCapabilityType  = "capability_type"
	LabelCapabilityID    = "capability_id"
)

Variables

View Source
var ActionLatencyBucketBoundariesMs = []float64{
	0, 5, 10, 25, 50, 75, 100,
	250, 500, 750, 1000,
	2500, 5000, 7500, 10000,
	15000, 30000,
}

ActionLatencyBucketBoundariesMs matches read-action latency buckets.

Functions

func ActionMetricAttributes

func ActionMetricAttributes(method string, metadata capabilities.RequestMetadata, capAttrsFn func() []attribute.KeyValue, extra []attribute.KeyValue) []attribute.KeyValue

ActionMetricAttributes combines capability, request, and optional per-input metric labels.

func MetricViews

func MetricViews() []sdkmetric.View

MetricViews returns OTel views for v2 capability action metrics. Register via loop.WithOtelViews before the Beholder client creates instruments.

func RequestID

func RequestID(workflowExecutionID, reference string) string

RequestID combines workflow execution ID and reference ID for log correlation.

func RequestLogKVs

func RequestLogKVs(metadata capabilities.RequestMetadata) []any

RequestLogKVs returns per-request structured log fields added by generated server code.

func ValOrUnknown

func ValOrUnknown(val string) string

ValOrUnknown returns the value if it is not empty, otherwise it returns "unknown". This avoids issues during exporting OTel metrics to Prometheus.

Types

type ActionMetrics

type ActionMetrics interface {
	OnSuccess(ctx context.Context, method string, tsStart, tsEmit time.Time, attrs ...attribute.KeyValue)
	OnError(ctx context.Context, method string, tsStart, tsEmit time.Time, isUserError bool, attrs ...attribute.KeyValue)
}

ActionMetrics records OTel metrics for v2 capability action lifecycle events. Instruments are exported via Beholder OTLP and appear in Prometheus after collector ingestion.

func NewActionMetrics

func NewActionMetrics() ActionMetrics

NewActionMetrics creates OTel metrics for v2 capability action outcomes.

func NoopActionMetrics

func NoopActionMetrics() ActionMetrics

NoopActionMetrics is a no-op ActionMetrics implementation for tests.

type MonitoringContext

type MonitoringContext struct {
	Logger logger.Logger
	// MetricsAttributes returns capability-scoped low-cardinality OTel labels such as
	// chain_id, network_name, and capability_id. Generated server code adds method
	// and per-request labels from RequestMetadata.
	MetricsAttributes func() []attribute.KeyValue
}

MonitoringContext carries per-capability monitoring inputs provided by the capability at runtime via MonitoringContext() on the generated ClientCapability interface. Action OTel metrics are owned by the generated server wrapper.

type MonitoringLabels

type MonitoringLabels interface {
	LogKVs() []any
	MetricKVs() []attribute.KeyValue
}

MonitoringLabels is an optional interface that request proto types may implement to contribute method-specific fields to structured logs and metrics emitted by the generated server (--with-monitoring). Returning nil or an empty slice is valid.

LogKVs are appended to lifecycle log lines (initiated / succeeded / failed). High-cardinality values (addresses, IDs, etc.) belong here.

MetricKVs are appended to ActionMetrics lifecycle events as OTel attributes. Keep MetricKVs low-cardinality to avoid overloading metrics storage.

Example (in chainlink-common, package solana):

func (r *WriteReportRequest) LogKVs() []any {
    return []any{"receiver", hex.EncodeToString(r.GetReceiver())}
}

func (r *WriteReportRequest) MetricKVs() []attribute.KeyValue {
    return nil
}

The generated server checks any(input).(monitoring.MonitoringLabels) at call time; if the request type does not implement it, monitoring still works — log lines just carry the method name and request metadata fields.

Jump to

Keyboard shortcuts

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