Kiểm tra integration log của Webhook
Cách webhook ghi log
Mỗi lần gửi webhook, WebhookServiceImpl tự động ghi log qua IntegrationLogService (async) với các thông tin:
| Trường | Giá trị |
|---|---|
code | WEBHOOK_{tenantId} (ví dụ: WEBHOOK_123) |
operation | WEBHOOK_SEND |
system | NEBULA |
status | SUCCESS hoặc FAILED |
request | Webhook config id, method, url, request body |
response | Response body (thành công) hoặc error message (thất bại) |
userId | tenantId (dạng String) |
Kiểm tra qua Admin API
Endpoint
POST /api/general/control/integration-log/filter
Các trường có thể filter
| Trường | Giá trị để filter webhook |
|---|---|
code | WEBHOOK_{tenantId} (ví dụ: WEBHOOK_123) |
integrationOperation | WEBHOOK_SEND |
integrationSystem | NEBULA |
integrationStatus | SUCCESS hoặc FAILED |
userId | tenantId |
Hỗ trợ pagination và sort (mặc định sort DESC theo id = mới nhất trước).
Endpoint xem chi tiết
GET /api/general/control/integration-log/detail/{id}
Kiểm tra bằng SQL
Tìm tất cả webhook log của một tenant
SELECT id, code, integration_status, request, response, created_date
FROM integration_log
WHERE code = 'WEBHOOK_123'
AND integration_operation = 'WEBHOOK_SEND'
ORDER BY created_date DESC
LIMIT 20;
Tìm webhook thất bại
SELECT id, code, request, response, created_date
FROM integration_log
WHERE integration_operation = 'WEBHOOK_SEND'
AND integration_status = 'FAILED'
ORDER BY created_date DESC
LIMIT 50;
Tìm webhook theo khoảng thời gian
SELECT id, code, integration_status, response, created_date
FROM integration_log
WHERE integration_operation = 'WEBHOOK_SEND'
AND created_date BETWEEN '2024-03-01' AND '2024-03-28'
ORDER BY created_date DESC;
Kiểm tra Webhook Execution
Bảng webhook_execution lưu chi tiết hơn integration log: URL, headers, request/response body, mã HTTP, số lần retry, lỗi, thời gian retry tiếp theo.
Các trường của WebhookExecution
| Trường | Kiểu | Mô tả |
|---|---|---|
id | Long | ID tự tăng |
tenant_id | Long | ID tenant |
webhook_id | Long | ID của TenantWebhook config |
url | String | URL đã gửi |
headers | Text (JSON) | Headers đã gửi (bao gồm auth) |
request_body | Text | Request body đã gửi |
status | Integer | 1=RETRY_FAILED, 2=SUCCESS, 3=FAILED, 4=RETRYING |
http_status_code | Integer | Mã HTTP nhận được |
response_body | Text | Response body nhận được |
last_error | String | Thông báo lỗi cuối cùng |
retry_count | Integer | Số lần đã retry |
max_retries | Integer | Số lần retry tối đa (mặc định 3) |
retry_policy | Integer | 1=EXPONENTIAL_BACKOFF, 2=IMMEDIATE |
next_execution_time | DateTime | Thời gian retry tiếp theo |
created_date | DateTime | Thời gian tạo |
Tìm execution theo tenant
SELECT id, url, status, http_status_code, retry_count, last_error, created_date
FROM webhook_execution
WHERE tenant_id = 123
ORDER BY created_date DESC
LIMIT 20;
Tìm execution thất bại chưa retry hết
SELECT id, tenant_id, url, status, retry_count, max_retries, next_execution_time, last_error
FROM webhook_execution
WHERE status = 1 -- RETRY_FAILED
ORDER BY next_execution_time ASC;
Tìm execution đang chờ retry (sắp được xử lý)
SELECT id, tenant_id, url, retry_count, next_execution_time
FROM webhook_execution
WHERE status = 1 -- RETRY_FAILED
AND next_execution_time <= NOW()
ORDER BY next_execution_time ASC
LIMIT 100;
Tìm execution thất bại vĩnh viễn
SELECT id, tenant_id, url, http_status_code, retry_count, last_error, created_date
FROM webhook_execution
WHERE status = 3 -- FAILED (hết retry)
ORDER BY created_date DESC
LIMIT 50;
Thống kê execution theo status
SELECT
CASE status
WHEN 1 THEN 'RETRY_FAILED'
WHEN 2 THEN 'SUCCESS'
WHEN 3 THEN 'FAILED'
WHEN 4 THEN 'RETRYING'
END AS status_name,
COUNT(*) AS total
FROM webhook_execution
WHERE tenant_id = 123
GROUP BY status;
So sánh Integration Log và Webhook Execution
| Integration Log | Webhook Execution | |
|---|---|---|
| Mục đích | Ghi log tổng quan | Theo dõi chi tiết từng lần gửi |
| Thông tin | Request/response dạng text | URL, headers, body, mã trạng thái, thông tin retry |
| Retry info | Không có | Có: retry_count, max_retries, next_execution_time |
| Dùng khi | Kiểm tra nhanh thành công/thất bại | Debug chi tiết, kiểm tra retry, xem response |