diff --git a/bffhd/capnp/authenticationsystem.rs b/bffhd/capnp/authenticationsystem.rs index d530dc5..56b1530 100644 --- a/bffhd/capnp/authenticationsystem.rs +++ b/bffhd/capnp/authenticationsystem.rs @@ -1,6 +1,7 @@ use capnp::capability::Promise; use capnp::Error; use capnp_rpc::pry; +use rsasl::mechname::Mechname; use rsasl::property::AuthId; use rsasl::session::{Session, Step}; use std::fmt; @@ -23,8 +24,18 @@ pub struct Authentication { } impl Authentication { - pub fn new(session: Session, sessionmanager: SessionManager) -> Self { - let span = tracing::info_span!(target: TARGET, "Authentication",); + pub fn new( + parent: &Span, + mechanism: &Mechname, /* TODO: this is stored in session as well, get it out of there. */ + session: Session, + sessionmanager: SessionManager, + ) -> Self { + let span = tracing::info_span!( + target: TARGET, + parent: parent, + "Authentication", + mechanism = mechanism.as_str() + ); tracing::trace!( target: TARGET, parent: &span, @@ -121,7 +132,7 @@ impl AuthenticationSystem for Authentication { "Authentication didn't provide an authid as required".to_string(), ) })); - let session = pry!(manager.open(uid.as_ref()).ok_or_else(|| { + let session = pry!(manager.open(&self.span, uid.as_ref()).ok_or_else(|| { tracing::warn!(uid = uid.as_str(), "Failed to lookup the given user"); capnp::Error::failed("Failed to lookup the given user".to_string()) })); diff --git a/bffhd/capnp/connection.rs b/bffhd/capnp/connection.rs index 7506649..9595ed9 100644 --- a/bffhd/capnp/connection.rs +++ b/bffhd/capnp/connection.rs @@ -90,7 +90,7 @@ impl bootstrap::Server for BootCap { "mechanisms", ) .entered(); - tracing::trace!("method call"); + tracing::trace!(target: "bffh::api", "method call"); let builder = result.get(); let mechs: Vec<_> = self @@ -149,7 +149,7 @@ impl bootstrap::Server for BootCap { let mechname = Mechname::new(mechanism.as_bytes()); let auth = if let Ok(mechname) = mechname { if let Ok(session) = self.authentication.start(mechname) { - Authentication::new(session, self.sessionmanager.clone()) + Authentication::new(&self.span, mechname, session, self.sessionmanager.clone()) } else { Authentication::invalid_mechanism() } diff --git a/bffhd/capnp/mod.rs b/bffhd/capnp/mod.rs index 9dc3db1..70345f7 100644 --- a/bffhd/capnp/mod.rs +++ b/bffhd/capnp/mod.rs @@ -165,7 +165,7 @@ impl APIServer { let connection_span = tracing::info_span!( target: "bffh::api", - "Bootstrap", + "connection", %peer.ip, peer.port, ); diff --git a/bffhd/initiators/mod.rs b/bffhd/initiators/mod.rs index e4c9714..3e24f75 100644 --- a/bffhd/initiators/mod.rs +++ b/bffhd/initiators/mod.rs @@ -17,6 +17,7 @@ use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; +use tracing::Span; use url::Url; mod dummy; @@ -33,12 +34,17 @@ pub trait Initiator: Future { #[derive(Clone)] pub struct InitiatorCallbacks { + span: Span, resource: Resource, sessions: SessionManager, } impl InitiatorCallbacks { - pub fn new(resource: Resource, sessions: SessionManager) -> Self { - Self { resource, sessions } + pub fn new(span: Span, resource: Resource, sessions: SessionManager) -> Self { + Self { + span, + resource, + sessions, + } } pub async fn try_update(&mut self, session: SessionHandle, status: Status) { @@ -46,17 +52,19 @@ impl InitiatorCallbacks { } pub fn open_session(&self, uid: &str) -> Option { - self.sessions.open(uid) + self.sessions.open(&self.span, uid) } } pub struct InitiatorDriver { + span: Span, name: String, initiator: Box, } impl InitiatorDriver { pub fn new( + span: Span, name: String, params: &HashMap, resource: Resource, @@ -65,9 +73,13 @@ impl InitiatorDriver { where I: 'static + Initiator + Unpin + Send, { - let callbacks = InitiatorCallbacks::new(resource, sessions); + let callbacks = InitiatorCallbacks::new(span.clone(), resource, sessions); let initiator = Box::new(I::new(params, callbacks)?); - Ok(Self { name, initiator }) + Ok(Self { + span, + name, + initiator, + }) } } @@ -133,15 +145,22 @@ fn load_single( resource: Resource, sessions: &SessionManager, ) -> Option { + let span = tracing::info_span!( + "initiator", + name = %name, + module = %module_name, + ); tracing::info!(%name, %module_name, ?params, "Loading initiator"); let o = match module_name.as_ref() { "Dummy" => Some(InitiatorDriver::new::( + span, name.clone(), params, resource, sessions.clone(), )), "Process" => Some(InitiatorDriver::new::( + span, name.clone(), params, resource, diff --git a/bffhd/session/mod.rs b/bffhd/session/mod.rs index 8533640..87eb902 100644 --- a/bffhd/session/mod.rs +++ b/bffhd/session/mod.rs @@ -17,11 +17,12 @@ impl SessionManager { } // TODO: make infallible - pub fn open(&self, uid: impl AsRef) -> Option { + pub fn open(&self, parent: &Span, uid: impl AsRef) -> Option { let uid = uid.as_ref(); if let Some(user) = self.users.get_user(uid) { let span = tracing::info_span!( target: "bffh::api", + parent: parent, "session", uid = uid, );