-
Notifications
You must be signed in to change notification settings - Fork 46
[kernel-1116] browser logging: Event Schema & Pipeline #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a03a5bd
42f415f
fa67dff
115c720
f07e40d
18fdb6d
997edb4
e5153da
1644fe7
36cff2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package events | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| ) | ||
|
|
||
| // maxS2RecordBytes is the maximum record size for the S2 event pipeline (1 MB). | ||
| const maxS2RecordBytes = 1_000_000 | ||
|
|
||
| // EventCategory determines type of logging | ||
| type EventCategory string | ||
|
|
||
| const ( | ||
| CategoryConsole EventCategory = "console" | ||
| CategoryNetwork EventCategory = "network" | ||
| CategoryPage EventCategory = "page" | ||
| CategoryInteraction EventCategory = "interaction" | ||
| CategoryLiveview EventCategory = "liveview" | ||
| CategoryCaptcha EventCategory = "captcha" | ||
| CategorySystem EventCategory = "system" | ||
| ) | ||
|
|
||
| type Source string | ||
|
|
||
| const ( | ||
| SourceCDP Source = "cdp" | ||
| SourceKernelAPI Source = "kernel_api" | ||
| SourceExtension Source = "extension" | ||
| SourceLocalProcess Source = "local_process" | ||
| ) | ||
|
|
||
| type DetailLevel string | ||
|
|
||
| const ( | ||
| DetailMinimal DetailLevel = "minimal" | ||
| DetailDefault DetailLevel = "default" | ||
| DetailVerbose DetailLevel = "verbose" | ||
| DetailRaw DetailLevel = "raw" | ||
| ) | ||
|
|
||
| // BrowserEvent is the canonical event structure for the browser capture pipeline. | ||
| type BrowserEvent struct { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: i wonder if Event would be a cleaner name than BrowserEvent. it feels more future-proof if extension/local-process/server-native producers end up as first-class peers. |
||
| CaptureSessionID string `json:"capture_session_id"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is capture_session_id intended to identify? this reads more like pipeline/native-producer lifecycle metadata than part of the portable event schema. if resume/subscription are meant to work across heterogeneous producers, i'd be careful about baking a producer-owned session id into every event. |
||
| Seq uint64 `json:"seq"` | ||
| Ts int64 `json:"ts"` | ||
| Type string `json:"type"` | ||
| Category EventCategory `json:"category"` | ||
| Source Source `json:"source"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is starting to feel like provenance wants to be an object rather than multiple top-level fields. i'd consider making source structured and moving cdp-specific context under source.metadata, e.g. {
"type": "console.log",
"category": "console",
"detail_level": "standard",
"source": {
"kind": "cdp",
"event": "Runtime.consoleAPICalled",
"metadata": {
"target_id": "...",
"cdp_session_id": "...",
"frame_id": "...",
"parent_frame_id": "..."
}
},
"data": { ... }
}that keeps the top level focused on stable cross-producer fields and makes non-cdp producers feel first-class too. |
||
| SourceEvent string `json:"source_event,omitempty"` | ||
| DetailLevel DetailLevel `json:"detail_level"` | ||
| TargetID string `json:"target_id,omitempty"` | ||
| CDPSessionID string `json:"cdp_session_id,omitempty"` | ||
| FrameID string `json:"frame_id,omitempty"` | ||
| ParentFrameID string `json:"parent_frame_id,omitempty"` | ||
| URL string `json:"url,omitempty"` | ||
| Data json.RawMessage `json:"data,omitempty"` | ||
| Truncated bool `json:"truncated,omitempty"` | ||
| } | ||
|
|
||
| // truncateIfNeeded marshals ev and returns the (possibly truncated) event together | ||
| func truncateIfNeeded(ev BrowserEvent) (BrowserEvent, []byte) { | ||
| data, err := json.Marshal(ev) | ||
| if err != nil { | ||
| return ev, data | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Marshal error silently writes corrupt JSONL lineLow Severity
Additional Locations (1)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. == |
||
| } | ||
| if len(data) <= maxS2RecordBytes { | ||
| return ev, data | ||
| } | ||
| ev.Data = json.RawMessage("null") | ||
| ev.Truncated = true | ||
| data, err = json.Marshal(ev) | ||
| if err != nil { | ||
| return ev, nil | ||
| } | ||
| return ev, data | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if this is meant to be a concrete level, i'd consider renaming default to standard. minimal/standard/verbose/raw reads like an actual ladder, whereas default feels more like a policy alias whose meaning could vary by producer.