Skip to content

Commit

Permalink
feat: support otel
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
zwpaper committed Dec 16, 2024
1 parent 81de67b commit 4a59782
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 48 deletions.
169 changes: 163 additions & 6 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 @@ -71,6 +71,11 @@ async-openai = "0.20"
tracing-test = "0.2"
clap = "4.3.0"
ratelimit = "0.10"
tracing-opentelemetry = "0.28.0"
opentelemetry = { version = "0.27.0", features = ["trace", "metrics"] }
opentelemetry_sdk = { version = "0.27.0", default-features = false, features = ["trace", "rt-tokio"] }
opentelemetry-otlp = { version = "0.27.0" }
opentelemetry-semantic-conventions = { version = "0.27.0", features = ["semconv_experimental"] }

[workspace.dependencies.uuid]
version = "1.3.3"
Expand Down
8 changes: 7 additions & 1 deletion crates/http-api-bindings/src/embedding/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use async_openai::{
};
use async_trait::async_trait;
use tabby_inference::Embedding;
use tracing::{info_span, Instrument};

pub struct OpenAIEmbeddingEngine {
client: async_openai::Client<OpenAIConfig>,
Expand Down Expand Up @@ -40,7 +41,12 @@ impl Embedding for OpenAIEmbeddingEngine {
user: None,
dimensions: None,
};
let resp = self.client.embeddings().create(request).await?;
let resp = self
.client
.embeddings()
.create(request)
.instrument(info_span!("embed_openai"))
.await?;
let data = resp
.data
.into_iter()
Expand Down
6 changes: 5 additions & 1 deletion crates/http-api-bindings/src/rate_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use futures::stream::BoxStream;
use leaky_bucket::RateLimiter;
use tabby_inference::{ChatCompletionStream, CompletionOptions, CompletionStream, Embedding};
use tokio::time::Duration;
use tracing::{info_span, Instrument};

fn new_rate_limiter(rpm: u64) -> RateLimiter {
let rps = (rpm as f64 / 60.0).ceil() as usize;
Expand All @@ -35,7 +36,10 @@ pub fn new_embedding(embedding: Box<dyn Embedding>, request_per_minute: u64) ->
impl Embedding for RateLimitedEmbedding {
async fn embed(&self, prompt: &str) -> anyhow::Result<Vec<f32>> {
self.rate_limiter.acquire(1).await;
self.embedding.embed(prompt).await
self.embedding
.embed(prompt)
.instrument(info_span!("rate_limit_embed"))
.await
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/tabby-index/src/code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tabby_common::{
};
use tabby_inference::Embedding;
use tokio::task::JoinHandle;
use tracing::warn;
use tracing::{info_span, warn, Instrument};

use self::intelligence::SourceCode;
use crate::{
Expand Down Expand Up @@ -126,7 +126,7 @@ async fn build_binarize_embedding_tokens(
embedding: Arc<dyn Embedding>,
body: &str,
) -> Result<Vec<String>> {
let embedding = match embedding.embed(body).await {
let embedding = match embedding.embed(body).instrument(info_span!("embed")).await {
Ok(x) => x,
Err(err) => {
bail!("Failed to embed chunk text: {}", err);
Expand Down
5 changes: 5 additions & 0 deletions crates/tabby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ strum = { workspace = true }
strfmt = "0.2.4"
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
tracing-opentelemetry.workspace = true
opentelemetry.workspace = true
opentelemetry_sdk.workspace = true
opentelemetry-otlp.workspace = true
opentelemetry-semantic-conventions.workspace = true
tantivy = { workspace = true }
anyhow = { workspace = true }
sysinfo = "0.29.8"
Expand Down
Loading

0 comments on commit 4a59782

Please sign in to comment.