Swap out old log for shiny tracing

This commit is contained in:
Tyler Hallada 2020-07-27 22:36:48 -04:00
parent fb99afdc26
commit b16ba3e3f7
8 changed files with 259 additions and 172 deletions

404
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,8 +13,6 @@ dotenv = "0.15"
http-api-problem = { version = "0.17", features = ["with-warp"] }
hyper = "0.13"
listenfd = "0.3"
log = "0.4"
pretty_env_logger = "0.4"
tokio = { version = "0.2", features = ["macros"] }
sqlx = { version = "0.3", default-features = false, features = [ "runtime-tokio", "macros", "postgres", "chrono", "uuid", "ipnetwork", "json" ] }
warp = { version = "0.2", features = ["compression"] }
@ -27,3 +25,5 @@ uuid = { version = "0.8", features = ["serde", "v4"] }
ipnetwork = "0.16"
url = "2.1"
async-trait = "0.1"
tracing = "0.1"
tracing-subscriber = "0.2"

View File

@ -30,3 +30,5 @@
# Todo
* Make self-contained docker container that can run the app without any setup.
* Add rate-limiting per IP address. The `tower` crate has a service that might
be useful for this.

View File

@ -1,6 +1,3 @@
#[macro_use]
extern crate log;
use anyhow::Result;
use clap::Clap;
use dotenv::dotenv;
@ -10,6 +7,8 @@ use serde::Serialize;
use sqlx::postgres::PgPool;
use std::convert::Infallible;
use std::env;
use tracing::info;
use tracing_subscriber::fmt::format::FmtSpan;
use url::Url;
use warp::Filter;
@ -53,10 +52,12 @@ struct ErrorMessage {
#[tokio::main]
async fn main() -> Result<()> {
dotenv().ok();
if env::var_os("RUST_LOG").is_none() {
env::set_var("RUST_LOG", "shopkeeper=info");
}
pretty_env_logger::init();
let env_log_filter =
env::var("RUST_LOG").unwrap_or_else(|_| "warp=info,shopkeeper=info".to_owned());
tracing_subscriber::fmt()
.with_env_filter(env_log_filter)
.with_span_events(FmtSpan::CLOSE)
.init();
let opts: Opts = Opts::parse();
if opts.migrate {
@ -96,7 +97,7 @@ async fn main() -> Result<()> {
)
.recover(problem::unpack_problem)
.with(warp::compression::gzip())
.with(warp::log("shopkeeper"));
.with(warp::trace::request());
let svc = warp::service(routes);
let make_svc = hyper::service::make_service_fn(|_: _| {

View File

@ -4,6 +4,7 @@ use chrono::prelude::*;
use serde::{Deserialize, Serialize};
use sqlx::postgres::PgPool;
use sqlx::types::Json;
use tracing::debug;
use super::ListParams;
use super::Model;

View File

@ -4,6 +4,7 @@ use chrono::prelude::*;
use ipnetwork::IpNetwork;
use serde::{Deserialize, Serialize};
use sqlx::postgres::PgPool;
use tracing::debug;
use uuid::Uuid;
use super::ListParams;

View File

@ -3,6 +3,7 @@ use async_trait::async_trait;
use chrono::prelude::*;
use serde::{Deserialize, Serialize};
use sqlx::postgres::PgPool;
use tracing::debug;
use super::ListParams;
use super::Model;

View File

@ -1,4 +1,5 @@
use http_api_problem::HttpApiProblem;
use tracing::error;
use warp::http::StatusCode;
use warp::{reject, Rejection, Reply};