Skip to content

Commit

Permalink
Merge branch 'master' into move-propagator
Browse files Browse the repository at this point in the history
  • Loading branch information
jtescher authored Oct 6, 2020
2 parents 07b3349 + 503503c commit 017b616
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
22 changes: 21 additions & 1 deletion opentelemetry-jaeger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
//! ```
#![deny(missing_docs, unreachable_pub, missing_debug_implementations)]
#![cfg_attr(test, deny(warnings))]

mod agent;
#[cfg(feature = "collector_client")]
mod collector;
Expand Down Expand Up @@ -176,6 +177,12 @@ const DEFAULT_SERVICE_NAME: &str = "OpenTelemetry";
/// Default agent endpoint if none is provided
const DEFAULT_AGENT_ENDPOINT: &str = "127.0.0.1:6831";

/// Instrument Library name MUST be reported in Jaeger Span tags with the following key
const INSTRUMENTATION_LIBRARY_NAME: &str = "otel.library.name";

/// Instrument Library version MUST be reported in Jaeger Span tags with the following key
const INSTRUMENTATION_LIBRARY_VERSION: &str = "otel.library.version";

/// Create a new Jaeger exporter pipeline builder.
pub fn new_pipeline() -> PipelineBuilder {
PipelineBuilder::default()
Expand Down Expand Up @@ -348,7 +355,8 @@ impl PipelineBuilder {
/// Install a Jaeger pipeline with the recommended defaults.
pub fn install(self) -> Result<(sdk::Tracer, Uninstall), Box<dyn Error>> {
let tracer_provider = self.build()?;
let tracer = tracer_provider.get_tracer("opentelemetry-jaeger", None);
let tracer =
tracer_provider.get_tracer("opentelemetry-jaeger", Some(env!("CARGO_PKG_VERSION")));

let provider_guard = global::set_tracer_provider(tracer_provider);

Expand Down Expand Up @@ -523,6 +531,18 @@ fn build_span_tags(span_data: &Arc<trace::SpanData>) -> Option<Vec<jaeger::Tag>>
})
.collect::<Vec<_>>();

// Set instrument library tags
tags.push(
api::KeyValue::new(
INSTRUMENTATION_LIBRARY_NAME,
span_data.instrumentation_lib.name,
)
.into(),
);
if let Some(version) = span_data.instrumentation_lib.version {
tags.push(api::KeyValue::new(INSTRUMENTATION_LIBRARY_VERSION, version).into())
}

// Ensure error status is set
if span_data.status_code != api::StatusCode::OK && !user_overrides.error {
tags.push(api::Key::new(ERROR).bool(true).into())
Expand Down
21 changes: 21 additions & 0 deletions opentelemetry-zipkin/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub(crate) mod span;

use endpoint::Endpoint;

/// Instrument Library name MUST be reported in Jaeger Span tags with the following key
const INSTRUMENTATION_LIBRARY_NAME: &str = "otel.library.name";

/// Instrument Library version MUST be reported in Jaeger Span tags with the following key
const INSTRUMENTATION_LIBRARY_VERSION: &str = "otel.library.version";

/// Converts `api::Event` into an `annotation::Annotation`
impl Into<annotation::Annotation> for api::Event {
fn into(self) -> annotation::Annotation {
Expand Down Expand Up @@ -81,6 +87,21 @@ pub(crate) fn into_zipkin_span(
.resource
.iter()
.map(|(k, v)| api::KeyValue::new(k.clone(), v.clone())),
)
.chain(
[
(
INSTRUMENTATION_LIBRARY_NAME,
Some(span_data.instrumentation_lib.name),
),
(
INSTRUMENTATION_LIBRARY_VERSION,
span_data.instrumentation_lib.version,
),
]
.iter()
.filter(|(_, val)| val.is_some())
.map(|(k, v)| api::KeyValue::new(<&str>::clone(k), v.unwrap_or(""))),
),
);

Expand Down
4 changes: 2 additions & 2 deletions src/api/baggage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//!
//! // Example baggage value passed in externally via http headers
//! let mut headers = HashMap::new();
//! headers.insert("otcorrelations".to_string(), "user_id=1".to_string());
//! headers.insert("baggage".to_string(), "user_id=1".to_string());
//!
//! let propagator = BaggagePropagator::new();
//! // can extract from any type that impls `Extractor`, usually an HTTP header map
Expand All @@ -37,7 +37,7 @@
//! // Inject aggage into http request
//! propagator.inject_context(&cx_with_additions, &mut headers);
//!
//! let header_value = headers.get("otcorrelations").expect("header is injected");
//! let header_value = headers.get("baggage").expect("header is injected");
//! assert!(header_value.contains("user_id=1"), "still contains previous name / value");
//! assert!(header_value.contains("server_id=42"), "contains new name / value pair");
//! ```
Expand Down
2 changes: 1 addition & 1 deletion src/api/baggage/propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::api::{self, Context, KeyValue};
use percent_encoding::{percent_decode_str, utf8_percent_encode, AsciiSet, CONTROLS};
use std::iter;

static BAGGAGE_HEADER: &str = "otcorrelations";
static BAGGAGE_HEADER: &str = "baggage";
const FRAGMENT: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b';').add(b',').add(b'=');

lazy_static::lazy_static! {
Expand Down
4 changes: 2 additions & 2 deletions src/api/context/propagation/composite_propagator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use std::fmt::Debug;
/// .with_baggage(vec![KeyValue::new("test", "example")]),
/// &mut injector);
///
/// // The injector now has both `otcorrelations` and `traceparent` headers
/// assert!(injector.get("otcorrelations").is_some());
/// // The injector now has both `baggage` and `traceparent` headers
/// assert!(injector.get("baggage").is_some());
/// assert!(injector.get("traceparent").is_some());
/// ```
#[derive(Debug)]
Expand Down
22 changes: 11 additions & 11 deletions src/sdk/trace/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ pub struct SamplingResult {
pub enum SamplingDecision {
/// `is_recording() == false`, span will not be recorded and all events and
/// attributes will be dropped.
NotRecord,
Drop,
/// `is_recording() == true`, but `Sampled` flag MUST NOT be set.
Record,
RecordOnly,
/// `is_recording() == true` AND `Sampled` flag` MUST be set.
RecordAndSampled,
RecordAndSample,
}

/// Sampling options
Expand Down Expand Up @@ -107,35 +107,35 @@ impl ShouldSample for Sampler {
) -> SamplingResult {
let decision = match self {
// Always sample the trace
Sampler::AlwaysOn => SamplingDecision::RecordAndSampled,
Sampler::AlwaysOn => SamplingDecision::RecordAndSample,
// Never sample the trace
Sampler::AlwaysOff => SamplingDecision::NotRecord,
Sampler::AlwaysOff => SamplingDecision::Drop,
// The parent decision if sampled; otherwise the decision of delegate_sampler
Sampler::ParentBased(delegate_sampler) => parent_context.map_or(
delegate_sampler
.should_sample(parent_context, trace_id, name, span_kind, attributes, links)
.decision,
|ctx| {
if ctx.is_sampled() {
SamplingDecision::RecordAndSampled
SamplingDecision::RecordAndSample
} else {
SamplingDecision::NotRecord
SamplingDecision::Drop
}
},
),
// Probabilistically sample the trace.
Sampler::TraceIdRatioBased(prob) => {
if *prob >= 1.0 {
SamplingDecision::RecordAndSampled
SamplingDecision::RecordAndSample
} else {
let prob_upper_bound = (prob.max(0.0) * (1u64 << 63) as f64) as u64;
// The trace_id is already randomly generated, so we don't need a new one here
let rnd_from_trace_id = (trace_id.to_u128() as u64) >> 1;

if rnd_from_trace_id < prob_upper_bound {
SamplingDecision::RecordAndSampled
SamplingDecision::RecordAndSample
} else {
SamplingDecision::NotRecord
SamplingDecision::Drop
}
}
}
Expand Down Expand Up @@ -241,7 +241,7 @@ mod tests {
&[],
)
.decision
== SamplingDecision::RecordAndSampled
== SamplingDecision::RecordAndSample
{
sampled += 1;
}
Expand Down
8 changes: 4 additions & 4 deletions src/sdk/trace/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ impl Tracer {
) -> Option<(u8, Vec<api::KeyValue>, TraceState)> {
match sampling_result {
sdk::SamplingResult {
decision: sdk::SamplingDecision::NotRecord,
decision: sdk::SamplingDecision::Drop,
..
} => None,
sdk::SamplingResult {
decision: sdk::SamplingDecision::Record,
decision: sdk::SamplingDecision::RecordOnly,
attributes,
trace_state,
} => {
Expand All @@ -97,7 +97,7 @@ impl Tracer {
))
}
sdk::SamplingResult {
decision: sdk::SamplingDecision::RecordAndSampled,
decision: sdk::SamplingDecision::RecordAndSample,
attributes,
trace_state,
} => {
Expand Down Expand Up @@ -302,7 +302,7 @@ mod tests {
) -> SamplingResult {
let trace_state = parent_context.unwrap().trace_state().clone();
SamplingResult {
decision: SamplingDecision::RecordAndSampled,
decision: SamplingDecision::RecordAndSample,
attributes: Vec::new(),
trace_state: trace_state.insert("foo".into(), "notbar".into()).unwrap(),
}
Expand Down

0 comments on commit 017b616

Please sign in to comment.