Skip to content

Commit 1c3a6b9

Browse files
feat: Restructure AJAX Aggregate (#1003)
Co-authored-by: Jordan Porter <[email protected]>
1 parent c487e04 commit 1c3a6b9

File tree

4 files changed

+426
-592
lines changed

4 files changed

+426
-592
lines changed

src/features/ajax/aggregate/chunk.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { nullable, numeric, getAddStringContext, addCustomAttributes } from '../../../common/serialize/bel-serializer'
2+
import { getInfo } from '../../../common/config/config'
3+
4+
export default class Chunk {
5+
constructor (events, aggregateInstance) {
6+
this.addString = getAddStringContext(aggregateInstance.agentIdentifier) // pass agentIdentifier here
7+
this.events = events
8+
this.payload = 'bel.7;'
9+
10+
for (let i = 0; i < events.length; i++) {
11+
const event = events[i]
12+
const fields = [
13+
numeric(event.startTime),
14+
numeric(event.endTime - event.startTime),
15+
numeric(0), // callbackEnd
16+
numeric(0), // no callbackDuration for non-SPA events
17+
this.addString(event.method),
18+
numeric(event.status),
19+
this.addString(event.domain),
20+
this.addString(event.path),
21+
numeric(event.requestSize),
22+
numeric(event.responseSize),
23+
event.type === 'fetch' ? 1 : '',
24+
this.addString(0), // nodeId
25+
nullable(event.spanId, this.addString, true) + // guid
26+
nullable(event.traceId, this.addString, true) + // traceId
27+
nullable(event.spanTimestamp, numeric, false) // timestamp
28+
]
29+
30+
let insert = '2,'
31+
32+
// Since configuration objects (like info) are created new each time they are set, we have to grab the current pointer to the attr object here.
33+
const jsAttributes = getInfo(aggregateInstance.agentIdentifier).jsAttributes
34+
35+
// add custom attributes
36+
// gql decorators are added as custom attributes to alleviate need for new BEL schema
37+
const attrParts = addCustomAttributes({ ...(jsAttributes || {}), ...(event.gql || {}) }, this.addString)
38+
fields.unshift(numeric(attrParts.length))
39+
40+
insert += fields.join(',')
41+
if (attrParts && attrParts.length > 0) {
42+
insert += ';' + attrParts.join(';')
43+
}
44+
if ((i + 1) < events.length) insert += ';'
45+
46+
this.payload += insert
47+
}
48+
49+
this.tooBig = this.payload.length * 2 > aggregateInstance.MAX_PAYLOAD_SIZE
50+
}
51+
}

0 commit comments

Comments
 (0)