Skip to content

Commit 4f9b873

Browse files
authored
Merge branch 'main' into NR-443292-dom-mutations
2 parents 1f74b98 + c229a63 commit 4f9b873

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

.github/actions/build-ab/templates/released.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// config
22
window.NREUM={
33
init: {
4+
feature_flags: ['soft_nav'],
45
distributed_tracing: {
56
enabled: true
67
},

src/common/harvest/harvester.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,24 @@ export function send (agentRef, { endpoint, targetApp, payload, localOpts = {},
135135

136136
const fullUrl = `${url}?${baseParams}${payloadParams}`
137137
const gzip = !!qs?.attributes?.includes('gzip')
138-
if (!gzip) {
139-
if (endpoint !== EVENTS) body = stringify(body) // all features going to 'events' endpoint should already be serialized & stringified
140-
// Warn--once per endpoint--if the agent tries to send large payloads
141-
if (body.length > 750000 && (warnings[endpoint] = (warnings[endpoint] || 0) + 1) === 1) warn(28, endpoint)
142-
}
138+
139+
// all gzipped data is already in the correct format and needs no transformation
140+
// all features going to 'events' endpoint should already be serialized & stringified
141+
let stringBody = gzip || endpoint === EVENTS ? body : stringify(body)
143142

144143
// If body is null, undefined, or an empty object or array after stringifying, send an empty string instead.
145-
if (!body || body.length === 0 || body === '{}' || body === '[]') body = ''
144+
if (!stringBody || stringBody.length === 0 || stringBody === '{}' || stringBody === '[]') stringBody = ''
145+
146+
// Warn--once per endpoint--if the agent tries to send large payloads
147+
if (endpoint !== BLOBS && stringBody.length > 750000 && (warnings[endpoint] = (warnings[endpoint] || 0) + 1) === 1) warn(28, endpoint)
146148

147149
const headers = [{ key: 'content-type', value: 'text/plain' }]
148150

149151
/* Since workers don't support sendBeacon right now, they can only use XHR method.
150152
Because they still do permit synch XHR, the idea is that at final harvest time (worker is closing),
151153
we just make a BLOCKING request--trivial impact--with the remaining data as a temp fill-in for sendBeacon.
152154
Following the removal of img-element method. */
153-
let result = submitMethod({ url: fullUrl, body, sync: localOpts.isFinalHarvest && isWorkerScope, headers })
155+
let result = submitMethod({ url: fullUrl, body: stringBody, sync: localOpts.isFinalHarvest && isWorkerScope, headers })
154156

155157
if (!localOpts.isFinalHarvest && cbFinished) { // final harvests don't hold onto buffer data (shouldRetryOnFail is false), so cleanup isn't needed
156158
if (submitMethod === xhrMethod) {
@@ -176,17 +178,23 @@ export function send (agentRef, { endpoint, targetApp, payload, localOpts = {},
176178
}
177179

178180
function trackHarvestMetadata () {
179-
const hasReplay = baseParams.includes('hr=1')
180-
const hasTrace = baseParams.includes('ht=1')
181-
const hasError = qs?.attributes?.includes('hasError=true')
182-
183-
handle('harvest-metadata', [{
184-
[featureName]: {
185-
...(hasReplay && { hasReplay }),
186-
...(hasTrace && { hasTrace }),
187-
...(hasError && { hasError })
188-
}
189-
}], undefined, FEATURE_NAMES.metrics, agentRef.ee)
181+
try {
182+
if (featureName === FEATURE_NAMES.jserrors && !body?.err) return
183+
184+
const hasReplay = baseParams.includes('hr=1')
185+
const hasTrace = baseParams.includes('ht=1')
186+
const hasError = qs?.attributes?.includes('hasError=true')
187+
188+
handle('harvest-metadata', [{
189+
[featureName]: {
190+
...(hasReplay && { hasReplay }),
191+
...(hasTrace && { hasTrace }),
192+
...(hasError && { hasError })
193+
}
194+
}], undefined, FEATURE_NAMES.metrics, agentRef.ee)
195+
} catch (err) {
196+
// do nothing
197+
}
190198
}
191199
}
192200

0 commit comments

Comments
 (0)