Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hellovai/tracing #1350

Draft
wants to merge 9 commits into
base: canary
Choose a base branch
from
Draft

hellovai/tracing #1350

wants to merge 9 commits into from

Conversation

hellovai
Copy link
Contributor

  • tracing impl for context
  • add new tracing client impl
  • stash everything
  • compile again
  • move tracing types around
  • one more
  • Merge latest
  • tracing WIP

Copy link

vercel bot commented Jan 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
baml ❌ Failed (Inspect) Jan 20, 2025 6:41pm

@entelligence-ai-reviews
Copy link

Walkthrough

This update enhances the project's tracing capabilities by introducing a new tracing module, adding necessary dependencies, and integrating these features across various components. Key changes include:

  • Dependency Updates: New dependencies like btrace and tracing-core have been added to support enhanced tracing and logging.
  • Module Enhancements: A new tracing module has been introduced to manage event definitions and storage.
  • Retry Policy: A CustomRetry policy has been implemented for the GPT4o client, allowing up to 3 retries.
  • Code Integration: Tracing functionalities have been integrated into the orchestrator and stream operations, improving maintainability and performance.

Changes

File(s) Summary
.mise.toml Updated the poetry version from 1.8.4 to 1.8.5.
engine/Cargo.lock, engine/Cargo.toml Added new dependencies btrace, tracing-core, and web-time. Updated tracing-core version to 0.1.33.
engine/baml-lib/baml-types/src/tracing/ Introduced a new module for tracing, including event definitions and storage management.
engine/baml-runtime/Cargo.toml, engine/baml-runtime/src/internal/llm_client/orchestrator/ Integrated btrace for tracing context and logging in orchestrator and stream operations.
engine/baml-lib/baml/tests/validation_files/prompt_fiddle_example.baml Added a CustomRetry policy with a maximum of 3 retries to the GPT4o client.
Entelligence.ai can learn from your feedback. Simply add 👍 / 👎 emojis to teach it your preferences. More shortcuts below

Emoji Descriptions:

  • ⚠️ Potential Issue - May require further investigation.
  • 🔒 Security Vulnerability - Fix to ensure system safety.
  • 💻 Code Improvement - Suggestions to enhance code quality.
  • 🔨 Refactor Suggestion - Recommendations for restructuring code.
  • ℹ️ Others - General comments and information.

Interact with the Bot:

  • Send a message or request using the format:
    @bot + *your message*
Example: @bot Can you suggest improvements for this code?
  • Help the Bot learn by providing feedback on its responses.
    @bot + *feedback*
Example: @bot Do not comment on `save_auth` function !

Comment on lines +13 to +31
// THESE ARE NOT CLONEABLE!!
pub struct LogEvent {
/*
* (span_id, content_span_id) is a unique identifier for a log event
* The query (span_id, *) gets all logs for a function call
*/

pub span_id: FunctionId,
pub content_span_id: ContentId,

// The chain of spans that lead to this log event
// Includes span_id at the last position (content_span_id is not included)
pub span_chain: Vec<FunctionId>,

// The timestamp of the log
pub timestamp: web_time::Instant,
// The content of the log
pub content: LogEventContent,
}

Choose a reason for hiding this comment

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

The LogEvent struct is missing Clone, PartialEq, and Hash traits which are needed for proper event tracking and comparison. Add these trait derivations.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// THESE ARE NOT CLONEABLE!!
pub struct LogEvent {
/*
* (span_id, content_span_id) is a unique identifier for a log event
* The query (span_id, *) gets all logs for a function call
*/
pub span_id: FunctionId,
pub content_span_id: ContentId,
// The chain of spans that lead to this log event
// Includes span_id at the last position (content_span_id is not included)
pub span_chain: Vec<FunctionId>,
// The timestamp of the log
pub timestamp: web_time::Instant,
// The content of the log
pub content: LogEventContent,
}
#[derive(Clone, PartialEq, Hash)]
pub struct LogEvent {
/*
* (span_id, content_span_id) is a unique identifier for a log event
* The query (span_id, *) gets all logs for a function call
*/
pub span_id: FunctionId,
pub content_span_id: ContentId,
// The chain of spans that lead to this log event
// Includes span_id at the last position (content_span_id is not included)
pub span_chain: Vec<FunctionId>,
// The timestamp of the log
pub timestamp: web_time::Instant,
// The content of the log
pub content: LogEventContent,
}

Comment on lines +38 to +39
let batch = TraceEventBatch { events };
let body = serde_json::to_string(&batch).unwrap();

Choose a reason for hiding this comment

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

Using unwrap() on serde_json::to_string() can panic if serialization fails. Should use proper error handling with ? operator.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let batch = TraceEventBatch { events };
let body = serde_json::to_string(&batch).unwrap();
let batch = TraceEventBatch { events };
let body = serde_json::to_string(&batch)?

Comment on lines +83 to +102
let client = reqwest::Client::new();
let start = Instant::now();

let request_body = GetSignedUrlRequest {
bucket: bucket.to_string(),
key: format!("{}/{}.json", key_prefix, uuid::Uuid::new_v4()),
};

eprintln!("Making POST request to URL: {}", lambda_url);
eprintln!(
"Request body: {}",
serde_json::to_string_pretty(&request_body)?
);

let response = client
.post(lambda_url)
.json(&request_body)
.send()
.await
.context("Failed to call lambda function")?;

Choose a reason for hiding this comment

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

Creating a new reqwest::Client for each request is inefficient. The client should be reused across requests by making it static or passing it as a parameter.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let client = reqwest::Client::new();
let start = Instant::now();
let request_body = GetSignedUrlRequest {
bucket: bucket.to_string(),
key: format!("{}/{}.json", key_prefix, uuid::Uuid::new_v4()),
};
eprintln!("Making POST request to URL: {}", lambda_url);
eprintln!(
"Request body: {}",
serde_json::to_string_pretty(&request_body)?
);
let response = client
.post(lambda_url)
.json(&request_body)
.send()
.await
.context("Failed to call lambda function")?;
let client = &CLIENT;
let start = Instant::now();
let request_body = GetSignedUrlRequest {
bucket: bucket.to_string(),
key: format!("{}/{}.json", key_prefix, uuid::Uuid::new_v4()),
};
eprintln!("Making POST request to URL: {}", lambda_url);
eprintln!(
"Request body: {}",
serde_json::to_string_pretty(&request_body)?
);
let response = client
.post(lambda_url)
.json(&request_body)
.send()
.await
.context("Failed to call lambda function")?

Comment on lines +9 to +16
let localset = tokio::task::LocalSet::new();
localset.spawn_local(async move {
if let Err(e) = run().await {
tracing::error!("server error: {}", e);
}
});

println!("shutting down server");

Choose a reason for hiding this comment

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

The localset is created but never executed with .await or run, causing the server to exit immediately after spawning the task. Fix by adding localset.await; after spawning.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let localset = tokio::task::LocalSet::new();
localset.spawn_local(async move {
if let Err(e) = run().await {
tracing::error!("server error: {}", e);
}
});
println!("shutting down server");
let localset = tokio::task::LocalSet::new();
localset.spawn_local(async move {
if let Err(e) = run().await {
tracing::error!("server error: {}", e);
}
});
localset.await;
println!("shutting down server");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants