Skip to content

Commit

Permalink
add spell span
Browse files Browse the repository at this point in the history
  • Loading branch information
gurinderu committed Nov 30, 2023
1 parent ca911a7 commit d0b3dac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
14 changes: 3 additions & 11 deletions sorcerer/src/script_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Sorcerer {
}

#[instrument(level = tracing::Level::INFO, skip_all)]
pub async fn execute_script(&self, event: TriggerEvent) {
pub async fn execute_script(&self, event: TriggerEvent, span: Arc<Span>) {
let error: Result<(), JError> = try {
let worker_id = self.services.get_service_owner(
"",
Expand All @@ -114,19 +114,11 @@ impl Sorcerer {
m.observe_spell_cast();
}

let particle_span = Arc::new(Span::current());

let async_span = tracing::info_span!(parent: particle_span.as_ref(), "Script executor: aquamarine async execute");
let async_span = tracing::info_span!(parent: span.as_ref(), "Script executor: aquamarine async execute");

self.aquamarine
.clone()
.execute(
ExtendedParticle {
particle,
span: particle_span,
},
None,
)
.execute(ExtendedParticle { particle, span }, None)
.instrument(async_span)
.await?;
};
Expand Down
11 changes: 7 additions & 4 deletions sorcerer/src/sorcerer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;

use futures::{FutureExt, StreamExt};
Expand Down Expand Up @@ -143,17 +144,19 @@ impl Sorcerer {
let spell_events_stream = UnboundedReceiverStream::new(spell_events_receiver);
spell_events_stream
.for_each_concurrent(None, move |spell_event| {
let span = tracing::info_span!(
let root_span = tracing::info_span!(
"Sorcerer: spell processing",
spell_id = spell_event.spell_id.to_string()
);
let _ = span.enter();
let root_span = Arc::new(root_span);
let async_span = tracing::info_span!(parent: root_span.as_ref(), "Sorcerer: async execute script");

let sorcerer = self.clone();
// Note that the event that triggered the spell is in `spell_event.event`
async move {
sorcerer.execute_script(spell_event).await;
sorcerer.execute_script(spell_event,root_span).await;
}
.instrument(span)
.instrument(async_span)
})
.await;
})
Expand Down

0 comments on commit d0b3dac

Please sign in to comment.