Enable jaeger + opentracing logging
This commit is contained in:
+17
-8
@@ -15,18 +15,29 @@ use tracing::instrument;
|
||||
use tracing::{error, info, trace};
|
||||
use tracing::{subscriber::set_global_default, Subscriber};
|
||||
use tracing_actix_web::TracingLogger;
|
||||
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
|
||||
use tracing_log::LogTracer;
|
||||
use tracing_opentelemetry::OpenTelemetryLayer;
|
||||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
||||
|
||||
/// 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 =
|
||||
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()
|
||||
.with(otel_layer)
|
||||
.with(env_filter)
|
||||
.with(JsonStorageLayer)
|
||||
.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!
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -50,7 +60,6 @@ static_loader! {
|
||||
#[instrument]
|
||||
fn build_tera() -> Result<Tera> {
|
||||
let mut tera = Tera::default();
|
||||
tracing::info!("Tracing activated!");
|
||||
|
||||
// Add translation support
|
||||
tera.register_function("fluent", FluentLoader::new(&*LOCALES));
|
||||
@@ -209,7 +218,7 @@ async fn webservice(server_config: ServerConfig) -> Result<()> {
|
||||
#[instrument]
|
||||
#[actix_web::main]
|
||||
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);
|
||||
|
||||
match cli::setup().await {
|
||||
|
||||
+27
-1
@@ -15,13 +15,14 @@ use image::{DynamicImage, ImageOutputFormat, Luma};
|
||||
use qrcode::{render::svg, QrCode};
|
||||
use queries::{authenticate, Role};
|
||||
use tera::{Context, Tera};
|
||||
use tracing::{info, trace, warn};
|
||||
use tracing::{info, instrument, trace, warn};
|
||||
|
||||
use pslink::forms::LinkForm;
|
||||
use pslink::models::{LoginUser, NewUser};
|
||||
use pslink::queries;
|
||||
use pslink::ServerError;
|
||||
|
||||
#[instrument]
|
||||
fn redirect_builder(target: &str) -> HttpResponse {
|
||||
HttpResponse::SeeOther()
|
||||
.set(CacheControl(vec![
|
||||
@@ -34,6 +35,7 @@ fn redirect_builder(target: &str) -> HttpResponse {
|
||||
.body(format!("Redirect to {}", target))
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
fn detect_language(request: &HttpRequest) -> Result<String, ServerError> {
|
||||
let requested = parse_accepted_languages(
|
||||
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
|
||||
|
||||
#[instrument(skip(id, tera))]
|
||||
pub async fn index(
|
||||
tera: web::Data<Tera>,
|
||||
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
|
||||
#[instrument(skip(id, tera))]
|
||||
pub async fn index_users(
|
||||
tera: web::Data<Tera>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -98,6 +103,8 @@ pub async fn index_users(
|
||||
Ok(redirect_builder("/admin/login"))
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(id, tera))]
|
||||
pub async fn view_link_empty(
|
||||
tera: web::Data<Tera>,
|
||||
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
|
||||
}
|
||||
|
||||
#[instrument(skip(id, tera))]
|
||||
pub async fn view_link(
|
||||
tera: web::Data<Tera>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -145,6 +153,7 @@ pub async fn view_link(
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(id, tera))]
|
||||
pub async fn view_profile(
|
||||
tera: web::Data<Tera>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -172,6 +181,7 @@ pub async fn view_profile(
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(id, tera))]
|
||||
pub async fn edit_profile(
|
||||
tera: web::Data<Tera>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -198,6 +208,7 @@ pub async fn edit_profile(
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn process_edit_profile(
|
||||
data: web::Form<NewUser>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -211,6 +222,7 @@ pub async fn process_edit_profile(
|
||||
)))
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn download_png(
|
||||
id: Identity,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -235,6 +247,7 @@ pub async fn download_png(
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(id, tera))]
|
||||
pub async fn signup(
|
||||
tera: web::Data<Tera>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -255,6 +268,7 @@ pub async fn signup(
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn process_signup(
|
||||
data: web::Form<NewUser>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -269,6 +283,7 @@ pub async fn process_signup(
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn toggle_admin(
|
||||
data: web::Path<String>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -281,6 +296,7 @@ pub async fn toggle_admin(
|
||||
)))
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn set_language(
|
||||
data: web::Path<String>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -290,6 +306,7 @@ pub async fn set_language(
|
||||
Ok(redirect_builder("/admin/index/"))
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn login(
|
||||
tera: web::Data<Tera>,
|
||||
id: Identity,
|
||||
@@ -323,6 +340,7 @@ pub async fn login(
|
||||
Ok(HttpResponse::Ok().body(rendered))
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn process_login(
|
||||
data: web::Form<LoginUser>,
|
||||
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> {
|
||||
info!("Logging out the user");
|
||||
id.forget();
|
||||
Ok(redirect_builder("/admin/login/"))
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn redirect(
|
||||
tera: web::Data<Tera>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -390,12 +411,14 @@ pub async fn redirect(
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn redirect_empty(
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
) -> Result<HttpResponse, ServerError> {
|
||||
Ok(redirect_builder(&config.empty_forward_url))
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn create_link(
|
||||
tera: web::Data<Tera>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -416,6 +439,7 @@ pub async fn create_link(
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn process_link_creation(
|
||||
data: web::Form<LinkForm>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -428,6 +452,7 @@ pub async fn process_link_creation(
|
||||
)))
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn edit_link(
|
||||
tera: web::Data<Tera>,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
@@ -460,6 +485,7 @@ pub async fn process_link_edit(
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(id))]
|
||||
pub async fn process_link_delete(
|
||||
id: Identity,
|
||||
config: web::Data<pslink::ServerConfig>,
|
||||
|
||||
Reference in New Issue
Block a user