(
&self,
inputs: Vec<NewApiBehaviorEventInput>,
)
| 422 | } |
| 423 | |
| 424 | pub async fn append_api_behavior_events( |
| 425 | &self, |
| 426 | inputs: Vec<NewApiBehaviorEventInput>, |
| 427 | ) -> Result<()> { |
| 428 | if inputs.is_empty() { |
| 429 | return Ok(()); |
| 430 | } |
| 431 | let _guard = self.api_behavior_gate.read().await; |
| 432 | let _file_guard = |
| 433 | acquire_table_access_file_lock(&self.api_behavior_table, TableAccessMode::Shared) |
| 434 | .await?; |
| 435 | let table = self.api_behavior_table().await?; |
| 436 | let now_ms = Utc::now().timestamp_millis(); |
| 437 | let records: Vec<ApiBehaviorRecord> = inputs |
| 438 | .into_iter() |
| 439 | .map(|input| ApiBehaviorRecord { |
| 440 | event_id: normalize_required_text(input.event_id, 96, "evt"), |
| 441 | occurred_at: input.occurred_at, |
| 442 | client_source: normalize_required_text(input.client_source, 24, "unknown"), |
| 443 | method: normalize_required_text(input.method, 16, "GET"), |
| 444 | path: normalize_required_text(input.path, 512, "/"), |
| 445 | query: normalize_text(input.query, 2048), |
| 446 | page_path: normalize_required_text(input.page_path, 512, "unknown"), |
| 447 | referrer: normalize_optional_text(input.referrer, 1024), |
| 448 | status_code: input.status_code.max(0), |
| 449 | latency_ms: input.latency_ms.max(0), |
| 450 | client_ip: normalize_required_text(input.client_ip, 64, "unknown"), |
| 451 | ip_region: normalize_required_text(input.ip_region, 128, "Unknown"), |
| 452 | ua_raw: normalize_optional_text(input.ua_raw, 1024), |
| 453 | device_type: normalize_required_text(input.device_type, 24, "unknown"), |
| 454 | os_family: normalize_required_text(input.os_family, 48, "unknown"), |
| 455 | browser_family: normalize_required_text(input.browser_family, 48, "unknown"), |
| 456 | request_id: normalize_required_text(input.request_id, 128, "unknown"), |
| 457 | trace_id: normalize_required_text(input.trace_id, 128, "unknown"), |
| 458 | created_at: now_ms, |
| 459 | updated_at: now_ms, |
| 460 | }) |
| 461 | .collect(); |
| 462 | append_api_behavior_records(&table, &records).await |
| 463 | } |
| 464 | |
| 465 | pub async fn list_api_behavior_events( |
| 466 | &self, |
no test coverage detected