Fix tracing subscriber after introducing Tokio-console (#8907)

We've also upgraded `Axum` in order to avoid having two versions of that
library in Collab (one due to Tokio-console).

Release Notes:

- N/A

---------

Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
Max Brunsfeld 2024-03-05 14:11:33 -08:00 committed by GitHub
parent 703c9655a0
commit b68a277b5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 75 additions and 118 deletions

View file

@ -22,8 +22,8 @@ anyhow.workspace = true
async-tungstenite = "0.16"
aws-config = { version = "1.1.5" }
aws-sdk-s3 = { version = "1.15.0" }
axum = { version = "0.5", features = ["json", "headers", "ws"] }
axum-extra = { version = "0.3", features = ["erased-json"] }
axum = { version = "0.6", features = ["json", "headers", "ws"] }
axum-extra = { version = "0.4", features = ["erased-json"] }
chrono.workspace = true
clock.workspace = true
clickhouse.workspace = true
@ -32,7 +32,6 @@ dashmap = "5.4"
envy = "0.4.2"
futures.workspace = true
hex.workspace = true
hyper = "0.14"
live_kit_server.workspace = true
log.workspace = true
nanoid = "0.4"
@ -59,8 +58,7 @@ toml.workspace = true
tower = "0.4"
tower-http = { workspace = true, features = ["trace"] }
tracing = "0.1.34"
tracing-log = "0.1.3"
tracing-subscriber = { version = "0.3.11", features = ["env-filter", "json"] }
tracing-subscriber = { version = "0.3.11", features = ["env-filter", "json", "registry", "tracing-log"] }
util.workspace = true
uuid.workspace = true

View file

@ -63,6 +63,8 @@ spec:
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 6669
protocol: TCP
livenessProbe:
httpGet:
path: /healthz

View file

@ -11,7 +11,7 @@ use crate::{
use anyhow::anyhow;
use axum::{
body::Body,
extract::{Path, Query},
extract::{self, Path, Query},
http::{self, Request, StatusCode},
middleware::{self, Next},
response::IntoResponse,
@ -26,7 +26,7 @@ use tower::ServiceBuilder;
pub use extensions::fetch_extensions_from_blob_store_periodically;
pub fn routes(rpc_server: Option<Arc<rpc::Server>>, state: Arc<AppState>) -> Router<Body> {
pub fn routes(rpc_server: Option<Arc<rpc::Server>>, state: Arc<AppState>) -> Router<(), Body> {
Router::new()
.route("/user", get(get_authenticated_user))
.route("/users/:id/access_tokens", post(create_access_token))
@ -176,8 +176,8 @@ async fn check_is_contributor(
}
async fn add_contributor(
Json(params): Json<AuthenticatedUserParams>,
Extension(app): Extension<Arc<AppState>>,
extract::Json(params): extract::Json<AuthenticatedUserParams>,
) -> Result<()> {
app.db
.add_contributor(

View file

@ -3,9 +3,12 @@ use std::sync::{Arc, OnceLock};
use anyhow::{anyhow, Context};
use aws_sdk_s3::primitives::ByteStream;
use axum::{
body::Bytes, headers::Header, http::HeaderName, routing::post, Extension, Router, TypedHeader,
body::Bytes,
headers::Header,
http::{HeaderMap, HeaderName, StatusCode},
routing::post,
Extension, Router, TypedHeader,
};
use hyper::{HeaderMap, StatusCode};
use serde::{Serialize, Serializer};
use sha2::{Digest, Sha256};
use telemetry_events::{
@ -81,8 +84,8 @@ impl Header for CloudflareIpCountryHeader {
pub async fn post_crash(
Extension(app): Extension<Arc<AppState>>,
body: Bytes,
headers: HeaderMap,
body: Bytes,
) -> Result<()> {
static CRASH_REPORTS_BUCKET: &str = "zed-crash-reports";

View file

@ -7,12 +7,12 @@ use anyhow::{anyhow, Context as _};
use aws_sdk_s3::presigning::PresigningConfig;
use axum::{
extract::{Path, Query},
http::StatusCode,
response::Redirect,
routing::get,
Extension, Json, Router,
};
use collections::HashMap;
use hyper::StatusCode;
use serde::{Deserialize, Serialize};
use std::{sync::Arc, time::Duration};
use time::PrimitiveDateTime;

View file

@ -43,8 +43,8 @@ impl From<axum::Error> for Error {
}
}
impl From<hyper::Error> for Error {
fn from(error: hyper::Error) -> Self {
impl From<axum::http::Error> for Error {
fn from(error: axum::http::Error) -> Self {
Self::Internal(error.into())
}
}

View file

@ -1,11 +1,10 @@
use anyhow::anyhow;
use axum::{extract::MatchedPath, routing::get, Extension, Router};
use axum::{extract::MatchedPath, http::Request, routing::get, Extension, Router};
use collab::{
api::fetch_extensions_from_blob_store_periodically, db, env, executor::Executor, AppState,
Config, MigrateConfig, Result,
};
use db::Database;
use hyper::Request;
use std::{
env::args,
net::{SocketAddr, TcpListener},
@ -16,8 +15,9 @@ use std::{
use tokio::signal::unix::SignalKind;
use tower_http::trace::{self, TraceLayer};
use tracing::Level;
use tracing_log::LogTracer;
use tracing_subscriber::{filter::EnvFilter, fmt::format::JsonFields, Layer};
use tracing_subscriber::{
filter::EnvFilter, fmt::format::JsonFields, util::SubscriberInitExt, Layer,
};
use util::ResultExt;
const VERSION: &str = env!("CARGO_PKG_VERSION");
@ -25,7 +25,6 @@ const REVISION: Option<&'static str> = option_env!("GITHUB_SHA");
#[tokio::main]
async fn main() -> Result<()> {
console_subscriber::init();
if let Err(error) = env::load_dotenv() {
eprintln!(
"error loading .env.toml (this is expected in production): {}",
@ -112,7 +111,8 @@ async fn main() -> Result<()> {
);
#[cfg(unix)]
axum::Server::from_tcp(listener)?
axum::Server::from_tcp(listener)
.map_err(|e| anyhow!(e))?
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.with_graceful_shutdown(async move {
let mut sigterm = tokio::signal::unix::signal(SignalKind::terminate())
@ -129,7 +129,8 @@ async fn main() -> Result<()> {
rpc_server.teardown();
}
})
.await?;
.await
.map_err(|e| anyhow!(e))?;
// todo("windows")
#[cfg(windows)]
@ -179,11 +180,11 @@ async fn handle_liveness_probe(Extension(state): Extension<Arc<AppState>>) -> Re
pub fn init_tracing(config: &Config) -> Option<()> {
use std::str::FromStr;
use tracing_subscriber::layer::SubscriberExt;
let rust_log = config.rust_log.clone()?;
LogTracer::init().log_err()?;
let filter = EnvFilter::from_str(config.rust_log.as_deref()?).log_err()?;
let subscriber = tracing_subscriber::Registry::default()
tracing_subscriber::registry()
.with(console_subscriber::spawn())
.with(if config.log_json.unwrap_or(false) {
Box::new(
tracing_subscriber::fmt::layer()
@ -193,17 +194,17 @@ pub fn init_tracing(config: &Config) -> Option<()> {
.json()
.flatten_event(true)
.with_span_list(true),
),
)
.with_filter(filter),
) as Box<dyn Layer<_> + Send + Sync>
} else {
Box::new(
tracing_subscriber::fmt::layer()
.event_format(tracing_subscriber::fmt::format().pretty()),
.event_format(tracing_subscriber::fmt::format().pretty())
.with_filter(filter),
)
})
.with(EnvFilter::from_str(rust_log.as_str()).log_err()?);
tracing::subscriber::set_global_default(subscriber).unwrap();
.init();
None
}

View file

@ -844,7 +844,7 @@ impl Header for AppVersionHeader {
}
}
pub fn routes(server: Arc<Server>) -> Router<Body> {
pub fn routes(server: Arc<Server>) -> Router<(), Body> {
Router::new()
.route("/rpc", get(handle_websocket_request))
.layer(