Skip to content

Event Protocol

All HealthGuard SDKs follow a unified event protocol. Event schemas are defined in @health-guard/core and validated with Zod.

Batch Ingestion

SDKs report events in batches via POST /api/events/batch.

Request Body

json
{
  "appKey": "web_abc123",
  "events": [
    { /* event 1 */ },
    { /* event 2 */ }
  ]
}

Fields

FieldTypeRequiredDescription
appKeystringYesUnique app identifier; must match every event's appKey
eventsarrayYesEvent array; minimum 1, maximum 50 items

Base Event Fields

All event types share the following common fields:

FieldTypeRequiredDescription
eventIdstringYesUnique event ID
appKeystringYesUnique app identifier
platformstringYesPlatform type; see enum below
timestampnumberYesEvent timestamp in milliseconds
sessionIdstringYesSession ID
anonymousIdstringYesAnonymous user ID
sdkVersionstringYesSDK version
releasestringNoApp version
environmentstringNodevelopment / test / production
userIdstringNoBusiness user identifier
pageUrlstringNoCurrent page URL
deviceInfoobjectNoDevice information

Platform Enum

  • web
  • wechat-miniprogram
  • alipay-miniprogram
  • flutter
  • uniapp-h5
  • uniapp-wechat
  • uniapp-alipay
  • uniapp-douyin
  • uniapp-app
  • uniapp

Environment Enum

  • development
  • test
  • production

Event Types

error

Error events report JS errors, promise rejections, resource failures, and request failures.

FieldTypeRequiredDescription
typestringYesAlways error
errorTypestringYesjs / promise / resource / request / native
messagestringYesError summary
stackstringNoError stack trace
filenamestringNoFailing file (browser)
linenonumberNoLine number
colnonumberNoColumn number
fingerprintstringYesIssue aggregation fingerprint
breadcrumbsarrayYesBreadcrumb array
contextobjectNoCustom context; max 20 keys
pagestringNoPage path
scenestringNoBusiness scene

http

HTTP events report request duration, status code, and failure reason.

FieldTypeRequiredDescription
typestringYesAlways http
methodstringYesHTTP method
urlstringYesRequest URL (sanitized)
statusnumberNoHTTP status code
durationnumberYesRequest duration in milliseconds
successbooleanYesWhether the request succeeded
errorMessagestringNoError description
fingerprintstringNoIssue aggregation fingerprint
contextobjectNoCustom context; max 20 keys
requestDataobjectNoRequest data; max 20 keys
pagestringNoPage path
scenestringNoBusiness scene

performance

Performance events report custom metrics or Web Vitals-like data.

FieldTypeRequiredDescription
typestringYesAlways performance
namestringYesMetric name
valuenumberYesMetric value
ratingstringNogood / needs-improvement / poor

Breadcrumb events explicitly record user actions or state changes.

FieldTypeRequiredDescription
typestringYesAlways breadcrumb
breadcrumb.typestringYesnavigation / click / http / manual
breadcrumb.messagestringYesBreadcrumb description
breadcrumb.timestampnumberYesTimestamp
breadcrumb.dataobjectNoAdditional data

Fingerprinting

  • Error fingerprint: Based on errorType, message, the first two lines of the stack, and context fields url / method / scene / page.
  • HTTP fingerprint: Based on method, URL pathname, status, and platform.

Fingerprints are used by the Collector to group similar events into Issues.

Sanitization & Limits

  • Sensitive URL query keys are replaced with [Filtered]: authorization, auth, cookie, password, secret, token, access_token, refresh_token.
  • context and requestData are limited to 20 keys each.
  • Request and response bodies are not collected by default.

Released under the MIT License.