{"record":{"id":"784cae47a42ed7f4","repo":"grafana/k6","slug":"trend-stats-resolver-is-empty","errorCode":null,"errorMessage":"trend stats resolver is empty","messagePattern":"trend stats resolver is empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/output/prometheusrw/remotewrite/trend.go","lineNumber":26,"sourceCode":"\n\tprompb \"buf.build/gen/go/prometheus/prometheus/protocolbuffers/go\"\n\t\"github.com/prometheus/client_golang/prometheus\"\n\tdto \"github.com/prometheus/client_model/go\"\n\t\"go.k6.io/k6/v2/metrics\"\n)\n\n// TrendStatsResolver is a map of trend stats name and their relative resolver function\ntype TrendStatsResolver map[string]func(*metrics.TrendSink) float64\n\ntype extendedTrendSink struct {\n\t*metrics.TrendSink\n\n\ttrendStats map[string]func(*metrics.TrendSink) float64\n}\n\nfunc newExtendedTrendSink(tsr TrendStatsResolver) (*extendedTrendSink, error) {\n\tif len(tsr) < 1 {\n\t\treturn nil, fmt.Errorf(\"trend stats resolver is empty\")\n\t}\n\treturn &extendedTrendSink{\n\t\tTrendSink:  metrics.NewTrendSink(),\n\t\ttrendStats: tsr,\n\t}, nil\n}\n\n// MapPrompb converts a k6 time series and its relative\n// Sink into the equivalent TimeSeries model as defined from\n// the Remote write specification.\nfunc (sink *extendedTrendSink) MapPrompb(series metrics.TimeSeries, t time.Time) []*prompb.TimeSeries {\n\t// Prometheus metric system does not support Trend so this mapping will\n\t// store a counter for the number of reported values and gauges to keep\n\t// track of aggregated values. Also store a sum of the values to allow\n\t// the calculation of moving averages.\n\t// TODO: when Prometheus implements support for sparse histograms, re-visit this implementation\n\n\ttg := &trendAsGauges{","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/output/prometheusrw/remotewrite/trend.go#L8-L44","documentation":"newExtendedTrendSink is a guard that refuses to build an extended trend sink when the supplied TrendStatsResolver map is empty — no trend-stat resolver functions were provided, so trend values cannot be computed.","triggerScenarios":"Thrown at internal/output/prometheusrw/remotewrite/trend.go:26 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide at least one trend stat resolver entry when constructing the sink","Check K6_PROMETHEUS_RW_TREND_STATS or native-histogram configuration isn't leaving stats empty"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}