Improve tracing, immediately stringify spantrace, remove join macros

This commit is contained in:
asonix 2022-12-13 23:36:40 -06:00
parent c15f591bc8
commit 430ebec810
8 changed files with 29 additions and 38 deletions

View file

@ -396,7 +396,6 @@ impl Config {
self.do_generate_url(kind).expect("Generated valid IRI") self.do_generate_url(kind).expect("Generated valid IRI")
} }
#[tracing::instrument(level = "debug", skip_all, fields(base_uri = tracing::field::debug(&self.base_uri), kind = tracing::field::debug(&kind)))]
fn do_generate_url(&self, kind: UrlKind) -> Result<IriString, Error> { fn do_generate_url(&self, kind: UrlKind) -> Result<IriString, Error> {
let iri = match kind { let iri = match kind {
UrlKind::Activity => FixedBaseResolver::new(self.base_uri.as_ref()) UrlKind::Activity => FixedBaseResolver::new(self.base_uri.as_ref())

View file

@ -37,7 +37,7 @@ impl ActorCache {
ActorCache { db } ActorCache { db }
} }
#[tracing::instrument(level = "debug" name = "Get Actor", skip_all, fields(id = id.to_string().as_str(), requests))] #[tracing::instrument(level = "debug" name = "Get Actor", skip_all, fields(id = id.to_string().as_str()))]
pub(crate) async fn get( pub(crate) async fn get(
&self, &self,
id: &IriString, id: &IriString,
@ -56,12 +56,8 @@ impl ActorCache {
#[tracing::instrument(level = "debug", name = "Add Connection", skip(self))] #[tracing::instrument(level = "debug", name = "Add Connection", skip(self))]
pub(crate) async fn add_connection(&self, actor: Actor) -> Result<(), Error> { pub(crate) async fn add_connection(&self, actor: Actor) -> Result<(), Error> {
let add_connection = self.db.add_connection(actor.id.clone()); self.db.add_connection(actor.id.clone()).await?;
let save_actor = self.db.save_actor(actor); self.db.save_actor(actor).await
tokio::try_join!(add_connection, save_actor)?;
Ok(())
} }
#[tracing::instrument(level = "debug", name = "Remove Connection", skip(self))] #[tracing::instrument(level = "debug", name = "Remove Connection", skip(self))]
@ -69,7 +65,7 @@ impl ActorCache {
self.db.remove_connection(actor.id.clone()).await self.db.remove_connection(actor.id.clone()).await
} }
#[tracing::instrument(level = "debug", name = "Fetch remote actor", skip_all, fields(id = id.to_string().as_str(), requests))] #[tracing::instrument(level = "debug", name = "Fetch remote actor", skip_all, fields(id = id.to_string().as_str()))]
pub(crate) async fn get_no_cache( pub(crate) async fn get_no_cache(
&self, &self,
id: &IriString, id: &IriString,

View file

@ -36,11 +36,9 @@ impl NodeCache {
#[tracing::instrument(level = "debug", name = "Get nodes", skip(self))] #[tracing::instrument(level = "debug", name = "Get nodes", skip(self))]
pub(crate) async fn nodes(&self) -> Result<Vec<Node>, Error> { pub(crate) async fn nodes(&self) -> Result<Vec<Node>, Error> {
let infos = self.db.connected_info(); let infos = self.db.connected_info().await?;
let instances = self.db.connected_instance(); let instances = self.db.connected_instance().await?;
let contacts = self.db.connected_contact(); let contacts = self.db.connected_contact().await?;
let (infos, instances, contacts) = tokio::try_join!(infos, instances, contacts)?;
let vec = self let vec = self
.db .db

View file

@ -10,7 +10,7 @@ use std::{convert::Infallible, fmt::Debug, io};
use tracing_error::SpanTrace; use tracing_error::SpanTrace;
pub(crate) struct Error { pub(crate) struct Error {
context: SpanTrace, context: String,
kind: ErrorKind, kind: ErrorKind,
} }
@ -53,7 +53,7 @@ where
{ {
fn from(error: T) -> Self { fn from(error: T) -> Self {
Error { Error {
context: SpanTrace::capture(), context: SpanTrace::capture().to_string(),
kind: error.into(), kind: error.into(),
} }
} }

View file

@ -80,7 +80,7 @@ impl Admin {
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
#[error("Failed authentication")] #[error("Failed authentication")]
pub(crate) struct Error { pub(crate) struct Error {
context: SpanTrace, context: String,
#[source] #[source]
kind: ErrorKind, kind: ErrorKind,
} }
@ -88,49 +88,49 @@ pub(crate) struct Error {
impl Error { impl Error {
fn invalid() -> Self { fn invalid() -> Self {
Error { Error {
context: SpanTrace::capture(), context: SpanTrace::capture().to_string(),
kind: ErrorKind::Invalid, kind: ErrorKind::Invalid,
} }
} }
fn missing_config() -> Self { fn missing_config() -> Self {
Error { Error {
context: SpanTrace::capture(), context: SpanTrace::capture().to_string(),
kind: ErrorKind::MissingConfig, kind: ErrorKind::MissingConfig,
} }
} }
fn missing_db() -> Self { fn missing_db() -> Self {
Error { Error {
context: SpanTrace::capture(), context: SpanTrace::capture().to_string(),
kind: ErrorKind::MissingDb, kind: ErrorKind::MissingDb,
} }
} }
fn bcrypt_verify(e: BcryptError) -> Self { fn bcrypt_verify(e: BcryptError) -> Self {
Error { Error {
context: SpanTrace::capture(), context: SpanTrace::capture().to_string(),
kind: ErrorKind::BCryptVerify(e), kind: ErrorKind::BCryptVerify(e),
} }
} }
fn bcrypt_hash(e: BcryptError) -> Self { fn bcrypt_hash(e: BcryptError) -> Self {
Error { Error {
context: SpanTrace::capture(), context: SpanTrace::capture().to_string(),
kind: ErrorKind::BCryptHash(e), kind: ErrorKind::BCryptHash(e),
} }
} }
fn parse_header(e: ParseError) -> Self { fn parse_header(e: ParseError) -> Self {
Error { Error {
context: SpanTrace::capture(), context: SpanTrace::capture().to_string(),
kind: ErrorKind::ParseHeader(e), kind: ErrorKind::ParseHeader(e),
} }
} }
fn canceled(_: BlockingError) -> Self { fn canceled(_: BlockingError) -> Self {
Error { Error {
context: SpanTrace::capture(), context: SpanTrace::capture().to_string(),
kind: ErrorKind::Canceled, kind: ErrorKind::Canceled,
} }
} }

View file

@ -36,10 +36,8 @@ pub(crate) async fn route(
.await? .await?
.into_inner(); .into_inner();
let is_allowed = state.db.is_allowed(actor.id.clone()); let is_allowed = state.db.is_allowed(actor.id.clone()).await?;
let is_connected = state.db.is_connected(actor.id.clone()); let is_connected = state.db.is_connected(actor.id.clone()).await?;
let (is_allowed, is_connected) = tokio::try_join!(is_allowed, is_connected)?;
if !is_allowed { if !is_allowed {
return Err(ErrorKind::NotAllowed(actor.id.to_string()).into()); return Err(ErrorKind::NotAllowed(actor.id.to_string()).into());
@ -54,7 +52,7 @@ pub(crate) async fn route(
} else if config.validate_signatures() { } else if config.validate_signatures() {
if let Some((verified, _)) = verified { if let Some((verified, _)) = verified {
if actor.public_key_id.as_str() != verified.key_id() { if actor.public_key_id.as_str() != verified.key_id() {
tracing::error!("Bad actor, more info: {:?}", input); tracing::error!("Actor signed with wrong key");
return Err(ErrorKind::BadActor( return Err(ErrorKind::BadActor(
actor.public_key_id.to_string(), actor.public_key_id.to_string(),
verified.key_id().to_owned(), verified.key_id().to_owned(),

View file

@ -24,18 +24,18 @@ struct Links {
links: Vec<Link>, links: Vec<Link>,
} }
#[tracing::instrument(name = "NodeInfo")] #[tracing::instrument(name = "NodeInfo", skip_all)]
pub(crate) async fn route( pub(crate) async fn route(
config: web::Data<Config>, config: web::Data<Config>,
state: web::Data<State>, state: web::Data<State>,
) -> web::Json<NodeInfo> { ) -> web::Json<NodeInfo> {
let (inboxes, blocks) = tokio::join!(state.db.inboxes(), async { let inboxes = state.db.inboxes().await;
if config.publish_blocks() {
let blocks = if config.publish_blocks() {
Some(state.db.blocks().await.unwrap_or_default()) Some(state.db.blocks().await.unwrap_or_default())
} else { } else {
None None
} };
});
let peers = inboxes let peers = inboxes
.unwrap_or_default() .unwrap_or_default()

View file

@ -5,7 +5,7 @@ use actix_web::{
}; };
#[allow(clippy::async_yields_async)] #[allow(clippy::async_yields_async)]
#[tracing::instrument(name = "Statistics")] #[tracing::instrument(name = "Statics")]
pub(crate) async fn route(filename: web::Path<String>) -> HttpResponse { pub(crate) async fn route(filename: web::Path<String>) -> HttpResponse {
if let Some(data) = StaticFile::get(&filename.into_inner()) { if let Some(data) = StaticFile::get(&filename.into_inner()) {
HttpResponse::Ok() HttpResponse::Ok()