feat: record external generation runs
This commit is contained in:
@@ -53,6 +53,55 @@ struct RouteTrackingSpec {
|
||||
scope_id: &'static str,
|
||||
}
|
||||
|
||||
pub async fn record_external_generation_run_after_success(
|
||||
state: &AppState,
|
||||
provider: &str,
|
||||
operation: &str,
|
||||
request_label: &str,
|
||||
request_payload: Value,
|
||||
started_at_micros: i64,
|
||||
success: bool,
|
||||
failure_reason: Option<String>,
|
||||
provider_request_id: Option<String>,
|
||||
result_payload: Option<Value>,
|
||||
) {
|
||||
let completed_at_micros = current_utc_micros();
|
||||
let duration_ms = completed_at_micros.saturating_sub(started_at_micros).max(0) / 1_000;
|
||||
let mut draft = TrackingEventDraft::new("external_generation_run", "external-generation");
|
||||
draft.scope_kind = RuntimeTrackingScopeKind::Module;
|
||||
draft.scope_id = provider.to_string();
|
||||
draft.metadata = json!({
|
||||
"runId": format!("external-generation-{}", Uuid::new_v4()),
|
||||
"provider": provider,
|
||||
"operation": operation,
|
||||
"requestLabel": request_label.trim(),
|
||||
"requestPayload": request_payload,
|
||||
"status": if success { "succeeded" } else { "failed" },
|
||||
"success": success,
|
||||
"failureReason": failure_reason,
|
||||
"providerRequestId": provider_request_id,
|
||||
"resultPayload": result_payload,
|
||||
"startedAtMicros": started_at_micros,
|
||||
"completedAtMicros": completed_at_micros,
|
||||
"durationMs": duration_ms,
|
||||
});
|
||||
|
||||
record_tracking_event_after_success(state, &external_generation_request_context(), draft).await;
|
||||
}
|
||||
|
||||
fn current_utc_micros() -> i64 {
|
||||
(OffsetDateTime::now_utc().unix_timestamp_nanos() / 1_000) as i64
|
||||
}
|
||||
|
||||
fn external_generation_request_context() -> RequestContext {
|
||||
RequestContext::new(
|
||||
format!("external-generation-{}", Uuid::new_v4()),
|
||||
"external generation run".to_string(),
|
||||
std::time::Duration::ZERO,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn record_route_tracking_event_after_success(
|
||||
state: &AppState,
|
||||
request_context: &RequestContext,
|
||||
|
||||
Reference in New Issue
Block a user