-
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.
still todo: - add LogValue - figure out span referencing question - fix all issues with the span trait - add docs to everything once done - complete noop impl - complete mock impl
- Loading branch information
Showing
6 changed files
with
385 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
#![doc(html_root_url = "https://docs.rs/opentracing-api/0.1.0")] | ||
|
||
mod context; | ||
mod tag; | ||
mod field; | ||
mod reference; | ||
mod span; | ||
mod tag; | ||
|
||
pub use context::SpanContext; | ||
pub use tag::{ParseTagsError, Tags}; | ||
pub use field::{Fields, ParseFieldsError}; | ||
pub use reference::{ParseReferencesError, References}; | ||
pub use span::{FinishedSpan, Span}; | ||
pub use tag::{ParseTagsError, TagValue, Tags}; |
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,70 @@ | ||
use std::fmt; | ||
use std::error::Error; | ||
use std::str::FromStr; | ||
|
||
const REF_CHILD_OF: &str = "child_of"; | ||
const REF_FOLLOWS_FROM: &str = "follows_from"; | ||
|
||
/// References provide a namespace for official OpenTracing reference types. | ||
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] | ||
pub enum References { | ||
/// See http://opentracing.io/spec/#causal-span-references for | ||
/// more information about ChildOf references. | ||
ChildOf, | ||
/// See http://opentracing.io/spec/#causal-span-references for | ||
/// more information about FollowsFrom references. | ||
FollowsFrom, | ||
} | ||
|
||
impl References { | ||
/// Returns the string representation for the enum reference variant. | ||
pub fn as_str(&self) -> &'static str { | ||
match *self { | ||
References::ChildOf => REF_CHILD_OF, | ||
References::FollowsFrom => REF_FOLLOWS_FROM, | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for References { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.as_str()) | ||
} | ||
} | ||
|
||
impl FromStr for References { | ||
type Err = ParseReferencesError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
REF_CHILD_OF => Ok(References::ChildOf), | ||
REF_FOLLOWS_FROM => Ok(References::FollowsFrom), | ||
_ => Err(ParseReferencesError::UnknownReference), | ||
} | ||
} | ||
} | ||
|
||
/// Describes errors which can happen while parsing into the `References` enum. | ||
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] | ||
pub enum ParseReferencesError { | ||
/// The provided reference is not known. | ||
UnknownReference, | ||
} | ||
|
||
impl Error for ParseReferencesError { | ||
fn description(&self) -> &str { | ||
match *self { | ||
ParseReferencesError::UnknownReference => "Unknown Reference", | ||
} | ||
} | ||
|
||
fn cause(&self) -> Option<&Error> { | ||
None | ||
} | ||
} | ||
|
||
impl fmt::Display for ParseReferencesError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.description()) | ||
} | ||
} |
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,81 @@ | ||
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<S>(&mut self, key: S, value: TagValue) | ||
where | ||
S: Into<String>; | ||
|
||
/// Allows to unset a tag based on the given key. Noop if | ||
/// it doesn't exist. | ||
fn unset_tag<S>(&mut self, key: S) | ||
where | ||
S: Into<String>; | ||
|
||
/// Returns a tag value if set, none otherwise | ||
fn tag<S>(&self, key: S) -> Option<&TagValue> | ||
where | ||
S: Into<String>; | ||
|
||
/// 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<S>(&mut self, key: S, value: String) | ||
where | ||
S: Into<String>; | ||
|
||
/// Allows to unset a baggage item based on the given key. Noop if | ||
/// it doesn't exist. | ||
fn unset_baggage_item<S>(&mut self, key: S) | ||
where | ||
S: Into<String>; | ||
|
||
/// the value of the baggage item identified by the given key, or None if no such item | ||
/// could be found. | ||
fn baggage_item<S>(&self, key: S) -> Option<&String> | ||
where | ||
S: Into<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<&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
Oops, something went wrong.