1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-03 00:53:23 +00:00

[BEEEP][PM-255518] Use tracing for improved observability (#16321)

* [BEEEP][PM-255518] Use tracing for improved observability

* feedback dani-garcia: use DefaultVisitor

* set default log level

* convert printlns in objc crate

* convert printlns in autotype crate

* convert printlns in autostart crate

* convert printlns in core/password crate

* convert printlns in core/biometric crate

* convert printlns in napi crate

* convert log usage in macos provider crate

* convert existing log macros to tracing

* fix the cargo.toml sort lint errors

* Revert "fix the cargo.toml sort lint errors"

This reverts commit fd149ab697.

* fix the sort lint using correct cargo sort version

* feedback coltonhurst: more comments/clarity on behavior

* revert changes to ssh_agent
This commit is contained in:
neuronull
2025-09-22 09:56:23 -06:00
committed by GitHub
parent 3bbc6c564c
commit 3f14fdc62d
17 changed files with 226 additions and 73 deletions

View File

@@ -31,7 +31,6 @@ ed25519 = { workspace = true, features = ["pkcs8"] }
futures = { workspace = true }
homedir = { workspace = true }
interprocess = { workspace = true, features = ["tokio"] }
log = { workspace = true }
pin-project = { workspace = true }
pkcs8 = { workspace = true, features = ["alloc", "encryption", "pem"] }
rand = { workspace = true }
@@ -52,6 +51,7 @@ thiserror = { workspace = true }
tokio = { workspace = true, features = ["io-util", "sync", "macros", "net"] }
tokio-stream = { workspace = true, features = ["net"] }
tokio-util = { workspace = true, features = ["codec"] }
tracing = { workspace = true }
typenum = { workspace = true }
zeroizing-alloc = { workspace = true }

View File

@@ -1,5 +1,6 @@
use anyhow::Result;
use ashpd::desktop::background::Background;
use tracing::{error, info};
pub async fn set_autostart(autostart: bool, params: Vec<String>) -> Result<()> {
let request = if params.is_empty() {
@@ -10,11 +11,15 @@ pub async fn set_autostart(autostart: bool, params: Vec<String>) -> Result<()> {
match request.send().await.and_then(|r| r.response()) {
Ok(response) => {
println!("[ASHPD] Autostart enabled: {:?}", response);
info!(
response = ?response,
"[ASHPD] Autostart enabled");
Ok(())
}
Err(err) => {
println!("[ASHPD] Error enabling autostart: {}", err);
error!(
error = %err,
"[ASHPD] Error enabling autostart");
Err(anyhow::anyhow!("error enabling autostart {}", err))
}
}

View File

@@ -4,6 +4,7 @@ use anyhow::Result;
use base64::Engine;
use rand::RngCore;
use sha2::{Digest, Sha256};
use tracing::error;
use crate::biometric::{base64_engine, KeyMaterial, OsDerivedKey};
use zbus::Connection;
@@ -35,7 +36,7 @@ impl super::BiometricTrait for Biometric {
match result {
Ok(result) => Ok(result.is_authorized),
Err(e) => {
println!("polkit biometric error: {:?}", e);
error!( error = %e, "polkit biometric error");
Ok(false)
}
}

View File

@@ -5,21 +5,21 @@ use interprocess::local_socket::{
tokio::{prelude::*, Stream},
GenericFilePath, ToFsName,
};
use log::{error, info};
use tracing::{error, info};
pub async fn connect(
path: PathBuf,
send: tokio::sync::mpsc::Sender<String>,
mut recv: tokio::sync::mpsc::Receiver<String>,
) -> Result<(), Box<dyn std::error::Error>> {
info!("Attempting to connect to {}", path.display());
info!(?path, "Attempting to connect");
let name = path.as_os_str().to_fs_name::<GenericFilePath>()?;
let conn = Stream::connect(name).await?;
let mut conn = crate::ipc::internal_ipc_codec(conn);
info!("Connected to {}", path.display());
info!(?path, "Connected");
// This `connected` and the latter `disconnected` messages are the only ones that
// are sent from the Rust IPC code and not just forwarded from the desktop app.
@@ -46,7 +46,7 @@ pub async fn connect(
res = conn.next() => {
match res {
Some(Err(e)) => {
error!("Error reading from IPC server: {e}");
error!(error = %e, "Error reading from IPC server");
break;
}
None => {

View File

@@ -7,12 +7,12 @@ use futures::{SinkExt, StreamExt, TryFutureExt};
use anyhow::Result;
use interprocess::local_socket::{tokio::prelude::*, GenericFilePath, ListenerOptions};
use log::{error, info};
use tokio::{
io::{AsyncRead, AsyncWrite},
sync::{broadcast, mpsc},
};
use tokio_util::sync::CancellationToken;
use tracing::{error, info};
use super::MESSAGE_CHANNEL_BUFFER;
@@ -143,11 +143,11 @@ async fn listen_incoming(
client_id
);
tokio::spawn(future.map_err(|e| {
error!("Error handling connection: {}", e)
error!(error = %e, "Error handling connection")
}));
},
Err(e) => {
error!("Error accepting connection: {}", e);
error!(error = %e, "Error accepting connection");
break;
},
}
@@ -176,7 +176,7 @@ async fn handle_connection(
loop {
tokio::select! {
_ = cancel_token.cancelled() => {
info!("Client {client_id} cancelled.");
info!(client_id, "Client cancelled.");
break;
},
@@ -187,7 +187,7 @@ async fn handle_connection(
client_stream.send(msg.into()).await?;
},
Err(e) => {
info!("Error reading message: {}", e);
error!(error = %e, "Error reading message");
break;
}
}
@@ -199,7 +199,7 @@ async fn handle_connection(
result = client_stream.next() => {
match result {
Some(Err(e)) => {
info!("Error reading from client {client_id}: {e}");
error!(client_id, error = %e, "Error reading from client");
client_to_server_send.send(Message {
client_id,
@@ -209,7 +209,7 @@ async fn handle_connection(
break;
},
None => {
info!("Client {client_id} disconnected.");
info!(client_id, "Client disconnected.");
client_to_server_send.send(Message {
client_id,

View File

@@ -2,6 +2,7 @@ use crate::password::PASSWORD_NOT_FOUND;
use anyhow::{anyhow, Result};
use oo7::dbus::{self};
use std::collections::HashMap;
use tracing::info;
pub async fn get_password(service: &str, account: &str) -> Result<String> {
match get_password_new(service, account).await {
@@ -27,7 +28,7 @@ async fn get_password_new(service: &str, account: &str) -> Result<String> {
// forces to read via secret service; remvove after 2025.03
async fn get_password_legacy(service: &str, account: &str) -> Result<String> {
println!("falling back to get legacy {} {}", service, account);
info!("falling back to get legacy {} {}", service, account);
let svc = dbus::Service::new().await?;
let collection = svc.default_collection().await?;
let keyring = oo7::Keyring::DBus(collection);
@@ -38,10 +39,7 @@ async fn get_password_legacy(service: &str, account: &str) -> Result<String> {
match res {
Some(res) => {
let secret = res.secret().await?;
println!(
"deleting legacy secret service entry {} {}",
service, account
);
info!(service, account, "deleting legacy secret service entry",);
keyring.delete(&attributes).await?;
let secret_string = String::from_utf8(secret.to_vec())?;
set_password(service, account, &secret_string).await?;
@@ -77,7 +75,7 @@ pub async fn delete_password(service: &str, account: &str) -> Result<()> {
// seems to happen because we call [delete_password] many times when a forced
// de-auth occurs to clean up old keys.
if is_locked().await? {
println!("skipping deletion of old keys. OS keyring is locked.");
info!("skipping deletion of old keys. OS keyring is locked.");
return Ok(());
}
@@ -105,11 +103,11 @@ pub async fn is_locked() -> Result<bool> {
if let Some(item) = items.first() {
return match item.is_locked().await {
Ok(is_locked) => {
println!("OS keyring is locked = {is_locked}");
info!(is_locked, "OS keyring");
Ok(is_locked)
}
Err(_) => {
println!("OS keyring is unlocked");
info!("OS keyring is unlocked");
Ok(false)
}
};