-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(err): store result of frame resolution (#26001)
- Loading branch information
1 parent
b7d772c
commit bdeae6f
Showing
18 changed files
with
507 additions
and
16 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
rust/.sqlx/query-1bb963ce083f26e4033cf1ad0b8e3aad574562e2c69eb7064ce6588ec7f9d080.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
rust/.sqlx/query-91db325f8239edad65b5c4adfcc219ac954ea792d5958d1bb44011835a518b53.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use chrono::{DateTime, Utc}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
use sqlx::Executor; | ||
use uuid::Uuid; | ||
|
||
use crate::error::Error; | ||
|
||
use super::Frame; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub struct ErrorTrackingStackFrame { | ||
pub raw_id: String, | ||
pub team_id: i32, | ||
pub created_at: DateTime<Utc>, | ||
pub symbol_set_id: Option<Uuid>, | ||
pub contents: Frame, | ||
pub resolved: bool, | ||
} | ||
|
||
impl ErrorTrackingStackFrame { | ||
pub fn new( | ||
raw_id: String, | ||
team_id: i32, | ||
symbol_set_id: Option<Uuid>, | ||
contents: Frame, | ||
resolved: bool, | ||
) -> Self { | ||
Self { | ||
raw_id, | ||
team_id, | ||
symbol_set_id, | ||
contents, | ||
resolved, | ||
created_at: Utc::now(), | ||
} | ||
} | ||
|
||
pub async fn save<'c, E>(&self, e: E) -> Result<(), Error> | ||
where | ||
E: Executor<'c, Database = sqlx::Postgres>, | ||
{ | ||
sqlx::query!( | ||
r#" | ||
INSERT INTO posthog_errortrackingstackframe (raw_id, team_id, created_at, symbol_set_id, contents, resolved, id) | ||
VALUES ($1, $2, $3, $4, $5, $6, $7) | ||
ON CONFLICT (raw_id, team_id) DO UPDATE SET | ||
created_at = $3, | ||
symbol_set_id = $4, | ||
contents = $5, | ||
resolved = $6 | ||
"#, | ||
self.raw_id, | ||
self.team_id, | ||
self.created_at, | ||
self.symbol_set_id, | ||
serde_json::to_value(&self.contents)?, | ||
self.resolved, | ||
Uuid::now_v7() | ||
).execute(e).await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn load<'c, E>(e: E, team_id: i32, raw_id: &str) -> Result<Option<Self>, Error> | ||
where | ||
E: Executor<'c, Database = sqlx::Postgres>, | ||
{ | ||
struct Returned { | ||
raw_id: String, | ||
team_id: i32, | ||
created_at: DateTime<Utc>, | ||
symbol_set_id: Option<Uuid>, | ||
contents: Value, | ||
resolved: bool, | ||
} | ||
let res = sqlx::query_as!( | ||
Returned, | ||
r#" | ||
SELECT raw_id, team_id, created_at, symbol_set_id, contents, resolved | ||
FROM posthog_errortrackingstackframe | ||
WHERE raw_id = $1 AND team_id = $2 | ||
"#, | ||
raw_id, | ||
team_id | ||
) | ||
.fetch_optional(e) | ||
.await?; | ||
|
||
let Some(found) = res else { | ||
return Ok(None); | ||
}; | ||
|
||
Ok(Some(Self { | ||
raw_id: found.raw_id, | ||
team_id: found.team_id, | ||
created_at: found.created_at, | ||
symbol_set_id: found.symbol_set_id, | ||
contents: serde_json::from_value(found.contents)?, | ||
resolved: found.resolved, | ||
})) | ||
} | ||
} |
Oops, something went wrong.