Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ schemars = "1.2.1"

thiserror = "2.0.18"

tracing = { version = "0.1.44", optional = true }

Comment thread
seun-ja marked this conversation as resolved.
jsonwebtoken = "9.3.1"

[features]
tracing = ["dep:tracing"]

[dev-dependencies]
serial_test = "3.4.0"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

---

## Feature Flag

**`tracing`**: Enables tracing for logging request/response traces. It requires a `RUST_LOG` environment variable to be set.

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README states the tracing feature "requires a RUST_LOG environment variable". Since the crate does not configure a tracing subscriber, RUST_LOG is not required and won’t do anything unless the user sets up a subscriber with filtering (e.g., tracing-subscriber + EnvFilter). Please update this section to explain the need to initialize a subscriber and treat RUST_LOG as optional/config-dependent.

Suggested change
**`tracing`**: Enables tracing for logging request/response traces. It requires a `RUST_LOG` environment variable to be set.
**`tracing`**: Enables tracing instrumentation for request/response traces. To see tracing output, your application must initialize a tracing subscriber (for example, with `tracing-subscriber`). A `RUST_LOG` environment variable is not required by this crate itself; it is optional and only has an effect if your subscriber is configured to read environment-based filters (for example, via `tracing-subscriber::EnvFilter`).

Copilot uses AI. Check for mistakes.

## Contributing

Pull requests and issues are welcome! Please open an issue to discuss your ideas or report bugs.
Expand Down
8 changes: 8 additions & 0 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ impl AgentServer {
tarpc::serde_transport::tcp::listen(self.socket_addr, Json::default).await?;
listener.config_mut().max_frame_length(usize::MAX);

#[cfg(feature = "tracing")]
tracing::info!("Listening on: {}", listener.local_addr());

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AgentServer::run no longer prints the listening address when the tracing feature is disabled (previously println! ran unconditionally). This makes the default binary/library behavior less observable. Consider keeping a non-tracing fallback (e.g., println! under cfg(not(feature = "tracing"))) or emitting the message via a logging facade that works without requiring the tracing feature.

Suggested change
tracing::info!("Listening on: {}", listener.local_addr());
tracing::info!("Listening on: {}", listener.local_addr());
#[cfg(not(feature = "tracing"))]
println!("Listening on: {}", listener.local_addr());

Copilot uses AI. Check for mistakes.

#[cfg(not(feature = "tracing"))]
println!("Listening on: {}", listener.local_addr());

listener
Expand Down Expand Up @@ -73,6 +77,10 @@ pub(crate) trait AgentWorker {

impl AgentWorker for AgentServer {
/// Handles a user message by passing it to the completion provider and returning the response.
#[cfg_attr(
feature = "tracing",
tracing::instrument(name = "agent.message", skip(self, _context, user_message))
)]
async fn message(
self,
_context: ::tarpc::context::Context,
Comment thread
seun-ja marked this conversation as resolved.
Expand Down
4 changes: 4 additions & 0 deletions src/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use crate::error::Error;

/// JWT token decoder
/// Decodes a JWT token and returns the claims if valid.
#[cfg_attr(
feature = "tracing",
tracing::instrument(name = "jwt.decode", skip(token, hmac_secret))
)]
pub(crate) fn decode_jwt(token: &str, hmac_secret: &str) -> Result<Claims, Error> {
let validation = jsonwebtoken::Validation::new(Algorithm::HS256);

Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
//! Ok(())
//!}
//!```

//!
//! ## Feature Flags
//!
//! `tracing`: Enables `tracing` instrumentation for request/response traces.
//!
mod agent;
mod builder;
pub mod error;
Expand Down
4 changes: 4 additions & 0 deletions src/providers/ollama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ impl OllamaAI {

#[async_trait::async_trait]
impl CompletionProvider for OllamaAI {
#[cfg_attr(
feature = "tracing",
tracing::instrument(name = "ollama.chat", skip(self, prompt))
)]
async fn chat(&self, prompt: &str) -> Result<String, Error> {
let response = self.agent.prompt(prompt).await?;
Ok(response)
Expand Down
4 changes: 4 additions & 0 deletions src/providers/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ impl OpenAI {

#[async_trait::async_trait]
impl CompletionProvider for OpenAI {
#[cfg_attr(
feature = "tracing",
tracing::instrument(name = "openai.chat", skip(self, prompt))
)]
async fn chat(&self, prompt: &str) -> Result<String, Error> {
let response = self.agent.prompt(prompt).await?;
Ok(response)
Expand Down
Loading