-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jean SIMARD <[email protected]> Signed-off-by: hamz2a <[email protected]>
- Loading branch information
1 parent
255cf0a
commit 63990f2
Showing
11 changed files
with
196 additions
and
23 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
editoast/migrations/2024-11-21-145205_create_stdcm_logs/down.sql
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 @@ | ||
DROP TABLE stdcm_logs; |
8 changes: 8 additions & 0 deletions
8
editoast/migrations/2024-11-21-145205_create_stdcm_logs/up.sql
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,8 @@ | ||
CREATE TABLE stdcm_logs ( | ||
id int8 PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, | ||
trace_id VARCHAR(32) UNIQUE NOT NULL, | ||
request jsonb NOT NULL, | ||
response jsonb NOT NULL, | ||
created timestamptz NOT NULL DEFAULT NOW(), | ||
user_id bigint REFERENCES authn_user ON DELETE CASCADE | ||
); |
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,54 @@ | ||
use chrono::DateTime; | ||
use chrono::Utc; | ||
use editoast_derive::Model; | ||
use editoast_models::DbConnection; | ||
use opentelemetry::trace::TraceContextExt; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
use tracing_opentelemetry::OpenTelemetrySpanExt; | ||
use utoipa::ToSchema; | ||
|
||
use crate::core::stdcm::Request; | ||
use crate::core::stdcm::Response; | ||
use crate::models::prelude::*; | ||
|
||
editoast_common::schemas! { | ||
StdcmLog, | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize, Model, ToSchema)] | ||
#[model(table = editoast_models::tables::stdcm_logs)] | ||
#[model(gen(ops = c))] | ||
pub struct StdcmLog { | ||
pub id: i64, | ||
pub trace_id: String, | ||
#[model(json)] | ||
pub request: Request, | ||
#[model(json)] | ||
pub response: Response, | ||
pub created: DateTime<Utc>, | ||
pub user_id: Option<i64>, | ||
} | ||
|
||
impl StdcmLog { | ||
pub async fn log( | ||
mut conn: DbConnection, | ||
request: Request, | ||
response: Response, | ||
user_id: Option<i64>, | ||
) { | ||
let trace_id = tracing::Span::current() | ||
.context() | ||
.span() | ||
.span_context() | ||
.trace_id(); | ||
let stdcm_log_changeset = StdcmLog::changeset() | ||
.trace_id(trace_id.to_string()) | ||
.request(request) | ||
.response(response.clone()) | ||
.user_id(user_id); | ||
if let Err(e) = stdcm_log_changeset.create(&mut conn).await { | ||
tracing::error!("Failed during log operation: {e}"); | ||
} | ||
} | ||
} |
Oops, something went wrong.