feat(backend/tracker): extract tabdata into separate message from batchmeta

This commit is contained in:
nick-delirium 2023-05-22 11:57:48 +02:00
parent 81671ca4ed
commit 464d4dfcd4
16 changed files with 52 additions and 198 deletions

View file

@ -97,16 +97,7 @@ func main() {
msg = assetMessageHandler.ParseAssets(m)
}
// Create TabData message from BatchMetadata if TabId is present
switch m := msg.(type) {
case *messages.BatchMetadata:
if m.TabId != "" {
newMsg := &messages.TabData{TabId: m.TabId}
newMsg.SetMeta(m.Meta())
msg = newMsg
}
}
// Filter message
if !messages.IsReplayerType(msg.TypeID()) {
return

View file

@ -2,7 +2,7 @@
package messages
func IsReplayerType(id int) bool {
return 1 != id && 3 != id && 17 != id && 23 != id && 24 != id && 25 != id && 26 != id && 27 != id && 28 != id && 29 != id && 30 != id && 31 != id && 32 != id && 42 != id && 56 != id && 62 != id && 63 != id && 64 != id && 66 != id && 78 != id && 80 != id && 81 != id && 82 != id && 112 != id && 115 != id && 117 != id && 125 != id && 126 != id && 127 != id && 107 != id && 91 != id && 92 != id && 94 != id && 95 != id && 97 != id && 98 != id && 99 != id && 101 != id && 104 != id && 110 != id && 111 != id
return 1 != id && 3 != id && 17 != id && 23 != id && 24 != id && 25 != id && 26 != id && 27 != id && 28 != id && 29 != id && 30 != id && 31 != id && 32 != id && 42 != id && 56 != id && 62 != id && 63 != id && 64 != id && 66 != id && 78 != id && 80 != id && 81 != id && 82 != id && 112 != id && 115 != id && 125 != id && 126 != id && 127 != id && 107 != id && 91 != id && 92 != id && 94 != id && 95 != id && 97 != id && 98 != id && 99 != id && 101 != id && 104 != id && 110 != id && 111 != id
}
func IsIOSType(id int) bool {
@ -10,5 +10,5 @@ func IsIOSType(id int) bool {
}
func IsDOMType(id int) bool {
return 0 == id || 4 == id || 5 == id || 6 == id || 7 == id || 8 == id || 9 == id || 10 == id || 11 == id || 12 == id || 13 == id || 14 == id || 15 == id || 16 == id || 18 == id || 19 == id || 20 == id || 37 == id || 38 == id || 49 == id || 50 == id || 51 == id || 54 == id || 55 == id || 57 == id || 58 == id || 59 == id || 60 == id || 61 == id || 67 == id || 69 == id || 70 == id || 71 == id || 72 == id || 73 == id || 74 == id || 75 == id || 76 == id || 77 == id || 113 == id || 114 == id || 118 == id || 119 == id || 90 == id || 93 == id || 96 == id || 100 == id || 102 == id || 103 == id || 105 == id
return 0 == id || 4 == id || 5 == id || 6 == id || 7 == id || 8 == id || 9 == id || 10 == id || 11 == id || 12 == id || 13 == id || 14 == id || 15 == id || 16 == id || 18 == id || 19 == id || 20 == id || 37 == id || 38 == id || 49 == id || 50 == id || 51 == id || 54 == id || 55 == id || 57 == id || 58 == id || 59 == id || 60 == id || 61 == id || 67 == id || 69 == id || 70 == id || 71 == id || 72 == id || 73 == id || 74 == id || 75 == id || 76 == id || 77 == id || 113 == id || 114 == id || 117 == id || 118 == id || 90 == id || 93 == id || 96 == id || 100 == id || 102 == id || 103 == id || 105 == id
}

View file

@ -74,16 +74,15 @@ const (
MsgJSException = 78
MsgZustand = 79
MsgBatchMeta = 80
MsgBatchMetadataDeprecated = 81
MsgBatchMetadata = 81
MsgPartitionedMessage = 82
MsgInputChange = 112
MsgSelectionChange = 113
MsgMouseThrashing = 114
MsgUnbindNodes = 115
MsgResourceTiming = 116
MsgBatchMetadata = 117
MsgTabChange = 118
MsgTabData = 119
MsgTabChange = 117
MsgTabData = 118
MsgIssueEvent = 125
MsgSessionEnd = 126
MsgSessionSearch = 127
@ -1977,7 +1976,7 @@ func (msg *BatchMeta) TypeID() int {
return 80
}
type BatchMetadataDeprecated struct {
type BatchMetadata struct {
message
Version uint64
PageNo uint64
@ -1986,7 +1985,7 @@ type BatchMetadataDeprecated struct {
Location string
}
func (msg *BatchMetadataDeprecated) Encode() []byte {
func (msg *BatchMetadata) Encode() []byte {
buf := make([]byte, 51+len(msg.Location))
buf[0] = 81
p := 1
@ -1998,11 +1997,11 @@ func (msg *BatchMetadataDeprecated) Encode() []byte {
return buf[:p]
}
func (msg *BatchMetadataDeprecated) Decode() Message {
func (msg *BatchMetadata) Decode() Message {
return msg
}
func (msg *BatchMetadataDeprecated) TypeID() int {
func (msg *BatchMetadata) TypeID() int {
return 81
}
@ -2166,37 +2165,6 @@ func (msg *ResourceTiming) TypeID() int {
return 116
}
type BatchMetadata struct {
message
Version uint64
PageNo uint64
FirstIndex uint64
Timestamp int64
Location string
TabId string
}
func (msg *BatchMetadata) Encode() []byte {
buf := make([]byte, 61+len(msg.Location)+len(msg.TabId))
buf[0] = 117
p := 1
p = WriteUint(msg.Version, buf, p)
p = WriteUint(msg.PageNo, buf, p)
p = WriteUint(msg.FirstIndex, buf, p)
p = WriteInt(msg.Timestamp, buf, p)
p = WriteString(msg.Location, buf, p)
p = WriteString(msg.TabId, buf, p)
return buf[:p]
}
func (msg *BatchMetadata) Decode() Message {
return msg
}
func (msg *BatchMetadata) TypeID() int {
return 117
}
type TabChange struct {
message
TabId string
@ -2204,7 +2172,7 @@ type TabChange struct {
func (msg *TabChange) Encode() []byte {
buf := make([]byte, 11+len(msg.TabId))
buf[0] = 118
buf[0] = 117
p := 1
p = WriteString(msg.TabId, buf, p)
return buf[:p]
@ -2215,7 +2183,7 @@ func (msg *TabChange) Decode() Message {
}
func (msg *TabChange) TypeID() int {
return 118
return 117
}
type TabData struct {
@ -2225,7 +2193,7 @@ type TabData struct {
func (msg *TabData) Encode() []byte {
buf := make([]byte, 11+len(msg.TabId))
buf[0] = 119
buf[0] = 118
p := 1
p = WriteString(msg.TabId, buf, p)
return buf[:p]
@ -2236,7 +2204,7 @@ func (msg *TabData) Decode() Message {
}
func (msg *TabData) TypeID() int {
return 119
return 118
}
type IssueEvent struct {

View file

@ -1188,9 +1188,9 @@ func DecodeBatchMeta(reader BytesReader) (Message, error) {
return msg, err
}
func DecodeBatchMetadataDeprecated(reader BytesReader) (Message, error) {
func DecodeBatchMetadata(reader BytesReader) (Message, error) {
var err error = nil
msg := &BatchMetadataDeprecated{}
msg := &BatchMetadata{}
if msg.Version, err = reader.ReadUint(); err != nil {
return nil, err
}
@ -1314,30 +1314,6 @@ func DecodeResourceTiming(reader BytesReader) (Message, error) {
return msg, err
}
func DecodeBatchMetadata(reader BytesReader) (Message, error) {
var err error = nil
msg := &BatchMetadata{}
if msg.Version, err = reader.ReadUint(); err != nil {
return nil, err
}
if msg.PageNo, err = reader.ReadUint(); err != nil {
return nil, err
}
if msg.FirstIndex, err = reader.ReadUint(); err != nil {
return nil, err
}
if msg.Timestamp, err = reader.ReadInt(); err != nil {
return nil, err
}
if msg.Location, err = reader.ReadString(); err != nil {
return nil, err
}
if msg.TabId, err = reader.ReadString(); err != nil {
return nil, err
}
return msg, err
}
func DecodeTabChange(reader BytesReader) (Message, error) {
var err error = nil
msg := &TabChange{}
@ -1956,7 +1932,7 @@ func ReadMessage(t uint64, reader BytesReader) (Message, error) {
case 80:
return DecodeBatchMeta(reader)
case 81:
return DecodeBatchMetadataDeprecated(reader)
return DecodeBatchMetadata(reader)
case 82:
return DecodePartitionedMessage(reader)
case 112:
@ -1970,10 +1946,8 @@ func ReadMessage(t uint64, reader BytesReader) (Message, error) {
case 116:
return DecodeResourceTiming(reader)
case 117:
return DecodeBatchMetadata(reader)
case 118:
return DecodeTabChange(reader)
case 119:
case 118:
return DecodeTabData(reader)
case 125:
return DecodeIssueEvent(reader)

View file

@ -689,7 +689,7 @@ class BatchMeta(Message):
self.timestamp = timestamp
class BatchMetadataDeprecated(Message):
class BatchMetadata(Message):
__id__ = 81
def __init__(self, version, page_no, first_index, timestamp, location):
@ -759,27 +759,15 @@ class ResourceTiming(Message):
self.cached = cached
class BatchMetadata(Message):
__id__ = 117
def __init__(self, version, page_no, first_index, timestamp, location, tab_id):
self.version = version
self.page_no = page_no
self.first_index = first_index
self.timestamp = timestamp
self.location = location
self.tab_id = tab_id
class TabChange(Message):
__id__ = 118
__id__ = 117
def __init__(self, tab_id):
self.tab_id = tab_id
class TabData(Message):
__id__ = 119
__id__ = 118
def __init__(self, tab_id):
self.tab_id = tab_id

View file

@ -634,7 +634,7 @@ class MessageCodec(Codec):
)
if message_id == 81:
return BatchMetadataDeprecated(
return BatchMetadata(
version=self.read_uint(reader),
page_no=self.read_uint(reader),
first_index=self.read_uint(reader),
@ -690,21 +690,11 @@ class MessageCodec(Codec):
)
if message_id == 117:
return BatchMetadata(
version=self.read_uint(reader),
page_no=self.read_uint(reader),
first_index=self.read_uint(reader),
timestamp=self.read_int(reader),
location=self.read_string(reader),
tab_id=self.read_string(reader)
)
if message_id == 118:
return TabChange(
tab_id=self.read_string(reader)
)
if message_id == 119:
if message_id == 118:
return TabData(
tab_id=self.read_string(reader)
)

View file

@ -673,7 +673,7 @@ export default class RawMessageReader extends PrimitiveReader {
};
}
case 118: {
case 117: {
const tabId = this.readString(); if (tabId === null) { return resetPointer() }
return {
tp: MType.TabChange,
@ -681,7 +681,7 @@ export default class RawMessageReader extends PrimitiveReader {
};
}
case 119: {
case 118: {
const tabId = this.readString(); if (tabId === null) { return resetPointer() }
return {
tp: MType.TabData,

View file

@ -3,7 +3,7 @@
import { MType } from './raw.gen'
const DOM_TYPES = [0,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20,37,38,49,50,51,54,55,57,58,59,60,61,67,69,70,71,72,73,74,75,76,77,113,114,118,119,90,93,96,100,102,103,105]
const DOM_TYPES = [0,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20,37,38,49,50,51,54,55,57,58,59,60,61,67,69,70,71,72,73,74,75,76,77,113,114,117,118,90,93,96,100,102,103,105]
export function isDOMType(t: MType) {
return DOM_TYPES.includes(t)
}

View file

@ -56,8 +56,8 @@ export const enum MType {
SelectionChange = 113,
MouseThrashing = 114,
ResourceTiming = 116,
TabChange = 118,
TabData = 119,
TabChange = 117,
TabData = 118,
IosSessionStart = 90,
IosCustomEvent = 93,
IosScreenChanges = 96,

View file

@ -57,8 +57,8 @@ export const TP_MAP = {
113: MType.SelectionChange,
114: MType.MouseThrashing,
116: MType.ResourceTiming,
118: MType.TabChange,
119: MType.TabData,
117: MType.TabChange,
118: MType.TabData,
90: MType.IosSessionStart,
93: MType.IosCustomEvent,
96: MType.IosScreenChanges,

View file

@ -414,7 +414,7 @@ type TrZustand = [
state: string,
]
type TrBatchMetadataDeprecated = [
type TrBatchMetadata = [
type: 81,
version: number,
pageNo: number,
@ -470,28 +470,18 @@ type TrResourceTiming = [
cached: boolean,
]
type TrBatchMetadata = [
type: 117,
version: number,
pageNo: number,
firstIndex: number,
timestamp: number,
location: string,
tabId: string,
]
type TrTabChange = [
type: 118,
type: 117,
tabId: string,
]
type TrTabData = [
type: 119,
type: 118,
tabId: string,
]
export type TrackerMessage = TrTimestamp | TrSetPageLocation | TrSetViewportSize | TrSetViewportScroll | TrCreateDocument | TrCreateElementNode | TrCreateTextNode | TrMoveNode | TrRemoveNode | TrSetNodeAttribute | TrRemoveNodeAttribute | TrSetNodeData | TrSetNodeScroll | TrSetInputTarget | TrSetInputValue | TrSetInputChecked | TrMouseMove | TrNetworkRequest | TrConsoleLog | TrPageLoadTiming | TrPageRenderTiming | TrCustomEvent | TrUserID | TrUserAnonymousID | TrMetadata | TrCSSInsertRule | TrCSSDeleteRule | TrFetch | TrProfiler | TrOTable | TrStateAction | TrRedux | TrVuex | TrMobX | TrNgRx | TrGraphQL | TrPerformanceTrack | TrStringDict | TrSetNodeAttributeDict | TrResourceTimingDeprecated | TrConnectionInformation | TrSetPageVisibility | TrLoadFontFace | TrSetNodeFocus | TrLongTask | TrSetNodeAttributeURLBased | TrSetCSSDataURLBased | TrTechnicalInfo | TrCustomIssue | TrCSSInsertRuleURLBased | TrMouseClick | TrCreateIFrameDocument | TrAdoptedSSReplaceURLBased | TrAdoptedSSInsertRuleURLBased | TrAdoptedSSDeleteRule | TrAdoptedSSAddOwner | TrAdoptedSSRemoveOwner | TrJSException | TrZustand | TrBatchMetadataDeprecated | TrPartitionedMessage | TrInputChange | TrSelectionChange | TrMouseThrashing | TrUnbindNodes | TrResourceTiming | TrBatchMetadata | TrTabChange | TrTabData
export type TrackerMessage = TrTimestamp | TrSetPageLocation | TrSetViewportSize | TrSetViewportScroll | TrCreateDocument | TrCreateElementNode | TrCreateTextNode | TrMoveNode | TrRemoveNode | TrSetNodeAttribute | TrRemoveNodeAttribute | TrSetNodeData | TrSetNodeScroll | TrSetInputTarget | TrSetInputValue | TrSetInputChecked | TrMouseMove | TrNetworkRequest | TrConsoleLog | TrPageLoadTiming | TrPageRenderTiming | TrCustomEvent | TrUserID | TrUserAnonymousID | TrMetadata | TrCSSInsertRule | TrCSSDeleteRule | TrFetch | TrProfiler | TrOTable | TrStateAction | TrRedux | TrVuex | TrMobX | TrNgRx | TrGraphQL | TrPerformanceTrack | TrStringDict | TrSetNodeAttributeDict | TrResourceTimingDeprecated | TrConnectionInformation | TrSetPageVisibility | TrLoadFontFace | TrSetNodeFocus | TrLongTask | TrSetNodeAttributeURLBased | TrSetCSSDataURLBased | TrTechnicalInfo | TrCustomIssue | TrCSSInsertRuleURLBased | TrMouseClick | TrCreateIFrameDocument | TrAdoptedSSReplaceURLBased | TrAdoptedSSInsertRuleURLBased | TrAdoptedSSDeleteRule | TrAdoptedSSAddOwner | TrAdoptedSSRemoveOwner | TrJSException | TrZustand | TrBatchMetadata | TrPartitionedMessage | TrInputChange | TrSelectionChange | TrMouseThrashing | TrUnbindNodes | TrResourceTiming | TrTabChange | TrTabData
export default function translate(tMsg: TrackerMessage): RawMessage | null {
switch(tMsg[0]) {
@ -960,14 +950,14 @@ export default function translate(tMsg: TrackerMessage): RawMessage | null {
}
}
case 118: {
case 117: {
return {
tp: MType.TabChange,
tabId: tMsg[1],
}
}
case 119: {
case 118: {
return {
tp: MType.TabData,
tabId: tMsg[1],

View file

@ -432,7 +432,7 @@ message 80, 'BatchMeta', :replayer => false, :tracker => false do
end
# since tracker 3.6.0 TODO: for webworker only
message 81, 'BatchMetadataDeprecated', :replayer => false do
message 81, 'BatchMetadata', :replayer => false do
uint 'Version'
uint 'PageNo'
uint 'FirstIndex'
@ -484,20 +484,11 @@ message 116, 'ResourceTiming', :replayer => :devtools do
boolean 'Cached'
end
message 117, 'BatchMetadata', :replayer => false do
uint 'Version'
uint 'PageNo'
uint 'FirstIndex'
int 'Timestamp'
string 'Location'
string 'TabId'
end
message 118, 'TabChange' do
message 117, 'TabChange' do
string 'TabId'
end
message 119, 'TabData' do
message 118, 'TabData' do
string 'TabId'
end

View file

@ -61,16 +61,15 @@ export declare const enum Type {
AdoptedSSRemoveOwner = 77,
JSException = 78,
Zustand = 79,
BatchMetadataDeprecated = 81,
BatchMetadata = 81,
PartitionedMessage = 82,
InputChange = 112,
SelectionChange = 113,
MouseThrashing = 114,
UnbindNodes = 115,
ResourceTiming = 116,
BatchMetadata = 117,
TabChange = 118,
TabData = 119,
TabChange = 117,
TabData = 118,
}
@ -483,8 +482,8 @@ export type Zustand = [
/*state:*/ string,
]
export type BatchMetadataDeprecated = [
/*type:*/ Type.BatchMetadataDeprecated,
export type BatchMetadata = [
/*type:*/ Type.BatchMetadata,
/*version:*/ number,
/*pageNo:*/ number,
/*firstIndex:*/ number,
@ -539,16 +538,6 @@ export type ResourceTiming = [
/*cached:*/ boolean,
]
export type BatchMetadata = [
/*type:*/ Type.BatchMetadata,
/*version:*/ number,
/*pageNo:*/ number,
/*firstIndex:*/ number,
/*timestamp:*/ number,
/*location:*/ string,
/*tabId:*/ string,
]
export type TabChange = [
/*type:*/ Type.TabChange,
/*tabId:*/ string,
@ -560,5 +549,5 @@ export type TabData = [
]
type Message = Timestamp | SetPageLocation | SetViewportSize | SetViewportScroll | CreateDocument | CreateElementNode | CreateTextNode | MoveNode | RemoveNode | SetNodeAttribute | RemoveNodeAttribute | SetNodeData | SetNodeScroll | SetInputTarget | SetInputValue | SetInputChecked | MouseMove | NetworkRequest | ConsoleLog | PageLoadTiming | PageRenderTiming | CustomEvent | UserID | UserAnonymousID | Metadata | CSSInsertRule | CSSDeleteRule | Fetch | Profiler | OTable | StateAction | Redux | Vuex | MobX | NgRx | GraphQL | PerformanceTrack | StringDict | SetNodeAttributeDict | ResourceTimingDeprecated | ConnectionInformation | SetPageVisibility | LoadFontFace | SetNodeFocus | LongTask | SetNodeAttributeURLBased | SetCSSDataURLBased | TechnicalInfo | CustomIssue | CSSInsertRuleURLBased | MouseClick | CreateIFrameDocument | AdoptedSSReplaceURLBased | AdoptedSSInsertRuleURLBased | AdoptedSSDeleteRule | AdoptedSSAddOwner | AdoptedSSRemoveOwner | JSException | Zustand | BatchMetadataDeprecated | PartitionedMessage | InputChange | SelectionChange | MouseThrashing | UnbindNodes | ResourceTiming | BatchMetadata | TabChange | TabData
type Message = Timestamp | SetPageLocation | SetViewportSize | SetViewportScroll | CreateDocument | CreateElementNode | CreateTextNode | MoveNode | RemoveNode | SetNodeAttribute | RemoveNodeAttribute | SetNodeData | SetNodeScroll | SetInputTarget | SetInputValue | SetInputChecked | MouseMove | NetworkRequest | ConsoleLog | PageLoadTiming | PageRenderTiming | CustomEvent | UserID | UserAnonymousID | Metadata | CSSInsertRule | CSSDeleteRule | Fetch | Profiler | OTable | StateAction | Redux | Vuex | MobX | NgRx | GraphQL | PerformanceTrack | StringDict | SetNodeAttributeDict | ResourceTimingDeprecated | ConnectionInformation | SetPageVisibility | LoadFontFace | SetNodeFocus | LongTask | SetNodeAttributeURLBased | SetCSSDataURLBased | TechnicalInfo | CustomIssue | CSSInsertRuleURLBased | MouseClick | CreateIFrameDocument | AdoptedSSReplaceURLBased | AdoptedSSInsertRuleURLBased | AdoptedSSDeleteRule | AdoptedSSAddOwner | AdoptedSSRemoveOwner | JSException | Zustand | BatchMetadata | PartitionedMessage | InputChange | SelectionChange | MouseThrashing | UnbindNodes | ResourceTiming | TabChange | TabData
export default Message

View file

@ -764,15 +764,15 @@ export function Zustand(
]
}
export function BatchMetadataDeprecated(
export function BatchMetadata(
version: number,
pageNo: number,
firstIndex: number,
timestamp: number,
location: string,
): Messages.BatchMetadataDeprecated {
): Messages.BatchMetadata {
return [
Messages.Type.BatchMetadataDeprecated,
Messages.Type.BatchMetadata,
version,
pageNo,
firstIndex,
@ -869,25 +869,6 @@ export function ResourceTiming(
]
}
export function BatchMetadata(
version: number,
pageNo: number,
firstIndex: number,
timestamp: number,
location: string,
tabId: string,
): Messages.BatchMetadata {
return [
Messages.Type.BatchMetadata,
version,
pageNo,
firstIndex,
timestamp,
location,
tabId,
]
}
export function TabChange(
tabId: string,
): Messages.TabChange {

View file

@ -51,18 +51,14 @@ export default class BatchWriter {
this.nextIndex,
this.timestamp,
this.url,
this.tabId,
]
console.log('meta', {
pageNo: this.pageNo,
nextIndex: this.nextIndex,
timestamp: this.timestamp,
url: this.url,
tabId: this.tabId,
})
const tabData: Messages.TabData = [Messages.Type.TabData, this.tabId]
this.writeType(batchMetadata)
this.writeFields(batchMetadata)
this.writeType(tabData as Message)
this.writeFields(tabData as Message)
this.isEmpty = true
}

View file

@ -246,7 +246,7 @@ export default class MessageEncoder extends PrimitiveEncoder {
return this.string(msg[1]) && this.string(msg[2])
break
case Messages.Type.BatchMetadataDeprecated:
case Messages.Type.BatchMetadata:
return this.uint(msg[1]) && this.uint(msg[2]) && this.uint(msg[3]) && this.int(msg[4]) && this.string(msg[5])
break
@ -274,10 +274,6 @@ export default class MessageEncoder extends PrimitiveEncoder {
return this.uint(msg[1]) && this.uint(msg[2]) && this.uint(msg[3]) && this.uint(msg[4]) && this.uint(msg[5]) && this.uint(msg[6]) && this.string(msg[7]) && this.string(msg[8]) && this.uint(msg[9]) && this.boolean(msg[10])
break
case Messages.Type.BatchMetadata:
return this.uint(msg[1]) && this.uint(msg[2]) && this.uint(msg[3]) && this.int(msg[4]) && this.string(msg[5]) && this.string(msg[6])
break
case Messages.Type.TabChange:
return this.string(msg[1])
break