-
Notifications
You must be signed in to change notification settings - Fork 153
unification of events + clusters #1080
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
Changes from 10 commits
66b1850
c00cb73
54293cf
20b9a47
e404454
87f00ee
98bcc6c
ad4dc1b
62a2957
1b8749c
3675325
0814b4a
46a4eee
07360f6
a328ed7
712f06e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| use anyhow::Result; | ||
| use sqlx::PgPool; | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::db::events::EventSource; | ||
|
|
||
| #[derive(Debug, Clone, sqlx::FromRow)] | ||
| pub struct EventClusterConfig { | ||
| pub value_template: String, | ||
| } | ||
|
|
||
| /// Get event cluster config for a specific event name and project | ||
| pub async fn get_event_cluster_config( | ||
| pool: &PgPool, | ||
| project_id: Uuid, | ||
| event_name: &str, | ||
| source: EventSource, | ||
| ) -> Result<Option<EventClusterConfig>> { | ||
| let config = sqlx::query_as::<_, EventClusterConfig>( | ||
| r#" | ||
| SELECT value_template | ||
| FROM event_cluster_configs | ||
| WHERE project_id = $1 AND event_name = $2 AND source = $3 | ||
| "#, | ||
skull8888888 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| .bind(project_id) | ||
| .bind(event_name) | ||
| .bind(source.to_string()) | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .fetch_optional(pool) | ||
| .await?; | ||
|
|
||
| Ok(config) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,27 +10,43 @@ use crate::{ | |
|
|
||
| use crate::traces::utils::convert_any_value_to_json_value; | ||
|
|
||
| #[derive(Serialize, Deserialize, Clone, Debug)] | ||
| pub enum EventSource { | ||
| #[serde(rename = "code")] | ||
| Code, | ||
| #[serde(rename = "semantic")] | ||
| Semantic, | ||
| } | ||
skull8888888 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| impl std::fmt::Display for EventSource { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self { | ||
| EventSource::Code => write!(f, "code"), | ||
| EventSource::Semantic => write!(f, "semantic"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Deserialize, Serialize, Clone, Debug)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct Event { | ||
| pub id: Uuid, | ||
| pub span_id: Uuid, | ||
| pub project_id: Uuid, | ||
| pub created_at: DateTime<Utc>, | ||
| pub timestamp: DateTime<Utc>, | ||
| pub name: String, | ||
| pub attributes: Value, | ||
| pub trace_id: Uuid, | ||
| pub source: EventSource, | ||
| } | ||
|
|
||
| impl Event { | ||
| pub fn estimate_size_bytes(&self) -> usize { | ||
| // 16 bytes for id, | ||
| // 16 bytes for span_id, | ||
| // 16 bytes for project_id, | ||
| // 8 bytes for created_at, | ||
| // 8 bytes for timestamp, | ||
| return 16 + 16 + 16 + 8 + 8 + self.name.len() + estimate_json_size(&self.attributes); | ||
| return 16 + 16 + 16 + 8 + self.name.len() + estimate_json_size(&self.attributes); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Event size estimate missing new source fieldThe |
||
| } | ||
|
|
||
|
|
@@ -46,11 +62,11 @@ impl Event { | |
| id: Uuid::new_v4(), | ||
| span_id, | ||
| project_id, | ||
| created_at: Utc::now(), | ||
| timestamp: Utc.timestamp_nanos(event.time_unix_nano as i64), | ||
| name: event.name, | ||
| attributes: Value::Object(attributes), | ||
| trace_id, | ||
| source: EventSource::Code, | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
| use serde_json::Value; | ||
| use uuid::Uuid; | ||
|
|
||
| /// Semantic event definition with prompt and schema (from definition or template) | ||
| #[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] | ||
| pub struct SemanticEventDefinition { | ||
| pub id: Uuid, | ||
| pub name: String, | ||
| pub prompt: String, | ||
| pub structured_output_schema: Value, | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.