First step for telemetry
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Valentin Brandl 2021-03-29 14:58:36 +02:00
parent 6570daef02
commit 35c13fa486
5 changed files with 176 additions and 13 deletions

170
Cargo.lock generated
View File

@ -18,7 +18,7 @@ dependencies = [
"futures-sink", "futures-sink",
"log", "log",
"pin-project 0.4.27", "pin-project 0.4.27",
"tokio", "tokio 0.2.25",
"tokio-util", "tokio-util",
] ]
@ -123,7 +123,7 @@ dependencies = [
"futures-channel", "futures-channel",
"futures-util", "futures-util",
"smallvec", "smallvec",
"tokio", "tokio 0.2.25",
] ]
[[package]] [[package]]
@ -267,6 +267,20 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "actix-web-opentelemetry"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac71801f541f5225e71f522d56901b0be7fd6ee2181724a7e551b74249d0129"
dependencies = [
"actix-http",
"actix-web",
"futures",
"opentelemetry 0.12.0",
"opentelemetry-semantic-conventions",
"serde 1.0.125",
]
[[package]] [[package]]
name = "addr2line" name = "addr2line"
version = "0.14.1" version = "0.14.1"
@ -574,6 +588,16 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
[[package]]
name = "dashmap"
version = "4.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
dependencies = [
"cfg-if 1.0.0",
"num_cpus",
]
[[package]] [[package]]
name = "derive_more" name = "derive_more"
version = "0.99.11" version = "0.99.11"
@ -902,7 +926,7 @@ dependencies = [
"http", "http",
"indexmap", "indexmap",
"slab", "slab",
"tokio", "tokio 0.2.25",
"tokio-util", "tokio-util",
"tracing", "tracing",
"tracing-futures", "tracing-futures",
@ -938,6 +962,7 @@ version = "0.17.1"
dependencies = [ dependencies = [
"actix-rt", "actix-rt",
"actix-web", "actix-web",
"actix-web-opentelemetry",
"badge", "badge",
"bytes 1.0.1", "bytes 1.0.1",
"config", "config",
@ -947,18 +972,21 @@ dependencies = [
"lazy_static", "lazy_static",
"number_prefix", "number_prefix",
"openssl-probe", "openssl-probe",
"opentelemetry 0.13.0",
"opentelemetry-jaeger",
"reqwest", "reqwest",
"ructe", "ructe",
"serde 1.0.125", "serde 1.0.125",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"tempfile", "tempfile",
"tokio", "tokio 0.2.25",
"tracing", "tracing",
"tracing-actix-web", "tracing-actix-web",
"tracing-bunyan-formatter", "tracing-bunyan-formatter",
"tracing-futures", "tracing-futures",
"tracing-log", "tracing-log",
"tracing-opentelemetry",
"tracing-subscriber", "tracing-subscriber",
"vergen", "vergen",
] ]
@ -1025,7 +1053,7 @@ dependencies = [
"itoa", "itoa",
"pin-project 1.0.5", "pin-project 1.0.5",
"socket2", "socket2",
"tokio", "tokio 0.2.25",
"tower-service", "tower-service",
"tracing", "tracing",
"want", "want",
@ -1040,7 +1068,7 @@ dependencies = [
"bytes 0.5.6", "bytes 0.5.6",
"hyper", "hyper",
"native-tls", "native-tls",
"tokio", "tokio 0.2.25",
"tokio-tls", "tokio-tls",
] ]
@ -1074,6 +1102,12 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
[[package]]
name = "integer-encoding"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48dc51180a9b377fd75814d0cc02199c20f8e99433d6762f650d39cdbbd3b56f"
[[package]] [[package]]
name = "iovec" name = "iovec"
version = "0.1.4" version = "0.1.4"
@ -1484,6 +1518,73 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "opentelemetry"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "514d24875c140ed269eecc2d1b56d7b71b573716922a763c317fb1b1b4b58f15"
dependencies = [
"async-trait",
"dashmap",
"fnv",
"futures",
"js-sys",
"lazy_static",
"percent-encoding",
"pin-project 1.0.5",
"rand 0.8.3",
"thiserror",
]
[[package]]
name = "opentelemetry"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91cea1dfd50064e52db033179952d18c770cbc5dfefc8eba45d619357ba3914"
dependencies = [
"async-trait",
"futures",
"js-sys",
"lazy_static",
"percent-encoding",
"pin-project 1.0.5",
"rand 0.8.3",
"thiserror",
"tokio 1.4.0",
"tokio-stream",
]
[[package]]
name = "opentelemetry-jaeger"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a619edf77ab8bc75d99220811e1cf1a14f1760750c80c4752a20a9aef7dce214"
dependencies = [
"async-trait",
"lazy_static",
"opentelemetry 0.13.0",
"thiserror",
"thrift",
]
[[package]]
name = "opentelemetry-semantic-conventions"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ecb679b997c41108a498e3ce8b933fe2f643a9a722ad8ca33f95edab84df106"
dependencies = [
"opentelemetry 0.12.0",
]
[[package]]
name = "ordered-float"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3305af35278dd29f46fcdd139e0b1fbfae2153f0e5928b39b035542dd31e37b7"
dependencies = [
"num-traits 0.2.14",
]
[[package]] [[package]]
name = "owned_ttf_parser" name = "owned_ttf_parser"
version = "0.6.0" version = "0.6.0"
@ -1807,7 +1908,7 @@ dependencies = [
"pin-project-lite 0.2.4", "pin-project-lite 0.2.4",
"serde 1.0.125", "serde 1.0.125",
"serde_urlencoded", "serde_urlencoded",
"tokio", "tokio 0.2.25",
"tokio-tls", "tokio-tls",
"url", "url",
"wasm-bindgen", "wasm-bindgen",
@ -2184,6 +2285,19 @@ dependencies = [
"num_cpus", "num_cpus",
] ]
[[package]]
name = "thrift"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6d965454947cc7266d22716ebfd07b18d84ebaf35eec558586bbb2a8cb6b5b"
dependencies = [
"byteorder",
"integer-encoding",
"log",
"ordered-float",
"threadpool",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.1.43" version = "0.1.43"
@ -2268,6 +2382,27 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "tokio"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722"
dependencies = [
"autocfg",
"pin-project-lite 0.2.4",
]
[[package]]
name = "tokio-stream"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e177a5d8c3bf36de9ebe6d58537d8879e964332f93fb3339e43f618c81361af0"
dependencies = [
"futures-core",
"pin-project-lite 0.2.4",
"tokio 1.4.0",
]
[[package]] [[package]]
name = "tokio-tls" name = "tokio-tls"
version = "0.3.1" version = "0.3.1"
@ -2275,7 +2410,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343"
dependencies = [ dependencies = [
"native-tls", "native-tls",
"tokio", "tokio 0.2.25",
] ]
[[package]] [[package]]
@ -2289,7 +2424,7 @@ dependencies = [
"futures-sink", "futures-sink",
"log", "log",
"pin-project-lite 0.1.11", "pin-project-lite 0.1.11",
"tokio", "tokio 0.2.25",
] ]
[[package]] [[package]]
@ -2391,6 +2526,19 @@ dependencies = [
"tracing-core", "tracing-core",
] ]
[[package]]
name = "tracing-opentelemetry"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccdf13c28f1654fe806838f28c5b9cb23ca4c0eae71450daa489f50e523ceb1"
dependencies = [
"opentelemetry 0.12.0",
"tracing",
"tracing-core",
"tracing-log",
"tracing-subscriber",
]
[[package]] [[package]]
name = "tracing-serde" name = "tracing-serde"
version = "0.1.2" version = "0.1.2"
@ -2439,7 +2587,7 @@ dependencies = [
"rand 0.7.3", "rand 0.7.3",
"smallvec", "smallvec",
"thiserror", "thiserror",
"tokio", "tokio 0.2.25",
"url", "url",
] ]
@ -2459,7 +2607,7 @@ dependencies = [
"resolv-conf", "resolv-conf",
"smallvec", "smallvec",
"thiserror", "thiserror",
"tokio", "tokio 0.2.25",
"trust-dns-proto", "trust-dns-proto",
] ]

