跳到正文

错误追踪

捕获错误与异常并按问题分组、检索与解决——Sentry 风格的错误监控。

概览

基础路径: https://api.infrai.cc/v1/errors
鉴权头: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/errors capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/errors/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

方法

errors.capture

POST /v1/errors/capture

捕获应用错误,可选标签。

参数

名称类型必填说明
messagestring
必填
可读的错误消息。
codestring可选可选的应用错误码。
stackstring可选可选的堆栈跟踪。
tagsRecord<string, string>可选用于分组的键/值标签。

返回

{ ok, error_id }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/errors/capture \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"exception": {"type": "ValueError", "message": "bad input", "stacktrace": "..."}, "level": "error"}'

errors.message

POST /v1/errors/message

上报一条结构化错误或日志消息

参数

名称类型必填说明
textstring
必填
消息正文
level'debug' | 'info' | 'warning' | 'error' | 'fatal'可选级别:debug/info/warning/error/fatal
tagsRecord<string, string>可选键值标签,便于过滤与分组
user_idstring可选关联的用户 ID
releasestring可选发布版本标识
environment'production' | 'staging' | 'development'可选环境:production/staging/development
idempotency_keystring可选幂等键,用于避免重复写入

返回

CaptureResult

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/errors/message \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "..."}'

errors.list

GET /v1/errors/list

分页列出捕获到的错误事件

参数

名称类型必填说明
filterRecord<string, unknown>可选过滤条件(观测过滤 DSL)
cursorstring可选分页游标
limitnumber可选每页返回数量

返回

ErrorEventList

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/errors/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

errors.search

GET /v1/errors/search

按关键词搜索错误事件

参数

名称类型必填说明
qstring
必填
搜索关键词
filterRecord<string, unknown>可选过滤条件(观测过滤 DSL)
cursorstring可选分页游标
limitnumber可选每页返回数量

返回

ErrorEventList

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/errors/search \
  -H "Authorization: Bearer $INFRAI_API_KEY"

errors.get

GET /v1/errors/get/{event_id}

按事件 ID 获取错误事件详情

参数

名称类型必填说明
event_idstring
必填
错误事件 ID

返回

ErrorEvent

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/errors/get/EVENT_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

errors.groups

GET /v1/errors/groups

分页列出错误分组

参数

名称类型必填说明
status'unresolved' | 'resolved' | 'ignored'可选按状态过滤:unresolved/resolved/ignored
sort'count_desc' | 'last_seen_desc' | 'first_seen_desc'可选排序方式:count_desc/last_seen_desc/first_seen_desc
cursorstring可选分页游标
limitnumber可选每页返回数量

返回

ErrorGroupList

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/errors/groups \
  -H "Authorization: Bearer $INFRAI_API_KEY"

errors.group_detail

GET /v1/errors/group_detail/{error_group_id}

获取错误分组的聚合详情

参数

名称类型必填说明
error_group_idstring
必填
错误分组 ID

返回

ErrorGroupDetail

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/errors/group_detail/ERROR_GROUP_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

errors.events

GET /v1/errors/events/{error_group_id}

列出某错误分组下的事件

参数

名称类型必填说明
error_group_idstring
必填
错误分组 ID
cursorstring可选分页游标
limitnumber可选每页返回数量

返回

ErrorEventList

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/errors/events/ERROR_GROUP_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

errors.resolve

POST /v1/errors/resolve/{error_group_id}

将错误分组标记为已解决

参数

名称类型必填说明
error_group_idstring
必填
错误分组 ID

返回

ErrorGroup

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/errors/resolve/ERROR_GROUP_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"error_group_id": "..."}'

errors.unresolve

POST /v1/errors/unresolve/{error_group_id}

撤销错误分组的已解决状态

参数

名称类型必填说明
error_group_idstring
必填
错误分组 ID

返回

ErrorGroup

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/errors/unresolve/ERROR_GROUP_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"error_group_id": "..."}'

errors.ignore

POST /v1/errors/ignore/{error_group_id}

将错误分组标记为忽略

参数

名称类型必填说明
error_group_idstring
必填
错误分组 ID

返回

ErrorGroup

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/errors/ignore/ERROR_GROUP_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"error_group_id": "..."}'

errors.delete

DELETE /v1/errors/delete/{error_group_id}

删除错误分组

参数

