Skip to content

Commit

Permalink
feat(datadog): add sampling priority tag in datadog spans (#792)
Browse files Browse the repository at this point in the history
* [dd-metrics-encode] encode sampling priority into metrics object of data dog exported data. data dog uses this to sample.

* [dd-metrics-encode] resolve ci issues by bumping msrv version

* [dd-metrics-encode] resolve ci issues by bumping msrv version to 1.59
  • Loading branch information
rex-remind101 authored Jun 10, 2022
1 parent 7c3a489 commit 3806258
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
7 changes: 5 additions & 2 deletions opentelemetry-datadog/src/exporter/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use url::ParseError;
mod v03;
mod v05;

// https://github.com/DataDog/dd-trace-js/blob/c89a35f7d27beb4a60165409376e170eacb194c5/packages/dd-trace/src/constants.js#L4
static SAMPLING_PRIORITY_KEY: &str = "_sampling_priority_v1";

/// Custom mapping between opentelemetry spans and datadog spans.
///
/// User can provide custom function to change the mapping. It currently supports customizing the following
Expand Down Expand Up @@ -242,7 +245,7 @@ pub(crate) mod tests {
None,
)?);

assert_eq!(encoded.as_str(), "kZGLpHR5cGWjd2Vip3NlcnZpY2Wsc2VydmljZV9uYW1lpG5hbWWpY29tcG9uZW50qHJlc291cmNlqHJlc291cmNlqHRyYWNlX2lkzwAAAAAAAAAHp3NwYW5faWTPAAAAAAAAAGOpcGFyZW50X2lkzwAAAAAAAAABpXN0YXJ00wAAAAAAAAAAqGR1cmF0aW9u0wAAAAA7msoApWVycm9y0gAAAACkbWV0YYGpc3Bhbi50eXBlo3dlYg==");
assert_eq!(encoded.as_str(), "kZGLpHR5cGWjd2Vip3NlcnZpY2Wsc2VydmljZV9uYW1lpG5hbWWpY29tcG9uZW50qHJlc291cmNlqHJlc291cmNlqHRyYWNlX2lkzwAAAAAAAAAHp3NwYW5faWTPAAAAAAAAAGOpcGFyZW50X2lkzwAAAAAAAAABpXN0YXJ00wAAAAAAAAAAqGR1cmF0aW9u0wAAAAA7msoApWVycm9y0gAAAACkbWV0YYGpc3Bhbi50eXBlo3dlYqdtZXRyaWNzgbVfc2FtcGxpbmdfcHJpb3JpdHlfdjHLAAAAAAAAAAA=");

Ok(())
}
Expand All @@ -263,7 +266,7 @@ pub(crate) mod tests {
)?);

assert_eq!(encoded.as_str(),
"kpWjd2VirHNlcnZpY2VfbmFtZaljb21wb25lbnSocmVzb3VyY2Wpc3Bhbi50eXBlkZGczgAAAAHOAAAAAs4AAAADzwAAAAAAAAAHzwAAAAAAAABjzwAAAAAAAAAB0wAAAAAAAAAA0wAAAAA7msoA0gAAAACBzgAAAATOAAAAAIDOAAAAAA==");
"kpajd2VirHNlcnZpY2VfbmFtZaljb21wb25lbnSocmVzb3VyY2Wpc3Bhbi50eXBltV9zYW1wbGluZ19wcmlvcml0eV92MZGRnM4AAAABzgAAAALOAAAAA88AAAAAAAAAB88AAAAAAAAAY88AAAAAAAAAAdMAAAAAAAAAANMAAAAAO5rKANIAAAAAgc4AAAAEzgAAAACBzgAAAAXLAAAAAAAAAADOAAAAAA==");

Ok(())
}
Expand Down
14 changes: 13 additions & 1 deletion opentelemetry-datadog/src/exporter/model/v03.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::exporter::model::Error;
use crate::exporter::model::{Error, SAMPLING_PRIORITY_KEY};
use crate::exporter::ModelConfig;
use opentelemetry::sdk::export::trace;
use opentelemetry::sdk::export::trace::SpanData;
Expand Down Expand Up @@ -95,6 +95,18 @@ where
rmp::encode::write_str(&mut encoded, key.as_str())?;
rmp::encode::write_str(&mut encoded, value.as_str().as_ref())?;
}

rmp::encode::write_str(&mut encoded, "metrics")?;
rmp::encode::write_map_len(&mut encoded, 1)?;
rmp::encode::write_str(&mut encoded, SAMPLING_PRIORITY_KEY)?;
rmp::encode::write_f64(
&mut encoded,
if span.span_context.is_sampled() {
1.0
} else {
0.0
},
)?;
}
}

Expand Down
12 changes: 11 additions & 1 deletion opentelemetry-datadog/src/exporter/model/v05.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::exporter::intern::StringInterner;
use crate::exporter::model::SAMPLING_PRIORITY_KEY;
use crate::exporter::{Error, ModelConfig};
use opentelemetry::sdk::export::trace;
use opentelemetry::sdk::export::trace::SpanData;
Expand Down Expand Up @@ -161,7 +162,16 @@ where
rmp::encode::write_u32(&mut encoded, interner.intern(key.as_str()))?;
rmp::encode::write_u32(&mut encoded, interner.intern(value.as_str().as_ref()))?;
}
rmp::encode::write_map_len(&mut encoded, 0)?;
rmp::encode::write_map_len(&mut encoded, 1)?;
rmp::encode::write_u32(&mut encoded, interner.intern(SAMPLING_PRIORITY_KEY))?;
rmp::encode::write_f64(
&mut encoded,
if span.span_context.is_sampled() {
1.0
} else {
0.0
},
)?;
rmp::encode::write_u32(&mut encoded, span_type)?;
}
}
Expand Down

0 comments on commit 3806258

Please sign in to comment.