Skip to content

Commit

Permalink
feat: set up tracing types & upload fake trace data (#1425)
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->


> [!IMPORTANT]
> Introduces a new tracing system for the BAML toolchain, adding modules
for handling trace events, updating dependencies, and including tests
for the new functionality.
> 
>   - **Behavior**:
> - Introduces tracing functionality with `TraceEvent`,
`TraceSpanStart`, `TraceSpanEnd`, and `TraceLog` in
`baml-types/src/tracing.rs`.
> - Adds `TraceEventUploadRequest` and `TraceEventUploadResponse` in
`baml-types/src/rpc/mod.rs` for handling trace event uploads.
> - Implements `TracerThread` in `btrace/src/tracer_thread.rs` to handle
trace event batching and uploading.
>   - **Modules**:
>     - Adds `tracing` and `rpc` modules to `baml-types`.
> - Adds `btrace` module with `TraceContext` and `InstrumentationScope`
in `btrace/src/lib.rs`.
>   - **Dependencies**:
> - Adds `tracing-core`, `time`, and `web-time` dependencies to
`baml-types` and `btrace`.
> - Updates `Cargo.toml` files to include new modules and dependencies.
>   - **Testing**:
> - Adds tests for tracing functionality in `btrace/tests.rs` using
`wasm-bindgen-test`.
>   - **Misc**:
> - Adds `sandbox` module with example usage of tracing in
`sandbox/src/main.rs` and `sandbox/src/upload-traces-main.rs`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for 1b80ae0. It will automatically
update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
sxlijin authored Feb 7, 2025
1 parent 19443b1 commit 3eebfc9
Show file tree
Hide file tree
Showing 15 changed files with 1,063 additions and 11 deletions.
52 changes: 50 additions & 2 deletions engine/Cargo.lock

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

21 changes: 15 additions & 6 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ members = [
"baml-runtime",
"baml-schema-wasm",
"bstd",
"btrace",
"cli",
"language_client_codegen",
"language_client_python",
"language_client_ruby/ext/ruby_ffi",
"language_client_typescript",
"sandbox",
]
default-members = [
"baml-lib/*",
Expand All @@ -20,6 +22,7 @@ default-members = [
# also have something to do with resolver=2 and how duplicate dep builds are handled)
# "baml-schema-wasm",
"bstd",
"btrace",
"cli",
"language_client_codegen",
"language_client_python",
Expand All @@ -32,8 +35,10 @@ anyhow = "1.0"
array-macro = "2"
askama = "0.12.1"
baml-cli = { path = "cli" }
baml-types = { path = "baml-lib/baml-types" }
base64 = "0.22.1"
bstd = { path = "bstd" }
btrace = { path = "btrace" }
bytes = "1.6.0"
cfg-if = "1.0.0"
clap = { version = "4.4.6", features = ["cargo", "derive"] }
Expand All @@ -47,6 +52,12 @@ http = "1.1.0"
http-body = "1.0.0"
indexmap = { version = "2.1.0", features = ["serde"] }
indoc = "2.0.5"
jsonish = { path = "baml-lib/jsonish" }
internal-baml-codegen = { path = "language_client_codegen" }
internal-baml-core = { path = "baml-lib/baml-core" }
internal-baml-jinja = { path = "baml-lib/jinja-runtime" }
internal-baml-schema-ast = { path = "baml-lib/schema-ast" }
internal-llm-client = { path = "baml-lib/llm-client" }
log = "0.4.20"
# TODO: disable imports, etc
minijinja = { version = "1.0.16", default-features = false, features = [
Expand All @@ -67,13 +78,14 @@ minijinja = { version = "1.0.16", default-features = false, features = [
# loader
#
] }
once_cell = "1"
pretty_assertions = "1.4.1"
rand = "0.8.5"
regex = "1.10.4"
reqwest = { version = "0.12.12", features = [
"json",
"native-tls-vendored",
"native-tls-alpn",
"native-tls-vendored",
"stream",
] }
scopeguard = "1.2.0"
Expand All @@ -84,16 +96,13 @@ static_assertions = "1.1.0"
strum = { version = "0.26.2", features = ["derive"] }
strum_macros = "0.26.2"
time = { version = "0.3.36", features = ["formatting"] }
tracing-core = { version = "0.1.31" }
pin-project-lite = "0.2.14"
url = "2.5.2"
uuid = { version = "1.8.0", features = ["v4", "v7", "serde"] }
walkdir = "2.5.0"
web-time = "1.1.0"

baml-types = { path = "baml-lib/baml-types" }
internal-baml-codegen = { path = "language_client_codegen" }
internal-baml-core = { path = "baml-lib/baml-core" }
internal-baml-jinja = { path = "baml-lib/jinja" }
internal-baml-schema-ast = { path = "baml-lib/schema-ast" }

[workspace.package]
version = "0.75.0"
Expand Down
11 changes: 8 additions & 3 deletions engine/baml-lib/baml-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ elided_named_lifetimes = "deny"
unused_imports = "deny"
unused_variables = "deny"

# Attention:
# Please try to keep this crate low-dependency! We want to keep this as minimal as possible.
[dependencies]
anyhow.workspace = true
clap.workspace = true
derive_builder.workspace = true
log.workspace = true
minijinja.workspace = true
once_cell.workspace = true
serde.workspace = true
serde_json.workspace = true
strum.workspace = true
minijinja.workspace = true
log.workspace = true
once_cell = "1"
time.workspace = true
tracing-core.workspace = true
web-time.workspace = true

[dependencies.indexmap]
workspace = true
Expand Down
2 changes: 2 additions & 0 deletions engine/baml-lib/baml-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ mod constraint;
mod map;
mod media;
mod minijinja;
pub mod rpc;
pub mod tracing;

mod baml_value;
mod field_type;
Expand Down
83 changes: 83 additions & 0 deletions engine/baml-lib/baml-types/src/rpc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};

use crate::tracing::TraceEventBatch;

// ------------------------------------------------------------------------------------------------

// TODO: version handling should be non-exhaustive for all of these
// clients need to say "i can only handle v1 responses"

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum BamlSrcUploadStatus {
Pending,
Completed,
Failed,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "version")]
pub enum GetBamlSrcUploadStatusRequest {
V1 {
project_id: String,
fingerprint: String,
},
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "version")]
pub enum GetBamlSrcUploadStatusResponse {
V1 {
project_id: String,
fingerprint: String,
status: BamlSrcUploadStatus,
},
}

// ------------------------------------------------------------------------------------------------

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "version")]
pub enum BamlSrcCreateUploadUrlRequest {
V1 {
project_id: String,
fingerprint: String,
},
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "version")]
pub enum BamlSrcCreateUploadUrlResponse {
V1 {
project_id: String,
fingerprint: String,
upload_url: String,
},
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "version")]
pub enum BamlSrcBlob {
V1 {
project_id: String,
fingerprint: String,
baml_src: IndexMap<String, String>,
},
}

// ------------------------------------------------------------------------------------------------

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "version")]
pub enum TraceEventUploadRequest {
V1 {
project_id: String,
trace_event_batch: TraceEventBatch,
},
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "version")]
pub enum TraceEventUploadResponse {
V1 { project_id: String },
}
Loading

0 comments on commit 3eebfc9

Please sign in to comment.