-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use SpanContext; | ||
use TagValue; | ||
|
||
/// The `Span` represents the OpenTracing specification's Span contract. | ||
pub trait Span<'a> { | ||
/// The associated `SpanContext`. | ||
type Context: SpanContext<'a>; | ||
|
||
/// Retrieve the associated `SpanContext`. | ||
/// | ||
/// This may be called any time, including after `finish`. | ||
fn context(&self) -> &Self::Context; | ||
|
||
/// Sets a key:value tag on the `Span`. | ||
fn set_tag(&mut self, key: &str, value: TagValue); | ||
|
||
/// Returns a tag value if set, none otherwise | ||
fn tag(&self, key: &str) -> Option<&'a TagValue>; | ||
|
||
/// Record an event at the current walltime timestamp. | ||
fn log(&mut self, event: String); | ||
|
||
/// Record an event at the given walltime timestamp. | ||
fn log_at(&mut self, timestamp: u64, event: String); | ||
|
||
/// Sets a baggage item in the Span (and its SpanContext) as a key/value pair. | ||
fn set_baggage_item(&mut self, key: &str, value: String); | ||
|
||
/// the value of the baggage item identified by the given key, or None if no such item | ||
/// could be found. | ||
fn baggage_item(&self, key: &str) -> Option<&'a String>; | ||
|
||
/// Sets the string name for the logical operation this span represents. | ||
fn set_operation_name(&mut self, name: &str); | ||
|
||
/// Returns the operation name if set, None otherwise. | ||
fn operation_name(&self) -> Option<&'a str>; | ||
|
||
/// Sets the end timestamp to now and finishes (records) the span. | ||
fn finish(self) -> FinishedSpan<Self::Context>; | ||
|
||
/// Sets an explicit end timestamp and finishes (records) the span. | ||
fn finish_at(self, timestamp: u64) -> FinishedSpan<Self::Context>; | ||
} | ||
|
||
pub struct FinishedSpan<C> { | ||
context: C, | ||
} | ||
|
||
impl<'a, C> FinishedSpan<C> | ||
where | ||
C: SpanContext<'a>, | ||
{ | ||
pub fn new(context: C) -> Self { | ||
FinishedSpan { context } | ||
} | ||
|
||
pub fn context(&self) -> &C { | ||
&self.context | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters