Collector API
HealthGuard Collector 提供 REST API 供 SDK 上报事件和 Dashboard 查询数据。
Base URL: http://your-collector-host:3100
POST /api/events/batch
事件批量上报接口。SDK 调用此接口上报采集到的事件。
Request
json
{
"appKey": "web_abc123",
"events": [
{
"eventId": "evt_xxx",
"appKey": "web_abc123",
"platform": "web",
"type": "error",
"timestamp": 1716192000000,
"sessionId": "session_xxx",
"anonymousId": "anon_xxx",
"sdkVersion": "0.1.0",
"errorType": "js",
"message": "Cannot read property 'foo' of undefined",
"stack": "...",
"fingerprint": "js:abc123",
"breadcrumbs": []
}
]
}Response
json
{
"accepted": 1
}字段说明
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
appKey | string | 是 | 应用唯一标识 |
events | array | 是 | 事件数组,最少 1 条,最多 50 条 |
POST /api/auth/register
用户注册。
Request
json
{
"email": "user@example.com",
"password": "your-password"
}Response
json
{
"token": "session_xxx",
"user": {
"id": "user_xxx",
"email": "user@example.com",
"createdAt": 1716192000000
}
}POST /api/auth/login
用户登录。
Request
同 /api/auth/register。
Response
同 /api/auth/register。
GET /api/auth/me
获取当前登录用户信息。
Headers
Authorization: Bearer <token>GET /api/apps
获取当前用户的应用列表。
Headers
Authorization: Bearer <token>POST /api/apps
创建新应用。
Headers
Authorization: Bearer <token>Request
json
{
"name": "My Web App",
"type": "web"
}GET /api/overview
获取数据概览。
Query Parameters
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
appKey | string | 否 | 按应用筛选 |
Response
json
{
"totals": {
"events": 128,
"errors": 12,
"failedRequests": 3,
"affectedUsers": 8,
"issues": 5
}
}GET /api/issues
获取 Issue 列表。
Query Parameters
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
appKey | string | 否 | 按应用筛选 |
GET /api/issues/:id
获取 Issue 详情。
Response
json
{
"issue": {
"id": "web_abc123:js:def456",
"appKey": "web_abc123",
"fingerprint": "js:def456",
"message": "Cannot read property 'foo' of undefined",
"errorType": "js",
"eventCount": 15,
"firstSeenAt": 1716100000000,
"lastSeenAt": 1716192000000
},
"events": [...]
}