View File

@ -15,6 +15,7 @@ name = "hoc"
[dependencies] [dependencies]
actix-rt = "1.1.1" actix-rt = "1.1.1"
actix-web = "3.3.2" actix-web = "3.3.2"
actix-web-opentelemetry = "0.10.0"
badge = "0.3.0" badge = "0.3.0"
bytes = "1.0.1" bytes = "1.0.1"
config = { version = "0.11.0", features = ["toml"] } config = { version = "0.11.0", features = ["toml"] }
@ -24,6 +25,8 @@ git2 = "0.13.17"
lazy_static = "1.4.0" lazy_static = "1.4.0"
number_prefix = "0.4.0" number_prefix = "0.4.0"
openssl-probe = "0.1.2" openssl-probe = "0.1.2"
opentelemetry = { version = "0.13.0", default-features = false, features = ["trace", "rt-tokio-current-thread"] }
opentelemetry-jaeger = "0.12.0"
reqwest = "0.10.10" reqwest = "0.10.10"
serde = "1.0.125" serde = "1.0.125"
serde_derive = "1.0.123" serde_derive = "1.0.123"
@ -33,6 +36,7 @@ tracing-actix-web = "0.2.1"
tracing-bunyan-formatter = "0.1.7" tracing-bunyan-formatter = "0.1.7"
tracing-futures = "0.2.5" tracing-futures = "0.2.5"
tracing-log = "0.1.2" tracing-log = "0.1.2"
tracing-opentelemetry = "0.11.0"
tracing-subscriber = { version = "0.2.17", features = ["registry", "env-filter"] } tracing-subscriber = { version = "0.2.17", features = ["registry", "env-filter"] }
[build-dependencies] [build-dependencies]

