vectordotdev/vector · error
argument must be a string
Error message
argument must be a string
What it means
get_vector_metric's helper starts with key.as_str().expect("argument must be a string") (lib/vector-vrl/metrics/src/get_vector_metric.rs). Its key parameter is defined as Parameter::required("key", kind::BYTES, ...), so VRL's compiler enforces bytes at the call site; the expect is a runtime assertion of that compile-time contract and signals an internal invariant violation if it ever fires.
Source
Thrown at lib/vector-vrl/metrics/src/get_vector_metric.rs:15
use std::{collections::BTreeMap, sync::LazyLock};
use vector_vrl_category::Category;
use vrl::prelude::{expression::Expr, *};
use crate::common::{
metric_into_vrl, metrics_vrl_typedef, resolve_tags, validate_tags, Error, MetricsStorage,
};
fn get_metric(
metrics_storage: &MetricsStorage,
key: Value,
tags: BTreeMap<String, String>,
) -> Result<Value, ExpressionError> {
let key_str = key.as_str().expect("argument must be a string");
let value = match metrics_storage.get_metric(&key_str, tags) {
Some(value) => metric_into_vrl(&value),
None => Value::Null,
};
Ok(value)
}
static DEFAULT_TAGS: LazyLock<Value> = LazyLock::new(|| Value::Object(BTreeMap::new()));
static PARAMETERS: LazyLock<Vec<Parameter>> = LazyLock::new(|| {
vec![
Parameter::required("key", kind::BYTES, "The metric name to search."),
Parameter::optional(
"tags",
kind::OBJECT,
"Tags to filter the results on. Values in this object support wildcards ('*') to match on parts of the tag value.",
)
.default(&DEFAULT_TAGS),View on GitHub (pinned to 3708c39b12)
Solutions
- Upgrade Vector/vector-vrl crates in lockstep
- Pass statically-typed strings: get_vector_metric("buffer_byte_size", tags = {...})
- Use the compiled Program API for embedding
- Report reproducible stock-build panics to vectordot/vector
Example fix
# before (vrl) get_vector_metric(key) # key: any # after (vrl) get_vector_metric(to_string!(key))
Defensive patterns
Strategy: type-guard
Validate before calling
# Literal or coerced metric key get_vector_metric(to_string!(key))
Type guard
fn is_bytes(v: &vrl::value::Value) -> bool {
matches!(v, vrl::value::Value::Bytes(_))
} Prevention
- Quote metric keys as string literals
- Compile-check remap transforms referencing metrics functions
- Keep VRL crates on one release
When it happens
Trigger: Executing get_vector_metric with a runtime key Value that is not bytes/string — prevented by compilation in normal flows (get_vector_metric(true) fails to compile); occurs only with VRL compiler bugs, version-mismatched vector-vrl crates, or direct helper use outside the compile pipeline.
Common situations: Embedding VRL without the type-checking pass; dependency skew between vector-vrl-metrics and the compiler; compiler regression testing.
Related errors
- argument must be a string
- argument must be a string
- argument must be a string
- argument must be a string
- key must be a string
AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20).
Data as JSON: /api/errors/6a69c65f13e8012e.
Report an issue: GitHub.