Skip to content

Commit

Permalink
Merge pull request #27 from palantir/global-tracer
Browse files Browse the repository at this point in the history
Make the tracer a global resource
  • Loading branch information
sfackler authored Nov 8, 2019
2 parents aeb30df + fb13c75 commit 81a15bb
Show file tree
Hide file tree
Showing 24 changed files with 538 additions and 666 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ version: 2
jobs:
build:
docker:
- image: rust:1.32.0
- image: rust:1.39.0
environment:
RUSTFLAGS: -D warnings
steps:
- checkout
- run: rustup component add rustfmt clippy
- *RESTORE_REGISTRY
- run: cargo generate-lockfile
- *SAVE_REGISTRY
- run: rustc --version > ~/rust-version
- *RESTORE_DEPS
- run: cargo fmt --all -- --check
- run: cargo clippy --all --all-targets
- run: cargo test --all
- run: cargo test --all --all-features
- *SAVE_DEPS
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace]
members = [
"futures-zipkin",
"http-zipkin",
"zipkin",
"zipkin-types",
Expand Down
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ schema.
The zipkin crate defines a `Tracer` object which handles the heavy lifting of
creating and recording Zipkin spans.

## futures-zipkin

[Documentation](https://docs.rs/futures-zipkin)

The futures-zipkin crate provides an adaptor type which bridges the thread-based
`Tracer` and the nonblocking `futures` world. It ensures that a `TraceContext`
is registered while the inner `Future`, `Stream`, or `Sink` is running.

## http-zipkin

[Documentation](https://docs.rs/http-zipkin)
Expand Down
14 changes: 0 additions & 14 deletions futures-zipkin/Cargo.toml

This file was deleted.

116 changes: 0 additions & 116 deletions futures-zipkin/src/lib.rs

This file was deleted.

5 changes: 3 additions & 2 deletions http-zipkin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "http-zipkin"
version = "0.1.1"
version = "0.2.0"
authors = ["Steven Fackler <sfackler@palantir.com>"]
edition = "2018"
license = "Apache-2.0"
description = "HTTP header propagation for Zipkin trace information."
repository = "https://github.com/palantir/rust-zipkin"
Expand All @@ -11,4 +12,4 @@ keywords = ["zipkin", "tracing"]

[dependencies]
http = "0.1"
zipkin = "0.3"
zipkin = { version = "0.4", path = "../zipkin" }
17 changes: 7 additions & 10 deletions http-zipkin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,20 @@
// limitations under the License.

//! HTTP header propagation for Zipkin trace information.
#![doc(html_root_url = "https://docs.rs/http-zipkin/0.1")]
#![doc(html_root_url = "https://docs.rs/http-zipkin/0.2")]
#![warn(missing_docs)]

extern crate http;
extern crate zipkin;

use http::header::{HeaderMap, HeaderValue};
use std::fmt::Write;
use std::str::FromStr;
use zipkin::{SamplingFlags, TraceContext};

const X_B3_SAMPLED: &'static str = "X-B3-Sampled";
const X_B3_FLAGS: &'static str = "X-B3-Flags";
const X_B3_TRACEID: &'static str = "X-B3-TraceId";
const X_B3_PARENTSPANID: &'static str = "X-B3-ParentSpanId";
const X_B3_SPANID: &'static str = "X-B3-SpanId";
const B3: &'static str = "b3";
const X_B3_SAMPLED: &str = "X-B3-Sampled";
const X_B3_FLAGS: &str = "X-B3-Flags";
const X_B3_TRACEID: &str = "X-B3-TraceId";
const X_B3_PARENTSPANID: &str = "X-B3-ParentSpanId";
const X_B3_SPANID: &str = "X-B3-SpanId";
const B3: &str = "b3";

/// Serializes sampling flags into the `b3` HTTP header.
///
Expand Down
1 change: 1 addition & 0 deletions zipkin-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "zipkin-types"
version = "0.1.0"
authors = ["Steven Fackler <sfackler@palantir.com>"]
edition = "2018"
license = "Apache-2.0"
description = "Type definitions for Zipkin distributed trace information"
repository = "https://github.com/palantir/rust-zipkin"
Expand Down
4 changes: 2 additions & 2 deletions zipkin-types/src/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use std::time::SystemTime;
/// Zipkin v1 core annotations such as "cs" and "sr" have been replaced with
/// `Span::kind`, which interprets timestamp and duration.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct Annotation {
#[cfg_attr(feature = "serde", serde(with = "::time_micros"))]
#[cfg_attr(feature = "serde", serde(with = "crate::time_micros"))]
timestamp: SystemTime,
value: String,
}
Expand Down
2 changes: 1 addition & 1 deletion zipkin-types/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};

/// The network context of a node in the service graph.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct Endpoint {
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
Expand Down
22 changes: 10 additions & 12 deletions zipkin-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,17 @@
//! [specification]: https://github.com/openzipkin/zipkin-api/blob/master/zipkin2-api.yaml
#![doc(html_root_url = "https://docs.rs/zipkin-types/0.1")]
#![warn(missing_docs)]
extern crate data_encoding;

#[cfg(feature = "serde")]
#[macro_use]
extern crate serde;

#[doc(inline)]
pub use annotation::Annotation;
pub use crate::annotation::Annotation;
#[doc(inline)]
pub use endpoint::Endpoint;
pub use crate::endpoint::Endpoint;
#[doc(inline)]
pub use span::{Kind, Span};
pub use crate::span::{Kind, Span};
#[doc(inline)]
pub use span_id::SpanId;
pub use crate::span_id::SpanId;
#[doc(inline)]
pub use trace_id::TraceId;
pub use crate::trace_id::TraceId;

pub mod annotation;
pub mod endpoint;
Expand All @@ -53,8 +48,11 @@ mod time_micros {
use std::time::{Duration, SystemTime, UNIX_EPOCH};

pub fn to_wire(time: &SystemTime) -> u64 {
super::duration_micros::to_wire(&time.duration_since(UNIX_EPOCH)
.unwrap_or(Duration::from_secs(0)))
super::duration_micros::to_wire(
&time
.duration_since(UNIX_EPOCH)
.unwrap_or(Duration::from_secs(0)),
)
}

pub fn from_wire(time: u64) -> SystemTime {
Expand Down
37 changes: 27 additions & 10 deletions zipkin-types/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
// limitations under the License.

//! Spans.
use crate::{Annotation, Endpoint, SpanId, TraceId};
use std::collections::HashMap;
use std::time::{Duration, SystemTime};

use {Annotation, Endpoint, SpanId, TraceId};

/// The "kind" of a span.
///
/// This has an impact on the relationship between the span's timestamp, duration, and local
/// endpoint.
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
pub enum Kind {
/// The client side of an RPC.
Expand Down Expand Up @@ -73,7 +72,7 @@ pub enum Kind {
/// server may both add their own annotations and binary annotations the span -
/// they will be merged.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct Span {
trace_id: TraceId,
Expand All @@ -86,25 +85,43 @@ pub struct Span {
kind: Option<Kind>,
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "Option::is_none", with = "::opt_time_micros")
serde(
skip_serializing_if = "Option::is_none",
with = "crate::opt_time_micros"
)
)]
timestamp: Option<SystemTime>,
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "Option::is_none", with = "::opt_duration_micros")
serde(
skip_serializing_if = "Option::is_none",
with = "crate::opt_duration_micros"
)
)]
duration: Option<Duration>,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "is_false", default = "value_false"))]
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "is_false", default = "value_false")
)]
debug: bool,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "is_false", default = "value_false"))]
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "is_false", default = "value_false")
)]
shared: bool,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
local_endpoint: Option<Endpoint>,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
remote_endpoint: Option<Endpoint>,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Vec::is_empty", default))]
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "Vec::is_empty", default)
)]
annotations: Vec<Annotation>,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "HashMap::is_empty", default))]
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "HashMap::is_empty", default)
)]
tags: HashMap<String, String>,
}

Expand Down
Loading

0 comments on commit 81a15bb

Please sign in to comment.