View File

@ -32,6 +32,7 @@ use actix_web::{
middleware::{self, normalize::TrailingSlash}, middleware::{self, normalize::TrailingSlash},
web, App, HttpResponse, HttpServer, Responder, web, App, HttpResponse, HttpServer, Responder,
}; };
use actix_web_opentelemetry::RequestTracing;
use badge::{Badge, BadgeOptions}; use badge::{Badge, BadgeOptions};
use git2::{BranchType, Repository}; use git2::{BranchType, Repository};
use number_prefix::NumberPrefix; use number_prefix::NumberPrefix;
@ -480,6 +481,7 @@ async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Res
App::new() App::new()
.app_data(state.clone()) .app_data(state.clone())
.app_data(repo_count.clone()) .app_data(repo_count.clone())
.wrap(RequestTracing::new())
.wrap(tracing_actix_web::TracingLogger) .wrap(tracing_actix_web::TracingLogger)
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim)) .wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
.service(index) .service(index)

View File

@ -1,5 +1,4 @@
use hoc::{config::Settings, telemetry}; use hoc::{config::Settings, telemetry};
use std::net::TcpListener; use std::net::TcpListener;
fn init() { fn init() {
@ -18,7 +17,8 @@ async fn main() -> std::io::Result<()> {
let address = format!("{}:{}", settings.host, settings.port); let address = format!("{}:{}", settings.host, settings.port);
// TODO: error handling // TODO: error handling
let listener = TcpListener::bind(address)?; let listener = TcpListener::bind(address).expect("cannot bind addres");
hoc::run(listener, settings) hoc::run(listener, settings)
.await .await
.expect("Server error") .expect("Server error")

View File

@ -1,3 +1,4 @@
use opentelemetry::{global, runtime::TokioCurrentThread};
use tracing::{subscriber::set_global_default, Subscriber}; use tracing::{subscriber::set_global_default, Subscriber};
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer}; use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
use tracing_log::LogTracer; use tracing_log::LogTracer;
@ -9,7 +10,15 @@ pub fn get_subscriber(name: &str, env_filter: &str) -> impl Subscriber + Send +
let formatting_layer = BunyanFormattingLayer::new(name.to_string(), std::io::stdout); let formatting_layer = BunyanFormattingLayer::new(name.to_string(), std::io::stdout);
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name(name)
.install_batch(TokioCurrentThread)
.expect("cannot install jaeger pipeline");
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
Registry::default() Registry::default()
.with(telemetry)
.with(env_filter) .with(env_filter)
.with(JsonStorageLayer) .with(JsonStorageLayer)
.with(formatting_layer) .with(formatting_layer)