Start moving from logging to tracing on collab server
Install some spans. Probably more work to do here. Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
2d9d30f74a
commit
1fe964ac16
8 changed files with 63 additions and 85 deletions
55
Cargo.lock
generated
55
Cargo.lock
generated
|
@ -474,7 +474,7 @@ dependencies = [
|
||||||
"cexpr",
|
"cexpr",
|
||||||
"clang-sys",
|
"clang-sys",
|
||||||
"clap 2.33.3",
|
"clap 2.33.3",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lazycell",
|
"lazycell",
|
||||||
"log",
|
"log",
|
||||||
|
@ -845,11 +845,10 @@ dependencies = [
|
||||||
"collections",
|
"collections",
|
||||||
"ctor",
|
"ctor",
|
||||||
"editor",
|
"editor",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"envy",
|
"envy",
|
||||||
"futures",
|
"futures",
|
||||||
"gpui",
|
"gpui",
|
||||||
"json_env_logger",
|
|
||||||
"language",
|
"language",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lipsum",
|
"lipsum",
|
||||||
|
@ -900,7 +899,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ctor",
|
"ctor",
|
||||||
"editor",
|
"editor",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"gpui",
|
"gpui",
|
||||||
"picker",
|
"picker",
|
||||||
|
@ -1349,7 +1348,7 @@ dependencies = [
|
||||||
"clock",
|
"clock",
|
||||||
"collections",
|
"collections",
|
||||||
"ctor",
|
"ctor",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"futures",
|
"futures",
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"gpui",
|
"gpui",
|
||||||
|
@ -1395,15 +1394,6 @@ dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "env_logger"
|
|
||||||
version = "0.7.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
|
|
||||||
dependencies = [
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_logger"
|
name = "env_logger"
|
||||||
version = "0.8.3"
|
version = "0.8.3"
|
||||||
|
@ -1485,7 +1475,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ctor",
|
"ctor",
|
||||||
"editor",
|
"editor",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"gpui",
|
"gpui",
|
||||||
"picker",
|
"picker",
|
||||||
|
@ -1889,7 +1879,7 @@ dependencies = [
|
||||||
"core-text",
|
"core-text",
|
||||||
"ctor",
|
"ctor",
|
||||||
"dhat",
|
"dhat",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"etagere",
|
"etagere",
|
||||||
"font-kit",
|
"font-kit",
|
||||||
"foreign-types",
|
"foreign-types",
|
||||||
|
@ -2341,18 +2331,6 @@ version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "41ee439ee368ba4a77ac70d04f14015415af8600d6c894dc1f11bd79758c57d5"
|
checksum = "41ee439ee368ba4a77ac70d04f14015415af8600d6c894dc1f11bd79758c57d5"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "json_env_logger"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4e2ec540ea0448b187d3a8b4a9f13e75527d06ef76b3a2baa1cd982aecb62ce2"
|
|
||||||
dependencies = [
|
|
||||||
"env_logger 0.7.1",
|
|
||||||
"kv-log-macro",
|
|
||||||
"log",
|
|
||||||
"serde_json",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kernel32-sys"
|
name = "kernel32-sys"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
@ -2372,15 +2350,6 @@ dependencies = [
|
||||||
"arrayvec 0.5.2",
|
"arrayvec 0.5.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "kv-log-macro"
|
|
||||||
version = "1.0.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f"
|
|
||||||
dependencies = [
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "language"
|
name = "language"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -2392,7 +2361,7 @@ dependencies = [
|
||||||
"clock",
|
"clock",
|
||||||
"collections",
|
"collections",
|
||||||
"ctor",
|
"ctor",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"futures",
|
"futures",
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"gpui",
|
"gpui",
|
||||||
|
@ -2559,7 +2528,7 @@ dependencies = [
|
||||||
"async-pipe",
|
"async-pipe",
|
||||||
"collections",
|
"collections",
|
||||||
"ctor",
|
"ctor",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"futures",
|
"futures",
|
||||||
"gpui",
|
"gpui",
|
||||||
"log",
|
"log",
|
||||||
|
@ -3162,7 +3131,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ctor",
|
"ctor",
|
||||||
"editor",
|
"editor",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"gpui",
|
"gpui",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"settings",
|
"settings",
|
||||||
|
@ -4632,7 +4601,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.7.1",
|
"arrayvec 0.7.1",
|
||||||
"ctor",
|
"ctor",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
"rand 0.8.3",
|
"rand 0.8.3",
|
||||||
]
|
]
|
||||||
|
@ -4749,7 +4718,7 @@ dependencies = [
|
||||||
"clock",
|
"clock",
|
||||||
"collections",
|
"collections",
|
||||||
"ctor",
|
"ctor",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"gpui",
|
"gpui",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
|
@ -5903,7 +5872,7 @@ dependencies = [
|
||||||
"dirs 3.0.1",
|
"dirs 3.0.1",
|
||||||
"easy-parallel",
|
"easy-parallel",
|
||||||
"editor",
|
"editor",
|
||||||
"env_logger 0.8.3",
|
"env_logger",
|
||||||
"file_finder",
|
"file_finder",
|
||||||
"fsevent",
|
"fsevent",
|
||||||
"futures",
|
"futures",
|
||||||
|
|
|
@ -25,7 +25,6 @@ base64 = "0.13"
|
||||||
envy = "0.4.2"
|
envy = "0.4.2"
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
json_env_logger = "0.1"
|
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
lipsum = { version = "0.8", optional = true }
|
lipsum = { version = "0.8", optional = true }
|
||||||
log = { version = "0.4.16", features = ["kv_unstable_serde"] }
|
log = { version = "0.4.16", features = ["kv_unstable_serde"] }
|
||||||
|
|
|
@ -81,8 +81,6 @@ spec:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: api
|
name: api
|
||||||
key: token
|
key: token
|
||||||
- name: LOG_JSON
|
|
||||||
value: "1"
|
|
||||||
- name: RUST_LOG
|
- name: RUST_LOG
|
||||||
value: ${RUST_LOG}
|
value: ${RUST_LOG}
|
||||||
- name: TRACE_LEVEL
|
- name: TRACE_LEVEL
|
||||||
|
|
|
@ -431,6 +431,12 @@ macro_rules! id_type {
|
||||||
self.0 as u64
|
self.0 as u64
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for $name {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
self.0.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,7 @@ impl AppState {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
if std::env::var("LOG_JSON").is_ok() {
|
|
||||||
json_env_logger::init();
|
|
||||||
} else {
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
}
|
|
||||||
|
|
||||||
if let Err(error) = env::load_dotenv() {
|
if let Err(error) = env::load_dotenv() {
|
||||||
log::error!(
|
log::error!(
|
||||||
|
|
|
@ -25,7 +25,6 @@ use axum::{
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{HashMap, HashSet};
|
||||||
use futures::{channel::mpsc, future::BoxFuture, FutureExt, SinkExt, StreamExt, TryStreamExt};
|
use futures::{channel::mpsc, future::BoxFuture, FutureExt, SinkExt, StreamExt, TryStreamExt};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use log::{as_debug, as_display};
|
|
||||||
use rpc::{
|
use rpc::{
|
||||||
proto::{self, AnyTypedEnvelope, EntityMessage, EnvelopedMessage, RequestMessage},
|
proto::{self, AnyTypedEnvelope, EntityMessage, EnvelopedMessage, RequestMessage},
|
||||||
Connection, ConnectionId, Peer, TypedEnvelope,
|
Connection, ConnectionId, Peer, TypedEnvelope,
|
||||||
|
@ -38,7 +37,7 @@ use std::{
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, Instant},
|
time::Duration,
|
||||||
};
|
};
|
||||||
use store::{Store, Worktree};
|
use store::{Store, Worktree};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
@ -47,12 +46,11 @@ use tokio::{
|
||||||
time::Sleep,
|
time::Sleep,
|
||||||
};
|
};
|
||||||
use tower::ServiceBuilder;
|
use tower::ServiceBuilder;
|
||||||
use tracing::{info_span, Instrument};
|
use tracing::{info_span, instrument, Instrument};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
type MessageHandler = Box<
|
type MessageHandler =
|
||||||
dyn Send + Sync + Fn(Arc<Server>, Box<dyn AnyTypedEnvelope>) -> BoxFuture<'static, Result<()>>,
|
Box<dyn Send + Sync + Fn(Arc<Server>, Box<dyn AnyTypedEnvelope>) -> BoxFuture<'static, ()>>;
|
||||||
>;
|
|
||||||
|
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
peer: Arc<Peer>,
|
peer: Arc<Peer>,
|
||||||
|
@ -161,7 +159,14 @@ impl Server {
|
||||||
"handle message",
|
"handle message",
|
||||||
payload_type = envelope.payload_type_name()
|
payload_type = envelope.payload_type_name()
|
||||||
);
|
);
|
||||||
(handler)(server, *envelope).instrument(span).boxed()
|
let future = (handler)(server, *envelope);
|
||||||
|
async move {
|
||||||
|
if let Err(error) = future.await {
|
||||||
|
tracing::error!(%error, "error handling message");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.instrument(span)
|
||||||
|
.boxed()
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
if prev_handler.is_some() {
|
if prev_handler.is_some() {
|
||||||
|
@ -238,12 +243,13 @@ impl Server {
|
||||||
pub fn handle_connection<E: Executor>(
|
pub fn handle_connection<E: Executor>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
addr: String,
|
address: String,
|
||||||
user_id: UserId,
|
user_id: UserId,
|
||||||
mut send_connection_id: Option<mpsc::Sender<ConnectionId>>,
|
mut send_connection_id: Option<mpsc::Sender<ConnectionId>>,
|
||||||
executor: E,
|
executor: E,
|
||||||
) -> impl Future<Output = ()> {
|
) -> impl Future<Output = ()> {
|
||||||
let mut this = self.clone();
|
let mut this = self.clone();
|
||||||
|
let span = info_span!("handle connection", %user_id, %address);
|
||||||
async move {
|
async move {
|
||||||
let (connection_id, handle_io, mut incoming_rx) = this
|
let (connection_id, handle_io, mut incoming_rx) = this
|
||||||
.peer
|
.peer
|
||||||
|
@ -258,6 +264,8 @@ impl Server {
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
tracing::info!(%user_id, %connection_id, %address, "connection opened");
|
||||||
|
|
||||||
if let Some(send_connection_id) = send_connection_id.as_mut() {
|
if let Some(send_connection_id) = send_connection_id.as_mut() {
|
||||||
let _ = send_connection_id.send(connection_id).await;
|
let _ = send_connection_id.send(connection_id).await;
|
||||||
}
|
}
|
||||||
|
@ -275,26 +283,22 @@ impl Server {
|
||||||
futures::pin_mut!(next_message);
|
futures::pin_mut!(next_message);
|
||||||
futures::select_biased! {
|
futures::select_biased! {
|
||||||
result = handle_io => {
|
result = handle_io => {
|
||||||
if let Err(err) = result {
|
if let Err(error) = result {
|
||||||
log::error!("error handling rpc connection {:?} - {:?}", addr, err);
|
tracing::error!(%error, "error handling I/O");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
message = next_message => {
|
message = next_message => {
|
||||||
if let Some(message) = message {
|
if let Some(message) = message {
|
||||||
let start_time = Instant::now();
|
|
||||||
let type_name = message.payload_type_name();
|
let type_name = message.payload_type_name();
|
||||||
log::info!(connection_id = connection_id.0, type_name = type_name; "rpc message received");
|
let span = tracing::info_span!("receive message", %user_id, %connection_id, %address, type_name);
|
||||||
|
async {
|
||||||
if let Some(handler) = this.handlers.get(&message.payload_type_id()) {
|
if let Some(handler) = this.handlers.get(&message.payload_type_id()) {
|
||||||
let notifications = this.notifications.clone();
|
let notifications = this.notifications.clone();
|
||||||
let is_background = message.is_background();
|
let is_background = message.is_background();
|
||||||
let handle_message = (handler)(this.clone(), message);
|
let handle_message = (handler)(this.clone(), message);
|
||||||
let handle_message = async move {
|
let handle_message = async move {
|
||||||
if let Err(err) = handle_message.await {
|
handle_message.await;
|
||||||
log::error!(connection_id = connection_id.0, type = type_name, error = as_display!(err); "rpc message error");
|
|
||||||
} else {
|
|
||||||
log::info!(connection_id = connection_id.0, type = type_name, duration = as_debug!(start_time.elapsed()); "rpc message handled");
|
|
||||||
}
|
|
||||||
if let Some(mut notifications) = notifications {
|
if let Some(mut notifications) = notifications {
|
||||||
let _ = notifications.send(()).await;
|
let _ = notifications.send(()).await;
|
||||||
}
|
}
|
||||||
|
@ -305,20 +309,21 @@ impl Server {
|
||||||
handle_message.await;
|
handle_message.await;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::warn!("unhandled message: {}", type_name);
|
tracing::error!("no message handler");
|
||||||
}
|
}
|
||||||
|
}.instrument(span).await;
|
||||||
} else {
|
} else {
|
||||||
log::info!(address = as_debug!(addr); "rpc connection closed");
|
tracing::info!(%user_id, %connection_id, %address, "connection closed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = this.sign_out(connection_id).await {
|
if let Err(error) = this.sign_out(connection_id).await {
|
||||||
log::error!("error signing out connection {:?} - {:?}", addr, err);
|
tracing::error!(%error, "error signing out");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}.instrument(span)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn sign_out(self: &mut Arc<Self>, connection_id: ConnectionId) -> Result<()> {
|
async fn sign_out(self: &mut Arc<Self>, connection_id: ConnectionId) -> Result<()> {
|
||||||
|
@ -854,6 +859,7 @@ impl Server {
|
||||||
Ok(proto::GetUsersResponse { users })
|
Ok(proto::GetUsersResponse { users })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(self, state, user_ids))]
|
||||||
fn update_contacts_for_users<'a>(
|
fn update_contacts_for_users<'a>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
state: &Store,
|
state: &Store,
|
||||||
|
|
|
@ -3,6 +3,7 @@ use anyhow::{anyhow, Result};
|
||||||
use collections::{BTreeMap, HashMap, HashSet};
|
use collections::{BTreeMap, HashMap, HashSet};
|
||||||
use rpc::{proto, ConnectionId};
|
use rpc::{proto, ConnectionId};
|
||||||
use std::{collections::hash_map, path::PathBuf};
|
use std::{collections::hash_map, path::PathBuf};
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
|
@ -81,6 +82,7 @@ pub struct LeftProject {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Store {
|
impl Store {
|
||||||
|
#[instrument(skip(self))]
|
||||||
pub fn add_connection(&mut self, connection_id: ConnectionId, user_id: UserId) {
|
pub fn add_connection(&mut self, connection_id: ConnectionId, user_id: UserId) {
|
||||||
self.connections.insert(
|
self.connections.insert(
|
||||||
connection_id,
|
connection_id,
|
||||||
|
@ -96,6 +98,7 @@ impl Store {
|
||||||
.insert(connection_id);
|
.insert(connection_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(self))]
|
||||||
pub fn remove_connection(
|
pub fn remove_connection(
|
||||||
&mut self,
|
&mut self,
|
||||||
connection_id: ConnectionId,
|
connection_id: ConnectionId,
|
||||||
|
|
|
@ -37,6 +37,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ResultExt {
|
pub trait ResultExt {
|
||||||
type Ok;
|
type Ok;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue