Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 2b68c5f

Browse files
committed
add thread_id and repo_ref to analytics
1 parent fc62db0 commit 2b68c5f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

server/bleep/src/analytics.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::sync::Arc;
22

3-
use crate::state::{PersistedState, StateSource};
3+
use crate::{
4+
repo::RepoRef,
5+
state::{PersistedState, StateSource},
6+
};
47

58
use rudderanalytics::{
69
client::RudderAnalytics,
@@ -13,6 +16,8 @@ use tracing::{info, warn};
1316
#[derive(Debug, Clone)]
1417
pub struct QueryEvent {
1518
pub query_id: uuid::Uuid,
19+
pub thread_id: uuid::Uuid,
20+
pub repo_ref: Option<RepoRef>,
1621
pub data: EventData,
1722
}
1823

@@ -137,6 +142,8 @@ impl RudderHub {
137142
event: "openai query".to_owned(),
138143
properties: Some(json!({
139144
"query_id": ev.query_id,
145+
"thread_id": ev.thread_id,
146+
"repo_ref": ev.repo_ref.as_ref().map(ToString::to_string),
140147
"data": ev.data,
141148
"package_metadata": options.package_metadata,
142149
})),

server/bleep/src/webserver/answer.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(super) async fn handle(
6262
) -> super::Result<impl IntoResponse> {
6363
let query_id = uuid::Uuid::new_v4();
6464
let response = _handle(
65-
Query(params),
65+
Query(params.clone()),
6666
Extension(app.clone()),
6767
Extension(user.clone()),
6868
query_id,
@@ -74,6 +74,8 @@ pub(super) async fn handle(
7474
&user,
7575
&QueryEvent {
7676
query_id,
77+
thread_id: params.thread_id,
78+
repo_ref: Some(params.repo_ref.clone()),
7779
data: EventData::output_stage("error")
7880
.with_payload("status", err.status.as_u16())
7981
.with_payload("message", err.message()),
@@ -108,6 +110,7 @@ pub(super) async fn _handle(
108110
let ctx = AppContext::new(app, user)
109111
.map_err(|e| super::Error::user(e).with_status(StatusCode::UNAUTHORIZED))?
110112
.with_query_id(query_id)
113+
.with_thread_id(params.thread_id)
111114
.with_repo_ref(params.repo_ref.clone());
112115

113116
// confirm client compatibility with answer-api
@@ -1137,8 +1140,9 @@ impl Action {
11371140
struct AppContext {
11381141
app: Application,
11391142
llm_gateway: llm_gateway::Client,
1140-
query_id: uuid::Uuid,
11411143
user: User,
1144+
query_id: uuid::Uuid,
1145+
thread_id: uuid::Uuid,
11421146
repo_ref: Option<RepoRef>,
11431147
}
11441148

@@ -1151,8 +1155,9 @@ impl AppContext {
11511155
Ok(Self {
11521156
app,
11531157
llm_gateway,
1154-
query_id: uuid::Uuid::nil(),
11551158
user,
1159+
query_id: uuid::Uuid::nil(),
1160+
thread_id: uuid::Uuid::nil(),
11561161
repo_ref: None,
11571162
})
11581163
}
@@ -1162,6 +1167,11 @@ impl AppContext {
11621167
self
11631168
}
11641169

1170+
fn with_thread_id(mut self, thread_id: uuid::Uuid) -> Self {
1171+
self.thread_id = thread_id;
1172+
self
1173+
}
1174+
11651175
fn with_repo_ref(mut self, repo_ref: RepoRef) -> Self {
11661176
self.repo_ref = Some(repo_ref);
11671177
self
@@ -1180,6 +1190,8 @@ impl AppContext {
11801190
fn track_query(&self, data: EventData) {
11811191
let event = QueryEvent {
11821192
query_id: self.query_id,
1193+
thread_id: self.thread_id,
1194+
repo_ref: self.repo_ref.clone(),
11831195
data,
11841196
};
11851197
self.app.track_query(&self.user, &event);

0 commit comments

Comments
 (0)