Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions crates/instrumentation-build/src/any_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ pub(crate) fn generate_any_event(
schema: &Schema,
opts: &Options,
) -> Result<TokenStream, GenerateError> {
let derives = derive_attr(opts.event_derives)?;

let variants: Vec<(Ident, Ident)> = schema
.entities()
.map(|entity| {
Expand All @@ -35,7 +33,11 @@ pub(crate) fn generate_any_event(
)
})
.collect();
if variants.is_empty() {
return Ok(quote! {});
}

let derives = derive_attr(opts.event_derives)?;
let decls = variants.iter().map(|(variant, event)| {
quote! { #variant(&'a ::quent_instrumentation::Event<#event>) }
});
Expand Down Expand Up @@ -118,4 +120,15 @@ mod tests {
pretty(expected)
);
}

#[test]
fn emits_nothing_without_entities() {
let schema = SchemaBuilder::new(ident("Demo")).build().unwrap();

assert!(
generate_any_event(&schema, &Options::default())
.unwrap()
.is_empty()
);
}
}
2 changes: 2 additions & 0 deletions crates/instrumentation-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub struct Options {

/// Emit `AnyEvent` and `AnyEvent::from_any`, a decoder from a type-erased
/// `&dyn Any` back to the concrete `Event<T>`. Carries [`Self::event_derives`].
///
/// No aggregate is emitted when the schema declares no events.
pub any_event: bool,
}

Expand Down
Loading