vectordotdev/vector · error · syn::Error
component must have a name defined (e.g. `#[component_name("
Error message
component must have a name defined (e.g. `#[component_name("foobar")]`) What it means
The component-name derive/attribute machinery in vector-config-macros requires every instrumented component type to declare exactly one name via `#[component_name("...")]`. After validating any attribute tokens, if none produced a usable name, the macro emits this compile error on the type's span. Without the constant NAME the generated docs and config schema cannot identify the component.
Source
Thrown at lib/vector-config-macros/src/component_name.rs:73
errors.push(e);
None
}
})
.collect::<Vec<_>>();
if !errors.is_empty() {
let mut main_error = errors.remove(0);
for error in errors.drain(..) {
main_error.combine(error);
}
return main_error.into_compile_error().into();
}
// Any component names we have now have been validated, so we just need to check and make sure
// we actually have one, and only one, and spit out the correct errors otherwise.
if component_names.is_empty() {
return Error::new(
ident.span(),
"component must have a name defined (e.g. `#[component_name(\"foobar\")]`)",
)
.into_compile_error()
.into();
}
if component_names.len() > 1 {
return Error::new(ident.span(), "component cannot have multiple names defined")
.into_compile_error()
.into();
}
let component_name = component_names.remove(0);
// We have a single, valid component name, so let's actually spit out our derive.
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
let derived = quote! {View on GitHub (pinned to 3708c39b12)
Solutions
- Add exactly one `#[component_name("your_component")]` attribute to the type carrying the derive.
- Check spelling/placement — the attribute must sit on the same item the macro processes.
- Copy the attribute block from a sibling component in the same directory as a template.
Example fix
// before
#[derive(ComponentName)]
struct MySinkConfig;
// after
#[component_name("my_sink")]
#[derive(ComponentName)]
struct MySinkConfig; Defensive patterns
Strategy: validation
Validate before calling
// The compiler enforces this at derive time; fix by adding the attribute:
// #[component_name("my_component")]
// #[derive(...)] struct MyConfig; Prevention
- When adding a component, copy the full attribute set from a sibling component first, then rename.
- Keep the derive and its component_name attribute adjacent so they are edited together.
When it happens
Trigger: Applying the component-name derive (or the `#[configurable_component(...)]` family) to a type without attaching `#[component_name("my_component")]`, or with the attribute misspelled so it is not recognized.
Common situations: Contributors adding a new source/transform/sink who copy the derive list but drop the name attribute; typos like `#[component_names(...)]` or placing the attribute on the wrong item so it is not collected.
Related errors
- component cannot have multiple names defined
- {component_type}s must have a name specified (e.g. `{compone
- #[derive(NamedInternalEvent)] can only be used with structs
- expected a string literal for the {component_type} name (i.e
- component name must be non-empty
AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20).
Data as JSON: /api/errors/e2ce076aa3962342.
Report an issue: GitHub.