Skip to content

Commit

Permalink
Add version and error code to dd spans.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Cirner committed Oct 12, 2021
1 parent a5661e4 commit 7bc7b55
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bin/env
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export TRACE_HEADER=x-trace-header
export LOGGING_THRESHOLD_SECONDS=1
export RUST_LOG=warn,object_store=debug
export DD_AGENT_ENABLED=false
DD_VERSION=undefined
export DD_SERVICE_NAME=object-store-service
export DD_TRACE_SPAN_TAGS=app:object-store,env:local
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ impl Config {
.expect("DD_AGENT_PORT could not be parsed into a u16");
let service_name = env::var("DD_SERVICE_NAME")
.unwrap_or("object-store".to_owned());
let version = env::var("DD_VERSION")
.unwrap_or("undefined".to_owned());
let mut span_tags: Vec<(String, String)> = env::var("DD_TRACE_SPAN_TAGS")
.unwrap_or("".to_owned())
.split(",")
Expand All @@ -99,6 +101,7 @@ impl Config {
})
.collect();
span_tags.extend(BASE_SPAN_TAGS.iter().map(|(k, v)| (k.to_string(), v.to_string())));
span_tags.push(("".to_owned(), version));

Some(DatadogConfig { agent_host, agent_port, service_name, span_tags })
} else {
Expand Down
26 changes: 15 additions & 11 deletions src/middleware/minitrace_grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ where
let response = inner.call(req).in_span(root_span).await?;

let status_code = response.headers().get("grpc-status").unwrap_or(&default_status_code).to_str().unwrap();
span_tags.push(("status.code".to_owned(), status_code.to_owned()));
// TODO remove if this isn't needed
// let status_code = tonic::Code::from_bytes(status_code.as_bytes());
// match status_code {
// tonic::Code::Ok => span_tags.push(("status.code".to_owned(), format!("{:?}", &status_code))),
// _ => {
// span_tags.push(("status.code".to_owned(), format!("{:?}", &status_code)));
// span_tags.push(("status.description".to_owned(), status_code.description().to_owned()));
// },
// }
let status_code = tonic::Code::from_bytes(status_code.as_bytes());
let error_code = match status_code {
tonic::Code::Ok => {
span_tags.push(("status.code".to_owned(), format!("{:?}", &status_code)));
0i32
},
_ => {
span_tags.push(("status.code".to_owned(), format!("{:?}", &status_code)));
span_tags.push(("status.description".to_owned(), status_code.description().to_owned()));
1i32
},
};
let spans: Vec<minitrace::span::Span> = collector.collect()
.into_iter()
.map(|mut span| {
Expand All @@ -114,10 +116,10 @@ where
.unwrap_or(&default_parent_span_id_header_value).to_str();
let parent_span_id: u64 = parent_span_id_header.unwrap().parse::<u64>().unwrap();

// TODO add error of non zero when there's an error
sender.send(MinitraceSpans {
r#type: String::from("rpc"),
resource,
error_code,
trace_id,
parent_span_id,
span_id_prefix,
Expand All @@ -132,6 +134,7 @@ where
pub struct MinitraceSpans {
r#type: String,
resource: String,
error_code: i32,
trace_id: u64,
parent_span_id: u64,
span_id_prefix: u32,
Expand Down Expand Up @@ -162,6 +165,7 @@ pub async fn report_datadog_traces(
&service_name,
&spans.r#type,
&spans.resource,
spans.error_code,
spans.trace_id,
spans.parent_span_id,
spans.span_id_prefix,
Expand Down

0 comments on commit 7bc7b55

Please sign in to comment.