补充 Raw 图片生成成功追踪

记录成功任务与输出数量
完善上游响应和失败阶段日志
This commit is contained in:
2026-09-08 23:25:47 +08:00
parent 6068eeda83
commit 65e73eee02
2 changed files with 31 additions and 3 deletions
+30 -2
View File
@@ -25,7 +25,9 @@ use crate::{
},
request_context::RequestContext,
state::AppState,
tracking::record_external_generation_run_after_success,
};
use time::OffsetDateTime;
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
@@ -66,8 +68,7 @@ pub(crate) async fn edit_raw_image(
let prepared = tokio::task::spawn_blocking(move || prepare_request(payload))
.await
.map_err(|error| {
AppError::from_status(StatusCode::INTERNAL_SERVER_ERROR)
.with_message(error.to_string())
AppError::from_status(StatusCode::INTERNAL_SERVER_ERROR).with_message(error.to_string())
})??;
let settings = require_openai_image_settings(&state)?.with_external_api_audit_context(
&request_context,
@@ -79,6 +80,17 @@ pub(crate) async fn edit_raw_image(
let request_id = request_context.request_id().to_string();
let points_cost = raw_image_edit_price(&state, prepared.width, prepared.height).await?;
let audit_settings = settings.clone();
let tracking_state = audit_settings.external_api_audit_state.clone();
let tracking_payload = json!({
"width": prepared.width,
"height": prepared.height,
"promptChars": prepared.prompt.chars().count(),
"hasMask": prepared.options.mask.is_some(),
"quality": prepared.options.quality.as_deref(),
"background": prepared.options.background.as_deref(),
"outputFormat": prepared.options.output_format.as_deref(),
});
let started_at_micros = (OffsetDateTime::now_utc().unix_timestamp_nanos() / 1_000) as i64;
let operation = async move {
let generated = match create_vector_engine_raw_image_edit(
&provider_settings,
@@ -95,6 +107,7 @@ pub(crate) async fn edit_raw_image(
return Err(map_platform_image_error(error));
}
};
let task_id = generated.task_id.clone();
let data = generated
.images
.into_iter()
@@ -102,6 +115,21 @@ pub(crate) async fn edit_raw_image(
b64_json: BASE64_STANDARD.encode(image.bytes),
})
.collect();
if let Some(state) = tracking_state.as_ref() {
record_external_generation_run_after_success(
state,
platform_image::VECTOR_ENGINE_PROVIDER,
"raw_image_edit",
"raw_image_edit",
tracking_payload,
started_at_micros,
true,
None,
Some(task_id),
Some(json!({ "imageCount": data.len() })),
)
.await;
}
Ok::<_, AppError>(RawImageEditResponse { data })
};
let result = with_editor_generation_durable_billing_boundary(
@@ -174,7 +174,7 @@ pub async fn create_vector_engine_raw_image_edit(
tracing::info!(
provider = VECTOR_ENGINE_PROVIDER,
endpoint = %url,
status,
status = status.as_u16(),
prompt_chars,
reference_image_count,
elapsed_ms = started_at.elapsed().as_millis() as u64,