diff options
| author | Christine Dodrill <me@christine.website> | 2020-10-02 18:36:57 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-02 18:36:57 -0400 |
| commit | fa13e57835e487d586024a2e065e8f4b30dc88cd (patch) | |
| tree | e62623fec8d1f3e376453cb33ad0e42b2019b589 /src/handlers | |
| parent | a6ee2e7e36e8e8fac6f7c5f452cd6a0a06790584 (diff) | |
| download | xesite-fa13e57835e487d586024a2e065e8f4b30dc88cd.tar.xz xesite-fa13e57835e487d586024a2e065e8f4b30dc88cd.zip | |
incorporate tracing instead of log (#222)
* incorporate tracing instead of log
* fix a test
* fix a test
Diffstat (limited to 'src/handlers')
| -rw-r--r-- | src/handlers/blog.rs | 20 | ||||
| -rw-r--r-- | src/handlers/feeds.rs | 7 | ||||
| -rw-r--r-- | src/handlers/gallery.rs | 3 | ||||
| -rw-r--r-- | src/handlers/mod.rs | 9 | ||||
| -rw-r--r-- | src/handlers/talks.rs | 3 |
5 files changed, 36 insertions, 6 deletions
diff --git a/src/handlers/blog.rs b/src/handlers/blog.rs index e494e04..fbc0c24 100644 --- a/src/handlers/blog.rs +++ b/src/handlers/blog.rs @@ -5,21 +5,26 @@ use crate::{ templates::{self, Html, RenderRucte}, }; use lazy_static::lazy_static; -use prometheus::{IntCounterVec, register_int_counter_vec, opts}; +use prometheus::{opts, register_int_counter_vec, IntCounterVec}; use std::sync::Arc; +use tracing::{error, instrument}; use warp::{http::Response, Rejection, Reply}; lazy_static! { - static ref HIT_COUNTER: IntCounterVec = - register_int_counter_vec!(opts!("blogpost_hits", "Number of hits to blogposts"), &["name"]) - .unwrap(); + static ref HIT_COUNTER: IntCounterVec = register_int_counter_vec!( + opts!("blogpost_hits", "Number of hits to blogposts"), + &["name"] + ) + .unwrap(); } +#[instrument(skip(state))] pub async fn index(state: Arc<State>) -> Result<impl Reply, Rejection> { let state = state.clone(); Response::builder().html(|o| templates::blogindex_html(o, state.blog.clone())) } +#[instrument(skip(state))] pub async fn series(state: Arc<State>) -> Result<impl Reply, Rejection> { let state = state.clone(); let mut series: Vec<String> = vec![]; @@ -36,6 +41,7 @@ pub async fn series(state: Arc<State>) -> Result<impl Reply, Rejection> { Response::builder().html(|o| templates::series_html(o, series)) } +#[instrument(skip(state))] pub async fn series_view(series: String, state: Arc<State>) -> Result<impl Reply, Rejection> { let state = state.clone(); let mut posts: Vec<Post> = vec![]; @@ -51,12 +57,14 @@ pub async fn series_view(series: String, state: Arc<State>) -> Result<impl Reply } if posts.len() == 0 { + error!("series not found"); Err(SeriesNotFound(series).into()) } else { Response::builder().html(|o| templates::series_posts_html(o, series, &posts)) } } +#[instrument(skip(state))] pub async fn post_view(name: String, state: Arc<State>) -> Result<impl Reply, Rejection> { let mut want: Option<Post> = None; @@ -69,7 +77,9 @@ pub async fn post_view(name: String, state: Arc<State>) -> Result<impl Reply, Re match want { None => Err(PostNotFound("blog".into(), name).into()), Some(post) => { - HIT_COUNTER.with_label_values(&[name.clone().as_str()]).inc(); + HIT_COUNTER + .with_label_values(&[name.clone().as_str()]) + .inc(); let body = Html(post.body_html.clone()); Response::builder().html(|o| templates::blogpost_html(o, post, body)) } diff --git a/src/handlers/feeds.rs b/src/handlers/feeds.rs index 752b08c..2022393 100644 --- a/src/handlers/feeds.rs +++ b/src/handlers/feeds.rs @@ -1,7 +1,8 @@ use crate::{app::State, templates}; use lazy_static::lazy_static; use prometheus::{opts, register_int_counter_vec, IntCounterVec}; -use std::{sync::Arc, io}; +use std::{io, sync::Arc}; +use tracing::instrument; use warp::{http::Response, Rejection, Reply}; lazy_static! { @@ -12,6 +13,7 @@ lazy_static! { .unwrap(); } +#[instrument(skip(state))] pub async fn jsonfeed(state: Arc<State>) -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["json"]).inc(); let state = state.clone(); @@ -26,6 +28,7 @@ pub enum RenderError { impl warp::reject::Reject for RenderError {} +#[instrument(skip(state))] pub async fn atom(state: Arc<State>) -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["atom"]).inc(); let state = state.clone(); @@ -41,6 +44,7 @@ pub async fn atom(state: Arc<State>) -> Result<impl Reply, Rejection> { .map_err(warp::reject::custom) } +#[instrument(skip(state))] pub async fn rss(state: Arc<State>) -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["rss"]).inc(); let state = state.clone(); @@ -56,6 +60,7 @@ pub async fn rss(state: Arc<State>) -> Result<impl Reply, Rejection> { .map_err(warp::reject::custom) } +#[instrument(skip(state))] pub async fn sitemap(state: Arc<State>) -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["sitemap"]).inc(); let state = state.clone(); diff --git a/src/handlers/gallery.rs b/src/handlers/gallery.rs index 2094ab2..ba3cba2 100644 --- a/src/handlers/gallery.rs +++ b/src/handlers/gallery.rs @@ -8,6 +8,7 @@ use lazy_static::lazy_static; use prometheus::{IntCounterVec, register_int_counter_vec, opts}; use std::sync::Arc; use warp::{http::Response, Rejection, Reply}; +use tracing::instrument; lazy_static! { static ref HIT_COUNTER: IntCounterVec = @@ -15,11 +16,13 @@ lazy_static! { .unwrap(); } +#[instrument(skip(state))] pub async fn index(state: Arc<State>) -> Result<impl Reply, Rejection> { let state = state.clone(); Response::builder().html(|o| templates::galleryindex_html(o, state.gallery.clone())) } +#[instrument(skip(state))] pub async fn post_view(name: String, state: Arc<State>) -> Result<impl Reply, Rejection> { let mut want: Option<Post> = None; diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 5c51352..d180a11 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -9,6 +9,7 @@ use warp::{ http::{Response, StatusCode}, Rejection, Reply, }; +use tracing::instrument; lazy_static! { static ref HIT_COUNTER: IntCounterVec = @@ -16,27 +17,32 @@ lazy_static! { .unwrap(); } +#[instrument] pub async fn index() -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["index"]).inc(); Response::builder().html(|o| templates::index_html(o)) } +#[instrument] pub async fn contact() -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["contact"]).inc(); Response::builder().html(|o| templates::contact_html(o)) } +#[instrument] pub async fn feeds() -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["feeds"]).inc(); Response::builder().html(|o| templates::feeds_html(o)) } +#[instrument(skip(state))] pub async fn resume(state: Arc<State>) -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["resume"]).inc(); let state = state.clone(); Response::builder().html(|o| templates::resume_html(o, Html(state.resume.clone()))) } +#[instrument(skip(state))] pub async fn patrons(state: Arc<State>) -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["patrons"]).inc(); let state = state.clone(); @@ -51,12 +57,14 @@ pub async fn patrons(state: Arc<State>) -> Result<impl Reply, Rejection> { } } +#[instrument(skip(state))] pub async fn signalboost(state: Arc<State>) -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["signalboost"]).inc(); let state = state.clone(); Response::builder().html(|o| templates::signalboost_html(o, state.signalboost.clone())) } +#[instrument] pub async fn not_found() -> Result<impl Reply, Rejection> { HIT_COUNTER.with_label_values(&["not_found"]).inc(); Response::builder().html(|o| templates::notfound_html(o, "some path".into())) @@ -109,6 +117,7 @@ lazy_static! { .unwrap(); } +#[instrument] pub async fn rejection(err: Rejection) -> Result<impl Reply, Infallible> { let path: String; let code; diff --git a/src/handlers/talks.rs b/src/handlers/talks.rs index 54f1e64..b64575c 100644 --- a/src/handlers/talks.rs +++ b/src/handlers/talks.rs @@ -8,6 +8,7 @@ use lazy_static::lazy_static; use prometheus::{IntCounterVec, register_int_counter_vec, opts}; use std::sync::Arc; use warp::{http::Response, Rejection, Reply}; +use tracing::instrument; lazy_static! { static ref HIT_COUNTER: IntCounterVec = @@ -15,11 +16,13 @@ lazy_static! { .unwrap(); } +#[instrument(skip(state))] pub async fn index(state: Arc<State>) -> Result<impl Reply, Rejection> { let state = state.clone(); Response::builder().html(|o| templates::talkindex_html(o, state.talks.clone())) } +#[instrument(skip(state))] pub async fn post_view(name: String, state: Arc<State>) -> Result<impl Reply, Rejection> { let mut want: Option<Post> = None; |
