Merge pull request #3503 from influxdata/crepererum/span_linking

feat: simplify linking of spans
pull/24376/head
kodiakhq[bot] 2022-01-21 09:33:49 +00:00 committed by GitHub
commit 898e8e76bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -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)]
@ -126,7 +131,7 @@ pub struct SpanRecorder {
span: Option<Span>,
}
impl<'a> SpanRecorder {
impl SpanRecorder {
pub fn new(mut span: Option<Span>) -> Self {
if let Some(span) = span.as_mut() {
span.start = Some(Utc::now());
@ -177,9 +182,16 @@ impl<'a> 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<'a> Drop for SpanRecorder {
impl Drop for SpanRecorder {
fn drop(&mut self) {
if let Some(mut span) = self.span.take() {
let now = Utc::now();