Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement span and propagation APIs #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ If you would like to contribute code you can do so through GitHub by forking the

## License

By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/opentracing/opentracing-java/blob/master/LICENSE
By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/opentracing/opentracing-rust/blob/master/LICENSE

All files are released with the Apache 2.0 license.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "opentracing"
version = "0.1.0"
authors = ["Isaac Hier"]
license = "Apache-2.0"
description = "OpenTracing API for Rust"
readme = "README.md"
documentation = "http://opentracing.io/documentation"
homepage = "http://opentracing.io"
repository = "https://github.com/opentracing/opentracing-rust"
keywords = ["distributed", "tracing"]
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! OpenTracing

#![crate_type = "lib"]
#![crate_name = "opentracing"]
4 changes: 4 additions & 0 deletions src/log/field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub struct Field<'a> {
&'a str key;
&'a util::Value value;
}
18 changes: 18 additions & 0 deletions src/propagation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub enum PropagationError {
UnsupportedFormat,
SpanContextNotFound,
InvalidSpanContext,
InvalidCarrier,
SpanContextCorrupted
}

pub type PropagationOption = Option<PropagationError>;

pub trait TextMapReader {
fn foreach_key(&self, f: &Fn(&str, &str) -> PropagationOption)
-> PropagationOption;
}

pub trait TextMapWriter {
fn set(&mut self, key: &str, value: &str);
}
33 changes: 33 additions & 0 deletions src/span.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::time::Instant;

pub trait SpanContext {
fn foreach_baggage_item(&self, f: &Fn(&str, &str) -> bool);
}

pub struct LogRecord {
Instant timestamp;
Vec<log::Field> fields;
}

pub struct FinishSpanOptions {
Instant finish_time;
Vec<LogRecord> log_records;
}

pub trait Span {
fn finish(&mut self);

fn finish_with_options(&mut self, &FinishSpanOptions options);

fn set_operation_name(&mut self, &str operation_name);

fn set_tag(&mut self, &str key, &util::Value value);

fn log_fields(&mut self, &Vec<log::Field> fields);

fn set_baggage_item(&mut self, &str restricted_key, &str value);

fn baggage_item(&self, &str restricted_key) -> str;

fn tracer(&self) -> &Tracer;
}
1 change: 1 addition & 0 deletions src/tracer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub trait Tracer {}
11 changes: 11 additions & 0 deletions src/util/value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub enum Value<'a> {
Str (&'a str),
Bool (bool),
I32 (i32),
U32 (u32),
I64 (i64),
U64 (u64),
F32 (f32),
F64 (f64),
NoOp
}