diff --git a/Cargo.lock b/Cargo.lock index 4b95f22..6844e90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1260,6 +1260,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num_cpus" version = "1.15.0" @@ -1354,6 +1364,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1842,6 +1858,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + [[package]] name = "shellexpand" version = "2.1.2" @@ -1954,6 +1979,8 @@ dependencies = [ "tokio", "tower", "tower-http", + "tracing", + "tracing-subscriber", "utoipa", "utoipa-swagger-ui", "uuid", @@ -2012,6 +2039,16 @@ dependencies = [ "syn 2.0.18", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "time" version = "0.3.21" @@ -2188,9 +2225,21 @@ dependencies = [ "cfg-if", "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + [[package]] name = "tracing-core" version = "0.1.31" @@ -2198,6 +2247,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", ] [[package]] @@ -2348,6 +2423,12 @@ dependencies = [ "syn 2.0.18", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/crates/tabby/Cargo.toml b/crates/tabby/Cargo.toml index 33d572f..0e12ad1 100644 --- a/crates/tabby/Cargo.toml +++ b/crates/tabby/Cargo.toml @@ -19,6 +19,8 @@ tower-http = { version = "0.4.0", features = ["cors"] } clap = { version = "4.3.0", features = ["derive"] } regex = "1.8.3" lazy_static = "1.4.0" +tracing = "0.1.37" +tracing-subscriber = "0.3.17" [dependencies.uuid] version = "1.3.3" @@ -29,4 +31,4 @@ features = [ ] [features] -link_shared = [ "ctranslate2-bindings/link_shared" ] +link_shared = ["ctranslate2-bindings/link_shared"] diff --git a/crates/tabby/src/main.rs b/crates/tabby/src/main.rs index 7e3605e..f53870a 100644 --- a/crates/tabby/src/main.rs +++ b/crates/tabby/src/main.rs @@ -1,3 +1,6 @@ +use tracing::{info, Level}; +use tracing_subscriber; + use clap::{Parser, Subcommand}; #[derive(Parser)] @@ -18,10 +21,9 @@ mod serve; #[tokio::main] async fn main() { - let cli = Cli::parse(); + tracing_subscriber::fmt::init(); - // You can check for the existence of subcommands, and if found use their - // matches just as you would the top level cmd + let cli = Cli::parse(); match &cli.command { Commands::Serve(args) => { serve::main(args) diff --git a/crates/tabby/src/serve/completions.rs b/crates/tabby/src/serve/completions.rs index 99d9a24..82296d1 100644 --- a/crates/tabby/src/serve/completions.rs +++ b/crates/tabby/src/serve/completions.rs @@ -1,3 +1,4 @@ +use tracing::{span, info, Level}; use axum::{extract::State, Json}; use ctranslate2_bindings::{ TextInferenceEngine, TextInferenceEngineCreateOptions, TextInferenceOptionsBuilder, @@ -40,6 +41,11 @@ pub async fn completion( State(state): State>, Json(request): Json, ) -> Json { + let completion_id = format!("cmpl-{}", uuid::Uuid::new_v4()); + let span = span!(Level::INFO, "completion", completion_id); + let _enter = span.enter(); + + info!(language=request.language, prompt=request.prompt); let options = TextInferenceOptionsBuilder::default() .max_decoding_length(64) .sampling_temperature(0.2) @@ -47,9 +53,10 @@ pub async fn completion( .unwrap(); let text = state.engine.inference(&request.prompt, options); let filtered_text = languages::remove_stop_words(&request.language, &text); + info!(response=filtered_text); Json(CompletionResponse { - id: format!("cmpl-{}", uuid::Uuid::new_v4()), + id: completion_id, created: timestamp(), choices: [Choice { index: 0, diff --git a/crates/tabby/src/serve/events.rs b/crates/tabby/src/serve/events.rs index eb0b605..d9ec2dd 100644 --- a/crates/tabby/src/serve/events.rs +++ b/crates/tabby/src/serve/events.rs @@ -1,4 +1,5 @@ use axum::Json; +use tracing::{span, info, Level}; use hyper::StatusCode; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; @@ -17,6 +18,10 @@ pub struct LogEventRequest { request_body = LogEventRequest, )] pub async fn log_event(Json(request): Json) -> StatusCode { - println!("log_event: {:?}", request); + info!( + completion_id=request.completion_id, + event_type=request.event_type, + choice_index=request.choice_index + ); StatusCode::OK }