Skip to content
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

fix: Console error on some cross-origin requests without NR CAT header #1407

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/features/ajax/instrument/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

var origRequest = gosNREUMOriginals().o.REQ
var origXHR = gosNREUMOriginals().o.XHR
const NR_CAT_HEADER = 'X-NewRelic-App-Data'

export class Instrument extends InstrumentBase {
static featureName = FEATURE_NAME
Expand Down Expand Up @@ -392,8 +393,8 @@
var size = responseSizeFromXhr(xhr, ctx.lastSize)
if (size) ctx.metrics.rxSize = size

if (ctx.sameOrigin) {
var header = xhr.getResponseHeader('X-NewRelic-App-Data')
if (ctx.sameOrigin && xhr.getAllResponseHeaders().indexOf(NR_CAT_HEADER) >= 0) {
var header = xhr.getResponseHeader(NR_CAT_HEADER)

Check warning on line 397 in src/features/ajax/instrument/index.js

View check run for this annotation

Codecov / codecov/patch

src/features/ajax/instrument/index.js#L397

Added line #L397 was not covered by tests
if (header) {
handle(SUPPORTABILITY_METRIC, ['Ajax/CrossApplicationTracing/Header/Seen'], undefined, FEATURE_NAMES.metrics, ee)
ctx.params.cat = header.split(', ').pop()
Expand Down
4 changes: 1 addition & 3 deletions tests/components/setup-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ export function setupAgent ({ agentOverrides = {}, info = {}, init = {}, loaderC
runtime = getRuntime(agentIdentifier)
if (!runtime.timeKeeper) {
runtime.timeKeeper = new TimeKeeper(agentIdentifier)
runtime.timeKeeper.processRumRequest({
getResponseHeader: jest.fn(() => (new Date()).toUTCString())
}, 450, 600, Date.now())
runtime.timeKeeper.processRumRequest({}, 450, 600, Date.now())
}
fakeAgent.features = {}
if (!runtime.harvester) runtime.harvester = new Harvester(fakeAgent)
Expand Down
Loading