Skip to content

Commit

Permalink
create links of child spans
Browse files Browse the repository at this point in the history
  • Loading branch information
eaypek-tfh committed Sep 28, 2024
1 parent 6343b0f commit 6f99bd2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
18 changes: 14 additions & 4 deletions iris-mpc-common/src/helpers/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
use opentelemetry::trace::{SpanContext, SpanId, TraceFlags, TraceId, TraceState};
use opentelemetry::{
global,
trace::{Span, SpanContext, SpanId, TraceContextExt, TraceFlags, TraceId, TraceState, Tracer},
Context,
};

pub fn trace_from_message_attributes(trace_id: &str, span_id: &str) -> eyre::Result<SpanContext> {
tracing::info!(
"Creating span context from message attributes. trace id: {}, span id: {}",
trace_id,
span_id
);

// Create and set the span parent context
let parent_ctx = SpanContext::new(
let parent_span_ctx = SpanContext::new(
TraceId::from(trace_id.parse::<u128>()?),
SpanId::from(span_id.parse::<u64>()?),
TraceFlags::default(),
true,
TraceState::default(),
);

Ok(parent_ctx)
let parent_ctx = Context::new().with_remote_span_context(parent_span_ctx);
let tracer = global::tracer("mpcv2-batch-tracer");
let mut span = tracer
.span_builder("mpcv2-batch-item")
.start_with_context(&tracer, &parent_ctx);
span.add_event("Created batch span item", vec![]);
Ok(span.span_context().clone())
}
14 changes: 10 additions & 4 deletions iris-mpc/src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,17 +914,21 @@ async fn server_main(config: Config) -> eyre::Result<()> {
let links: Vec<Link> = batch
.span_contexts
.iter()
.map(|span| Link::new(span.clone(), Vec::new()))
.map(|span_ctx| Link::new(span_ctx.clone(), Vec::new()))
.collect();

tracing::info!(
"Created span links for batch processing of length {}",
links.len()
);

let batch_span = tracer
.span_builder("batch_processing")
.with_links(links)
.start(&tracer);

let otel_context = OtelContext::current_with_span(batch_span);
let tracing_span = tracing::span!(tracing::Level::INFO, "batch_processing");
tracing_span.set_parent(otel_context);
tracing::Span::current().set_parent(otel_context);

process_identity_deletions(
&batch,
Expand All @@ -940,7 +944,9 @@ async fn server_main(config: Config) -> eyre::Result<()> {
tracing::info!("Received batch in {:?}", now.elapsed());
background_tasks.check_tasks();

let result_future = handle.submit_batch_query(batch).instrument(tracing_span);
let result_future = handle
.submit_batch_query(batch)
.instrument(tracing::Span::current());

next_batch = receive_batch(
party_id,
Expand Down

0 comments on commit 6f99bd2

Please sign in to comment.