-
Notifications
You must be signed in to change notification settings - Fork 49
[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
Changes from 9 commits
a03a5bd
42f415f
fa67dff
115c720
f07e40d
18fdb6d
997edb4
e5153da
1644fe7
36cff2d
339d7d3
b370416
41a7aee
9f4c808
6c82459
6506ed7
8ecd492
e572e7b
6fc54c5
d791a9e
bf091f5
5d958df
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,88 @@ | ||
| package events | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| ) | ||
|
|
||
| // maxS2RecordBytes is the maximum record size for the S2 event pipeline (1 MB). | ||
| const maxS2RecordBytes = 1_000_000 | ||
|
|
||
| // EventCategory is a first-class envelope field that determines log file routing. | ||
| 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" | ||
| ) | ||
|
|
||
| // SourceKind identifies the provenance of an event — which subsystem produced it. | ||
| type SourceKind string | ||
|
|
||
| const ( | ||
| SourceCDP SourceKind = "cdp" | ||
| SourceKernelAPI SourceKind = "kernel_api" | ||
| SourceExtension SourceKind = "extension" | ||
| SourceLocalProcess SourceKind = "local_process" | ||
| ) | ||
|
|
||
| // DetailLevel controls the verbosity of the event payload. | ||
| 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. | ||
| // | ||
| // The envelope is designed so that capture config and subscription selectors | ||
| // can operate on stable, first-class fields (Category, SourceKind, DetailLevel) | ||
| // without parsing the Type string. Type carries semantic identity (e.g. | ||
| // "console.log", "network.request"); SourceEvent carries the raw upstream | ||
| // event name (e.g. "Runtime.consoleAPICalled") for diagnostics. | ||
| // | ||
| // DetailLevel is always serialised (no omitempty). Pipeline.Publish defaults it | ||
| // to DetailDefault; callers constructing events outside a Pipeline should set it | ||
| // explicitly. | ||
| 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"` | ||
| SourceKind SourceKind `json:"source_kind"` | ||
| 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 returns a copy of ev with Data replaced with json.RawMessage("null") | ||
| // and Truncated set to true if the marshaled size exceeds maxS2RecordBytes. | ||
| // Never attempt byte-slice truncation of the Data field — partial JSON is invalid. | ||
| func truncateIfNeeded(ev BrowserEvent) BrowserEvent { | ||
| candidate, err := json.Marshal(ev) | ||
| if err != nil { | ||
| // Marshal should never fail for BrowserEvent (all fields are JSON-safe), | ||
| // but if it does return ev unchanged rather than silently nulling Data. | ||
| return ev | ||
| } | ||
| if len(candidate) <= maxS2RecordBytes { | ||
| return ev | ||
| } | ||
| ev.Data = json.RawMessage("null") | ||
| ev.Truncated = true | ||
| return ev | ||
| } | ||
|
cursor[bot] marked this conversation as 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.