Skip to content

Commit

Permalink
Span properties (#13)
Browse files Browse the repository at this point in the history
* Mimics tags that Datadog java trace library uses for apm metrics.

* Forks and makes some changes to minitrace to support the full DD API.
  • Loading branch information
Stephen Cirner authored Oct 15, 2021
1 parent 2099800 commit 91a0d66
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 55 deletions.
78 changes: 40 additions & 38 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ tonic = "0.5"
tonic-health = "0.4"
tower = "0.4.8"
reqwest = { version = "0.11" }
minitrace = { git = "https://github.com/tikv/minitrace-rust.git" }
minitrace-macro = { git = "https://github.com/tikv/minitrace-rust.git" }
minitrace-datadog = { git = "https://github.com/tikv/minitrace-rust.git" }
minitrace = { git = "https://github.com/scirner22/minitrace-rust.git" }
minitrace-macro = { git = "https://github.com/scirner22/minitrace-rust.git" }
minitrace-datadog = { git = "https://github.com/scirner22/minitrace-rust.git" }
minstant = { git = "https://github.com/tikv/minstant.git" }
# TODO can we upgrade this?
tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "sync"] }
Expand Down
7 changes: 7 additions & 0 deletions bin/env
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ export URI_HOST=figure.com
export STORAGE_TYPE=file_system
export STORAGE_BASE_PATH=storage_bucket
export TRACE_HEADER=x-trace-header
export LOGGING_THRESHOLD_SECONDS=1
export RUST_LOG=warn,object_store=debug
export DD_AGENT_ENABLED=false
export DD_VERSION=undefined
export DD_SERVICE=object-store
export DD_ENV=local
export DD_TRACE_SPAN_TAGS=
32 changes: 29 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::net::{IpAddr, SocketAddr};
pub struct DatadogConfig {
pub agent_host: IpAddr,
pub agent_port: u16,
pub service_name: String,
pub service: String,
pub span_tags: Vec<(String, String)>,
}

#[derive(Debug)]
Expand All @@ -31,6 +32,12 @@ pub struct Config {
pub trace_header: String,
}

const BASE_SPAN_TAGS: [(&'static str, &'static str); 3] = [
("component", "grpc-server"),
("language", "rust"),
("span.kind", "server"),
];

impl Config {
pub fn new() -> Self {
let url = env::var("OS_URL").expect("OS_URL not set");
Expand Down Expand Up @@ -78,10 +85,29 @@ impl Config {
.unwrap_or("8126".to_owned())
.parse()
.expect("DD_AGENT_PORT could not be parsed into a u16");
let service_name = env::var("DD_SERVICE_NAME")
let service = env::var("DD_SERVICE")
.unwrap_or("object-store".to_owned());
let version = env::var("DD_VERSION")
.unwrap_or("undefined".to_owned());
let environment = env::var("DD_ENV")
.expect("DD_ENV not set");
let mut span_tags: Vec<(String, String)> = env::var("DD_TRACE_SPAN_TAGS")
.unwrap_or("".to_owned())
.split(",")
.map(|s| s.split_at(s.find(":").expect("DD_TRACE_SPAN_TAGS invalid syntax")))
.map(|(k, v)| {
let mut v = v.chars();
v.next();

(k.to_owned(), v.as_str().to_owned())
})
.collect();
span_tags.extend(BASE_SPAN_TAGS.iter().map(|(k, v)| (k.to_string(), v.to_string())));
span_tags.push(("app".to_owned(), service.clone()));
span_tags.push(("version".to_owned(), version));
span_tags.push(("env".to_owned(), environment));

Some(DatadogConfig { agent_host, agent_port, service_name })
Some(DatadogConfig { agent_host, agent_port, service, span_tags })
} else {
None
};
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ async fn main() -> Result<()> {
datadog_receiver,
dd_config.agent_host,
dd_config.agent_port,
dd_config.service_name.clone(),
dd_config.service.clone(),
));
}

log::info!("Starting server on {:?}", &config.url);

// TODO add server fields that make sense
if config.dd_config.is_some() {
if let Some(ref dd_config) = config.dd_config {
Server::builder()
.layer(LoggingMiddlewareLayer::new(Arc::clone(&config)))
.layer(MinitraceGrpcMiddlewareLayer::new(datadog_sender))
.layer(MinitraceGrpcMiddlewareLayer::new(Arc::clone(&config), dd_config.span_tags.clone(), datadog_sender))
.add_service(health_service)
.add_service(PublicKeyServiceServer::new(public_key_service))
.add_service(MailboxServiceServer::new(mailbox_service))
Expand Down
Loading

0 comments on commit 91a0d66

Please sign in to comment.