Skip to content

Commit

Permalink
Added macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Modularius committed Aug 23, 2024
1 parent d9869af commit 617ad87
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions common/src/tracer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,50 @@ macro_rules! init_tracer {
tracer
}};
}

/// Should be called to populate the metadata fields of a given span
/// # Arguments
/// - metadata: supermusr_streaming_types::frame_metadata::FrameMetadata
/// - span: Span
///
/// # Prerequisites
/// The span should have been created with appropriate empty fields, either by
/// ```ignore
/// fields(
/// //...
/// metadata_timestamp = tracing::field::Empty,
/// metadata_frame_number = tracing::field::Empty,
/// metadata_period_number = tracing::field::Empty,
/// metadata_veto_flags = tracing::field::Empty,
/// metadata_protons_per_pulse = tracing::field::Empty,
/// metadata_running = tracing::field::Empty,
/// //...
/// )
/// ```
/// if using the #[instrument] macro over a function, or with
/// ```ignore
/// "metadata_timestamp" = tracing::field::Empty,
/// "metadata_frame_number" = tracing::field::Empty,
/// "metadata_period_number" = tracing::field::Empty,
/// "metadata_veto_flags" = tracing::field::Empty,
/// "metadata_protons_per_pulse" = tracing::field::Empty,
/// "metadata_running" = tracing::field::Empty,
/// ```
/// if creating the span directly using `info_span!()` or similar.
#[macro_export]
macro_rules! record_metadata_fields_to_span {
($metadata:expr, $span:expr) => {
$span.record(
"metadata_timestamp",
$metadata
.timestamp
.format(supermusr_common::TIMESTAMP_FORMAT)
.to_string(),
);
$span.record("metadata_frame_number", $metadata.frame_number);
$span.record("metadata_period_number", $metadata.period_number);
$span.record("metadata_veto_flags", $metadata.veto_flags);
$span.record("metadata_protons_per_pulse", $metadata.protons_per_pulse);
$span.record("metadata_running", $metadata.running);
};
}

0 comments on commit 617ad87

Please sign in to comment.