Add a connection-specific span to each API handler

This commit is contained in:
Nadja Reitzenstein 2022-06-24 12:25:52 +02:00
parent fac0a9ba94
commit 13bbe2bee9
3 changed files with 50 additions and 21 deletions

View File

@ -8,12 +8,14 @@ use crate::session::SessionManager;
use capnp::capability::Promise;
use capnp_rpc::pry;
use rsasl::mechname::Mechname;
use tracing::Span;
/// Cap'n Proto API Handler
pub struct BootCap {
peer_addr: SocketAddr,
authentication: AuthenticationHandle,
sessionmanager: SessionManager,
span: Span,
}
impl BootCap {
@ -21,12 +23,14 @@ impl BootCap {
peer_addr: SocketAddr,
authentication: AuthenticationHandle,
sessionmanager: SessionManager,
span: Span,
) -> Self {
tracing::trace!(%peer_addr, "bootstrapping RPC");
tracing::trace!(parent: &span, %peer_addr, "bootstrapping RPC");
Self {
peer_addr,
authentication,
sessionmanager,
span,
}
}
}

View File

@ -12,7 +12,7 @@ use futures_util::{stream, AsyncRead, AsyncWrite, FutureExt, StreamExt};
use std::future::Future;
use std::io;
use std::net::SocketAddr;
use std::net::{IpAddr, SocketAddr};
use crate::authentication::AuthenticationHandle;
use crate::session::SessionManager;
@ -145,12 +145,35 @@ impl APIServer {
peer_addr: SocketAddr,
stream: impl Future<Output = io::Result<TlsStream<IO>>>,
) {
tracing::debug!("handling new API connection");
let span = tracing::trace_span!("api.handle");
let _guard = span.enter();
struct Peer {
ip: IpAddr,
port: u16,
}
let peer = Peer {
ip: peer_addr.ip(),
port: peer_addr.port(),
};
tracing::debug!(
%peer.ip,
peer.port,
"spawning api handler"
);
let connection_span = tracing::info_span!(
"rpcsystem",
%peer.ip,
peer.port,
);
let f = async move {
tracing::trace!(parent: &connection_span, "starting tls exchange");
let stream = match stream.await {
Ok(stream) => stream,
Err(e) => {
tracing::error!("TLS handshake failed: {}", e);
Err(error) => {
tracing::error!(parent: &connection_span, %error, "TLS handshake failed");
return;
}
};
@ -161,10 +184,15 @@ impl APIServer {
peer_addr,
self.authentication.clone(),
self.sessionmanager.clone(),
connection_span.clone(),
));
if let Err(e) = RpcSystem::new(Box::new(vat), Some(bootstrap.client)).await {
tracing::error!("Error during RPC handling: {}", e);
if let Err(error) = RpcSystem::new(Box::new(vat), Some(bootstrap.client)).await {
tracing::error!(
parent: &connection_span,
%error,
"error occured during rpc handling",
);
}
};
let cgroup = SupervisionRegistry::with(SupervisionRegistry::new_group);

View File

@ -43,7 +43,7 @@ mod tls;
use std::sync::Arc;
use futures_util::StreamExt;
use futures_util::{FutureExt, StreamExt};
use miette::{Context, IntoDiagnostic, Report};
use once_cell::sync::OnceCell;
@ -94,20 +94,17 @@ impl Diflouroborane {
}
tracing::info!("Server is being spawned");
let handle = executor.spawn(server.serve());
std::thread::spawn(move || {
let result = async_io::block_on(handle);
match result {
Some(Ok(())) => {
tracing::info!("console server finished without error");
}
Some(Err(error)) => {
tracing::info!(%error, "console server finished with error");
}
None => {
tracing::info!("console server finished with panic");
}
executor.spawn(handle.map(|result| match result {
Some(Ok(())) => {
tracing::info!("console server finished without error");
}
});
Some(Err(error)) => {
tracing::info!(%error, "console server finished with error");
}
None => {
tracing::info!("console server finished with panic");
}
}));
let env = StateDB::open_env(&config.db_path)?;