feat: simplify linking of spans
Linking of span contexts was introduced in but the high-level
interface was never used. This adds the missing bits to allow links to
be used with `Span` and `SpanRecorder`.
@@ -72,6 +72,11 @@ impl Span {
pub fn child(&self, name: impl Into<Cow<'static, str>>) -> Self {
self.ctx.child(name)
}
+
+ /// Link this span to another context.
+ pub fn link(&mut self, other: &SpanContext) {
+ self.ctx.links.push((other.trace_id, other.span_id));
+ }
}
#[derive(Debug, Clone)]
@@ -177,6 +182,13 @@ impl SpanRecorder {
pub fn span(&self) -> Option<&Span> {
self.span.as_ref()
}
+
+ /// Link this span to another context.
+ pub fn link(&mut self, other: &SpanContext) {
+ if let Some(span) = self.span.as_mut() {
+ span.link(other);
+ }
+ }
}
impl Drop for SpanRecorder {
