Documentation
¶
Index ¶
- Constants
- Variables
- func ActionMetricAttributes(method string, metadata capabilities.RequestMetadata, ...) []attribute.KeyValue
- func MetricViews() []sdkmetric.View
- func RequestID(workflowExecutionID, reference string) string
- func RequestLogKVs(metadata capabilities.RequestMetadata) []any
- func ValOrUnknown(val string) string
- type ActionMetrics
- type MonitoringContext
- type MonitoringLabels
Constants ¶
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 ¶
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 ¶
MetricViews returns OTel views for v2 capability action metrics. Register via loop.WithOtelViews before the Beholder client creates instruments.
func RequestLogKVs ¶
func RequestLogKVs(metadata capabilities.RequestMetadata) []any
RequestLogKVs returns per-request structured log fields added by generated server code.
func ValOrUnknown ¶
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 ¶
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.