Enable jaeger + opentracing logging
This commit is contained in:
parent
ac172670be
commit
6fd36936a3
74
Cargo.lock
generated
74
Cargo.lock
generated
@ -1713,6 +1713,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 = "intl-memoizer"
|
name = "intl-memoizer"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
@ -2119,6 +2125,44 @@ version = "0.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b91cea1dfd50064e52db033179952d18c770cbc5dfefc8eba45d619357ba3914"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"futures 0.3.14",
|
||||||
|
"js-sys",
|
||||||
|
"lazy_static",
|
||||||
|
"percent-encoding",
|
||||||
|
"pin-project 1.0.6",
|
||||||
|
"rand 0.8.3",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry-jaeger"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ddd4984441954f9ebbe3eebdfc6fd4fa95be6400d403171228779b949f3cd918"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"lazy_static",
|
||||||
|
"opentelemetry",
|
||||||
|
"thiserror",
|
||||||
|
"thrift",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ordered-float"
|
||||||
|
version = "1.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3305af35278dd29f46fcdd139e0b1fbfae2153f0e5928b39b035542dd31e37b7"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ouroboros"
|
name = "ouroboros"
|
||||||
version = "0.8.3"
|
version = "0.8.3"
|
||||||
@ -2400,6 +2444,8 @@ dependencies = [
|
|||||||
"fluent-langneg",
|
"fluent-langneg",
|
||||||
"fluent-templates",
|
"fluent-templates",
|
||||||
"image",
|
"image",
|
||||||
|
"opentelemetry",
|
||||||
|
"opentelemetry-jaeger",
|
||||||
"qrcode",
|
"qrcode",
|
||||||
"rand 0.8.3",
|
"rand 0.8.3",
|
||||||
"rpassword",
|
"rpassword",
|
||||||
@ -2410,7 +2456,7 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
"tracing-actix-web",
|
"tracing-actix-web",
|
||||||
"tracing-bunyan-formatter",
|
"tracing-bunyan-formatter",
|
||||||
"tracing-log",
|
"tracing-opentelemetry",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -3372,6 +3418,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 = "tiff"
|
name = "tiff"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
@ -3595,6 +3654,19 @@ dependencies = [
|
|||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-opentelemetry"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99003208b647dae59dcefc49c98aecaa3512fbc29351685d4b9ef23a9218458e"
|
||||||
|
dependencies = [
|
||||||
|
"opentelemetry",
|
||||||
|
"tracing",
|
||||||
|
"tracing-core",
|
||||||
|
"tracing-log",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-serde"
|
name = "tracing-serde"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
@ -27,9 +27,11 @@ chrono = { version = "0.4", features = ["serde"] }
|
|||||||
argonautica = "0.2"
|
argonautica = "0.2"
|
||||||
tracing = { version = "0.1", features = ["log"] }
|
tracing = { version = "0.1", features = ["log"] }
|
||||||
tracing-bunyan-formatter = "0.2.0"
|
tracing-bunyan-formatter = "0.2.0"
|
||||||
tracing-subscriber = { version = "0.2.12", features = ["registry", "env-filter"] }
|
tracing-subscriber = { version = "0.2.17", features = ["registry", "env-filter"] }
|
||||||
tracing-log = "0.1"
|
|
||||||
tracing-actix-web = "0.2.1"
|
tracing-actix-web = "0.2.1"
|
||||||
|
tracing-opentelemetry = "0.12"
|
||||||
|
opentelemetry = "0.13"
|
||||||
|
opentelemetry-jaeger="0.12"
|
||||||
qrcode = "0.12"
|
qrcode = "0.12"
|
||||||
image = "0.23"
|
image = "0.23"
|
||||||
rand="0.8"
|
rand="0.8"
|
||||||
|
@ -15,18 +15,29 @@ use tracing::instrument;
|
|||||||
use tracing::{error, info, trace};
|
use tracing::{error, info, trace};
|
||||||
use tracing::{subscriber::set_global_default, Subscriber};
|
use tracing::{subscriber::set_global_default, Subscriber};
|
||||||
use tracing_actix_web::TracingLogger;
|
use tracing_actix_web::TracingLogger;
|
||||||
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
|
use tracing_opentelemetry::OpenTelemetryLayer;
|
||||||
use tracing_log::LogTracer;
|
|
||||||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
||||||
|
|
||||||
/// Compose multiple layers into a `tracing`'s subscriber.
|
/// Compose multiple layers into a `tracing`'s subscriber.
|
||||||
pub fn get_subscriber(name: String, env_filter: String) -> impl Subscriber + Send + Sync {
|
#[must_use]
|
||||||
|
pub fn get_subscriber(name: &str, env_filter: &str) -> impl Subscriber + Send + Sync {
|
||||||
let env_filter =
|
let env_filter =
|
||||||
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter));
|
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter));
|
||||||
let formatting_layer = BunyanFormattingLayer::new(name, std::io::stdout);
|
// Create a jaeger exporter pipeline for a `trace_demo` service.
|
||||||
|
let tracer = opentelemetry_jaeger::new_pipeline()
|
||||||
|
.with_service_name(name)
|
||||||
|
.install_simple()
|
||||||
|
.expect("Error initializing Jaeger exporter");
|
||||||
|
let formatting_layer = tracing_subscriber::fmt::layer().with_target(false);
|
||||||
|
|
||||||
|
// Create a layer with the configured tracer
|
||||||
|
let otel_layer = OpenTelemetryLayer::new(tracer);
|
||||||
|
|
||||||
|
// Use the tracing subscriber `Registry`, or any other subscriber
|
||||||
|
// that impls `LookupSpan`
|
||||||
Registry::default()
|
Registry::default()
|
||||||
|
.with(otel_layer)
|
||||||
.with(env_filter)
|
.with(env_filter)
|
||||||
.with(JsonStorageLayer)
|
|
||||||
.with(formatting_layer)
|
.with(formatting_layer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +45,6 @@ pub fn get_subscriber(name: String, env_filter: String) -> impl Subscriber + Sen
|
|||||||
///
|
///
|
||||||
/// It should only be called once!
|
/// It should only be called once!
|
||||||
pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {
|
pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {
|
||||||
LogTracer::init().expect("Failed to set logger");
|
|
||||||
set_global_default(subscriber).expect("Failed to set subscriber");
|
set_global_default(subscriber).expect("Failed to set subscriber");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +60,6 @@ static_loader! {
|
|||||||
#[instrument]
|
#[instrument]
|
||||||
fn build_tera() -> Result<Tera> {
|
fn build_tera() -> Result<Tera> {
|
||||||
let mut tera = Tera::default();
|
let mut tera = Tera::default();
|
||||||
tracing::info!("Tracing activated!");
|
|
||||||
|
|
||||||
// Add translation support
|
// Add translation support
|
||||||
tera.register_function("fluent", FluentLoader::new(&*LOCALES));
|
tera.register_function("fluent", FluentLoader::new(&*LOCALES));
|
||||||
@ -209,7 +218,7 @@ async fn webservice(server_config: ServerConfig) -> Result<()> {
|
|||||||
#[instrument]
|
#[instrument]
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::result::Result<(), ServerError> {
|
async fn main() -> std::result::Result<(), ServerError> {
|
||||||
let subscriber = get_subscriber("app".into(), "info".into());
|
let subscriber = get_subscriber("fhs.li", "info");
|
||||||
init_subscriber(subscriber);
|
init_subscriber(subscriber);
|
||||||
|
|
||||||
match cli::setup().await {
|
match cli::setup().await {
|
||||||
|
@ -15,13 +15,14 @@ use image::{DynamicImage, ImageOutputFormat, Luma};
|
|||||||
use qrcode::{render::svg, QrCode};
|
use qrcode::{render::svg, QrCode};
|
||||||
use queries::{authenticate, Role};
|
use queries::{authenticate, Role};
|
||||||
use tera::{Context, Tera};
|
use tera::{Context, Tera};
|
||||||
use tracing::{info, trace, warn};
|
use tracing::{info, instrument, trace, warn};
|
||||||
|
|
||||||
use pslink::forms::LinkForm;
|
use pslink::forms::LinkForm;
|
||||||
use pslink::models::{LoginUser, NewUser};
|
use pslink::models::{LoginUser, NewUser};
|
||||||
use pslink::queries;
|
use pslink::queries;
|
||||||
use pslink::ServerError;
|
use pslink::ServerError;
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
fn redirect_builder(target: &str) -> HttpResponse {
|
fn redirect_builder(target: &str) -> HttpResponse {
|
||||||
HttpResponse::SeeOther()
|
HttpResponse::SeeOther()
|
||||||
.set(CacheControl(vec![
|
.set(CacheControl(vec![
|
||||||
@ -34,6 +35,7 @@ fn redirect_builder(target: &str) -> HttpResponse {
|
|||||||
.body(format!("Redirect to {}", target))
|
.body(format!("Redirect to {}", target))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
fn detect_language(request: &HttpRequest) -> Result<String, ServerError> {
|
fn detect_language(request: &HttpRequest) -> Result<String, ServerError> {
|
||||||
let requested = parse_accepted_languages(
|
let requested = parse_accepted_languages(
|
||||||
request
|
request
|
||||||
@ -63,6 +65,8 @@ fn detect_language(request: &HttpRequest) -> Result<String, ServerError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Show the list of all available links if a user is authenticated
|
/// Show the list of all available links if a user is authenticated
|
||||||
|
|
||||||
|
#[instrument(skip(id, tera))]
|
||||||
pub async fn index(
|
pub async fn index(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -81,6 +85,7 @@ pub async fn index(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Show the list of all available links if a user is authenticated
|
/// Show the list of all available links if a user is authenticated
|
||||||
|
#[instrument(skip(id, tera))]
|
||||||
pub async fn index_users(
|
pub async fn index_users(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -98,6 +103,8 @@ pub async fn index_users(
|
|||||||
Ok(redirect_builder("/admin/login"))
|
Ok(redirect_builder("/admin/login"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id, tera))]
|
||||||
pub async fn view_link_empty(
|
pub async fn view_link_empty(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -106,6 +113,7 @@ pub async fn view_link_empty(
|
|||||||
view_link(tera, config, id, web::Path::from("".to_owned())).await
|
view_link(tera, config, id, web::Path::from("".to_owned())).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id, tera))]
|
||||||
pub async fn view_link(
|
pub async fn view_link(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -145,6 +153,7 @@ pub async fn view_link(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id, tera))]
|
||||||
pub async fn view_profile(
|
pub async fn view_profile(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -172,6 +181,7 @@ pub async fn view_profile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id, tera))]
|
||||||
pub async fn edit_profile(
|
pub async fn edit_profile(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -198,6 +208,7 @@ pub async fn edit_profile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn process_edit_profile(
|
pub async fn process_edit_profile(
|
||||||
data: web::Form<NewUser>,
|
data: web::Form<NewUser>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -211,6 +222,7 @@ pub async fn process_edit_profile(
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn download_png(
|
pub async fn download_png(
|
||||||
id: Identity,
|
id: Identity,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -235,6 +247,7 @@ pub async fn download_png(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id, tera))]
|
||||||
pub async fn signup(
|
pub async fn signup(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -255,6 +268,7 @@ pub async fn signup(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn process_signup(
|
pub async fn process_signup(
|
||||||
data: web::Form<NewUser>,
|
data: web::Form<NewUser>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -269,6 +283,7 @@ pub async fn process_signup(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn toggle_admin(
|
pub async fn toggle_admin(
|
||||||
data: web::Path<String>,
|
data: web::Path<String>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -281,6 +296,7 @@ pub async fn toggle_admin(
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn set_language(
|
pub async fn set_language(
|
||||||
data: web::Path<String>,
|
data: web::Path<String>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -290,6 +306,7 @@ pub async fn set_language(
|
|||||||
Ok(redirect_builder("/admin/index/"))
|
Ok(redirect_builder("/admin/index/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn login(
|
pub async fn login(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
id: Identity,
|
id: Identity,
|
||||||
@ -323,6 +340,7 @@ pub async fn login(
|
|||||||
Ok(HttpResponse::Ok().body(rendered))
|
Ok(HttpResponse::Ok().body(rendered))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn process_login(
|
pub async fn process_login(
|
||||||
data: web::Form<LoginUser>,
|
data: web::Form<LoginUser>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -355,11 +373,14 @@ pub async fn process_login(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn logout(id: Identity) -> Result<HttpResponse, ServerError> {
|
pub async fn logout(id: Identity) -> Result<HttpResponse, ServerError> {
|
||||||
|
info!("Logging out the user");
|
||||||
id.forget();
|
id.forget();
|
||||||
Ok(redirect_builder("/admin/login/"))
|
Ok(redirect_builder("/admin/login/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub async fn redirect(
|
pub async fn redirect(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -390,12 +411,14 @@ pub async fn redirect(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub async fn redirect_empty(
|
pub async fn redirect_empty(
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
) -> Result<HttpResponse, ServerError> {
|
) -> Result<HttpResponse, ServerError> {
|
||||||
Ok(redirect_builder(&config.empty_forward_url))
|
Ok(redirect_builder(&config.empty_forward_url))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn create_link(
|
pub async fn create_link(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -416,6 +439,7 @@ pub async fn create_link(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn process_link_creation(
|
pub async fn process_link_creation(
|
||||||
data: web::Form<LinkForm>,
|
data: web::Form<LinkForm>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -428,6 +452,7 @@ pub async fn process_link_creation(
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn edit_link(
|
pub async fn edit_link(
|
||||||
tera: web::Data<Tera>,
|
tera: web::Data<Tera>,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
@ -460,6 +485,7 @@ pub async fn process_link_edit(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(id))]
|
||||||
pub async fn process_link_delete(
|
pub async fn process_link_delete(
|
||||||
id: Identity,
|
id: Identity,
|
||||||
config: web::Data<pslink::ServerConfig>,
|
config: web::Data<pslink::ServerConfig>,
|
||||||
|
Loading…
Reference in New Issue
Block a user