名称类型必填说明
error_group_idstring
必填
错误分组 ID

返回

DeleteResult

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X DELETE https://api.infrai.cc/v1/errors/delete/ERROR_GROUP_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

errors.bulk

POST /v1/errors/bulk

对多个错误分组批量执行操作

参数

名称类型必填说明
error_group_idsstring[]
必填
目标错误分组 ID 列表
action'resolve' | 'unresolve' | 'ignore' | 'delete'
必填
批量动作:resolve/unresolve/ignore/delete

返回

ErrorBulkResult

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/errors/bulk \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"error_group_ids": [], "action": "resolve"}'

errors.export

POST /v1/errors/export

导出错误数据

参数

名称类型必填说明
filterRecord<string, unknown>可选过滤条件(观测过滤 DSL)
format'json' | 'csv'可选导出格式:json 或 csv

返回

ErrorExportResult

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/errors/export \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'

errors.retention.get

GET /v1/errors/retention/get

查询错误数据保留期配置

返回

{ days, auto_export_before_cleanup, export_destination }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/errors/retention/get \
  -H "Authorization: Bearer $INFRAI_API_KEY"

errors.retention.set

PUT /v1/errors/retention/set

设置错误数据保留期

参数

名称类型必填说明
daysnumber
必填
保留天数
auto_export_before_cleanupboolean可选清理前是否自动导出
export_destinationstring可选导出目标地址

返回

{ days, auto_export_before_cleanup, export_destination }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X PUT https://api.infrai.cc/v1/errors/retention/set \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"days": 0}'

全部能力

本模块全部已路由能力——完整的对外 REST 契约。上方方法是带讲解的入门示例,此表是完整参考。

能力端点说明
errors.bulkPOST /v1/errors/bulkBulk-apply resolve/ignore/delete and other actions across multiple error groups.
errors.capturePOST /v1/errors/captureCapture an error event, aggregated into a group by fingerprint.
errors.deleteDELETE /v1/errors/delete/{error_group_id}Delete a specified error group.
errors.eventsGET /v1/errors/events/{error_group_id}Page through all events within an error group.
errors.exportPOST /v1/errors/exportExport error data matching the filters (JSON or CSV).
errors.getGET /v1/errors/get/{event_id}Get the details of one error event by event ID.
errors.group_detailGET /v1/errors/group_detail/{error_group_id}Get the aggregated details of a specified error group.
errors.groupsGET /v1/errors/groupsPage through error groups, with status filtering and sorting.
errors.ignorePOST /v1/errors/ignore/{error_group_id}Mark an error group as ignored.
errors.listGET /v1/errors/listPage through captured error events, with filtering.
errors.messagePOST /v1/errors/messageCapture a structured error/log message (level, tags, user, release, environment).
errors.resolvePOST /v1/errors/resolve/{error_group_id}Mark an error group as resolved.
errors.retention.getGET /v1/errors/retention/getGet the retention-period configuration for error data.
errors.retention.setPUT /v1/errors/retention/setSet the retention period for error data, with auto-export before purge.
errors.searchGET /v1/errors/searchFull-text search error events by keyword.
errors.unresolvePOST /v1/errors/unresolve/{error_group_id}Revert an error group's resolved status.

完整示例

本模块的生产级端到端范例:先一次性配置,再运行业务流程,尽量覆盖本模块的多数 API。

单文件可运行 Python 程序(仅标准库、无 SDK):拷贝后填入 INFRAI_API_KEY 运行,即可按真实业务流逐步体验本模块核心 API——每一步都真实调用并计费,后续步骤复用前一步返回的真实字段。12 行 helper 就是全部集成代码。

python
#!/usr/bin/env python3
"""Infrai · errors — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) errors.capture — POST /v1/errors/capture · Capture an error event, aggregated into a group by fingerprint.
r1 = show("errors.capture", infrai("POST", "/v1/errors/capture", {"exception":{"type":"ValueError","message":"bad input","stacktrace":"..."},"level":"error"}))

# 2) errors.message — POST /v1/errors/message · Capture a structured error/log message (level, tags, user, release, environment).
r2 = show("errors.message", infrai("POST", "/v1/errors/message", {"text":"..."}))

# 3) errors.list — GET /v1/errors/list · Page through captured error events, with filtering.
r3 = show("errors.list", infrai("GET", "/v1/errors/list"))