Skip to content

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
}

字段说明

字段类型必填说明
appKeystring应用唯一标识
eventsarray事件数组,最少 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

参数类型必填说明
appKeystring按应用筛选

Response

json
{
  "totals": {
    "events": 128,
    "errors": 12,
    "failedRequests": 3,
    "affectedUsers": 8,
    "issues": 5
  }
}

GET /api/issues

获取 Issue 列表。

Query Parameters

参数类型必填说明
appKeystring按应用筛选

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": [...]
}

Released under the MIT License.