Skip to content

Commit

Permalink
Add resource and type to span.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Cirner committed Oct 11, 2021
1 parent a9b54e9 commit a5661e4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
49 changes: 25 additions & 24 deletions Cargo.lock

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

15 changes: 11 additions & 4 deletions src/middleware/minitrace_grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ where
let sender = self.sender.clone();

let headers = req.headers().clone();
let mut path = req.uri().path().chars();
path.next();
let path = path.as_str().to_owned();
let mut resource = req.uri().path().chars();
resource.next();
let resource = resource.as_str().to_owned();

Box::pin(async move {
let (root_span, collector) = Span::root(path);
let (root_span, collector) = Span::root("grpc.server".to_owned());
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();
Expand Down Expand Up @@ -114,7 +114,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,
trace_id,
parent_span_id,
span_id_prefix,
Expand All @@ -127,6 +130,8 @@ where
}

pub struct MinitraceSpans {
r#type: String,
resource: String,
trace_id: u64,
parent_span_id: u64,
span_id_prefix: u32,
Expand Down Expand Up @@ -155,6 +160,8 @@ pub async fn report_datadog_traces(
while let Some(spans) = receiver.recv().await {
let bytes = Reporter::encode(
&service_name,
&spans.r#type,
&spans.resource,
spans.trace_id,
spans.parent_span_id,
spans.span_id_prefix,
Expand Down

0 comments on commit a5661e4

Please sign in to comment.