diff --git a/opentracing-api/src/lib.rs b/opentracing-api/src/lib.rs index ac6ec50..4e3a842 100644 --- a/opentracing-api/src/lib.rs +++ b/opentracing-api/src/lib.rs @@ -3,7 +3,9 @@ mod context; mod tag; mod field; +mod span; pub use context::SpanContext; -pub use tag::{ParseTagsError, Tags}; +pub use tag::{ParseTagsError, TagValue, Tags}; pub use field::{Fields, ParseFieldsError}; +pub use span::Span; diff --git a/opentracing-api/src/span.rs b/opentracing-api/src/span.rs new file mode 100644 index 0000000..0570501 --- /dev/null +++ b/opentracing-api/src/span.rs @@ -0,0 +1,51 @@ +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) -> &'a Self::Context; + + /// Sets a key:value tag on the `Span`. + fn set_tag(&mut self, key: &str, value: 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 get_baggage_item(&self, key: &str) -> Option<&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 get_operation_name(&self) -> Option<&'a str>; + + /// Sets the end timestamp to now and finishes (records) the span. + /// + /// With the exception of calls to `context()`, this should be the last + /// call made to the span instance. Future calls to `finish` are defined + /// as noops, and future calls to other methods other than `context()` + /// lead to undefined behavior. + fn finish(&mut self); + + /// Sets an explicit end timestamp and finishes (records) the span. + /// + /// With the exception of calls to `context()`, this should be the last + /// call made to the span instance. Future calls to `finish` are defined + /// as noops, and future calls to other methods other than `context()` + /// lead to undefined behavior. + fn finish_at(&mut self, timestamp: u64); +} diff --git a/opentracing-api/src/tag.rs b/opentracing-api/src/tag.rs index 9f3123d..faaee88 100644 --- a/opentracing-api/src/tag.rs +++ b/opentracing-api/src/tag.rs @@ -171,6 +171,12 @@ impl fmt::Display for ParseTagsError { } } +pub enum TagValue { + String(String), + Boolean(bool), + Number(f64), +} + #[cfg(test)] mod tests {