feat: add logging instrumentation
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Aravinth Manivannan 2022-12-29 01:45:47 +05:30
parent 4416027253
commit bbc00e7c3b
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
7 changed files with 30 additions and 13 deletions

24
Cargo.lock generated
View file

@ -762,11 +762,11 @@ dependencies = [
"derive_more",
"futures-util",
"lazy_static",
"log",
"pretty_env_logger",
"serde 1.0.143",
"serde_json",
"sqlx",
"tracing",
"url",
]
@ -2081,21 +2081,33 @@ dependencies = [
[[package]]
name = "tracing"
version = "0.1.36"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307"
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
dependencies = [
"cfg-if",
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.29"
name = "tracing-attributes"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7"
checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
dependencies = [
"once_cell",
]

View file

@ -15,7 +15,6 @@ actix-web = "4"
actix-web-httpauth = "0.8.0"
futures-util = { version = "0.3.17", default-features = false, features = ["std"] }
lazy_static = "1.4.0"
log = "0.4.17"
pretty_env_logger = "0.4.0"
serde = { version = "1", features=["derive"]}
actix-web-codegen-const-routes = { version = "0.1.0", tag = "0.1.0", git = "https://github.com/realaravinth/actix-web-codegen-const-routes" }
@ -27,6 +26,7 @@ url = { version = "2.2.2", features = ["serde"]}
serde_json = { version ="1", features = ["raw_value"]}
sqlx = { version = "0.6.1", features = [ "runtime-actix-rustls", "postgres", "time", "offline", "json"] }
clap = { vesrion = "3.2.20", features = ["derive"]}
tracing = { version = "0.1.37", features = ["log"] }
[build-dependencies]

View file

@ -102,6 +102,7 @@ impl From<FormSubmission> for FormSubmissionResp {
path = "API_V1_ROUTES.forms.get_all",
wrap = "HttpAuthentication::bearer(bearerauth)"
)]
#[tracing::instrument(name = "Get form submissions", skip(ctx))]
async fn list_all(
ctx: AppCtx,
payload: web::Json<Table>,
@ -120,6 +121,7 @@ async fn list_all(
}
#[actix_web_codegen_const_routes::post(path = "API_V1_ROUTES.forms.submit")]
#[tracing::instrument(name = "Upload form", skip(ctx, payload))]
async fn upload(
ctx: AppCtx,
query: web::Query<Table>,

View file

@ -47,6 +47,7 @@ pub mod routes {
/// emits build details of the bninary
#[actix_web_codegen_const_routes::get(path = "crate::API_V1_ROUTES.meta.build_details")]
#[tracing::instrument(name = "Get build details", skip(ctx))]
async fn build_details(ctx: AppCtx) -> impl Responder {
let build = BuildDetails {
version: VERSION,
@ -64,7 +65,8 @@ pub struct Health {
/// checks all components of the system
#[actix_web_codegen_const_routes::get(path = "crate::API_V1_ROUTES.meta.health")]
async fn health(ctx: crate::AppCtx) -> impl Responder {
#[tracing::instrument(name = "Get system health", skip(ctx))]
async fn health(ctx: AppCtx) -> impl Responder {
let mut resp_builder = HealthBuilder::default();
resp_builder.db(ctx.db.ping().await);

View file

@ -18,6 +18,7 @@ use std::sync::Arc;
use std::thread;
use argon2_creds::{Config, ConfigBuilder, PasswordPolicy};
use tracing::info;
//use crate::errors::ServiceResult;
use crate::db::*;
@ -54,9 +55,9 @@ impl Ctx {
#[allow(unused_variables)]
let init = thread::spawn(move || {
log::info!("Initializing credential manager");
info!("Initializing credential manager");
c.init();
log::info!("Initialized credential manager");
info!("Initialized credential manager");
});
//let db = match s.database.database_type {

View file

@ -20,7 +20,7 @@ use actix_web::http::StatusCode;
use actix_web::web::JsonConfig;
use actix_web::{error::InternalError, middleware, App, HttpServer};
use clap::{Parser, Subcommand};
use log::info;
use tracing::info;
use lazy_static::lazy_static;

View file

@ -19,9 +19,9 @@ use std::path::Path;
use config::{Config, ConfigError, Environment, File};
use derive_more::Display;
use log::warn;
use serde::Deserialize;
use serde::Serialize;
use tracing::warn;
use url::Url;
#[derive(Debug, Clone, Deserialize)]
@ -96,7 +96,7 @@ impl Settings {
} else if Path::new(ETC).exists() {
s.merge(File::with_name(ETC))?;
} else {
log::warn!("configuration file not found");
warn!("configuration file not found");
}
s.merge(Environment::with_prefix("LPFORMS").separator("_"))?;