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: Correct naming for logging pageUrl attribute #1225

Merged
merged 2 commits into from
Oct 28, 2024
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
3 changes: 1 addition & 2 deletions src/common/config/runtime.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getModeledObject } from './configurable'
import { getNREUMInitializedAgent } from '../window/nreum'
import { globalScope, originTime } from '../constants/runtime'
import { originTime } from '../constants/runtime'
import { BUILD_ENV, DIST_METHOD, VERSION } from '../constants/env'

/**
Expand All @@ -23,7 +23,6 @@ const model = {
loaderType: undefined,
maxBytes: 30000,
onerror: undefined,
origin: '' + globalScope.location,
ptid: undefined,
releaseIds: {},
/** Agent-specific metadata found in the RUM call response. ex. entityGuid */
Expand Down
4 changes: 2 additions & 2 deletions src/features/logging/shared/log.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { globalScope } from '../../../common/constants/runtime'
import { initialLocation } from '../../../common/constants/runtime'
import { cleanURL } from '../../../common/url/clean-url'
import { LOG_LEVELS } from '../constants'

Expand All @@ -22,7 +22,7 @@ export class Log {
/** @type {long} */
this.timestamp = timestamp
this.message = message
this.attributes = { ...attributes, pageUrl: cleanURL('' + globalScope.location) }
this.attributes = { ...attributes, pageUrl: cleanURL('' + initialLocation) }
this.level = level.toUpperCase()
}
}
6 changes: 3 additions & 3 deletions src/features/spa/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { AggregateBase } from '../../utils/aggregate-base'
import { firstContentfulPaint } from '../../../common/vitals/first-contentful-paint'
import { firstPaint } from '../../../common/vitals/first-paint'
import { bundleId } from '../../../common/ids/bundle-id'
import { loadedAsDeferredBrowserScript } from '../../../common/constants/runtime'
import { initialLocation, loadedAsDeferredBrowserScript } from '../../../common/constants/runtime'
import { handle } from '../../../common/event-emitter/handle'
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants'
import { warn } from '../../../common/util/console'
Expand All @@ -35,8 +35,8 @@ export class Aggregate extends AggregateBase {
super(agentRef, FEATURE_NAME)

this.state = {
initialPageURL: agentRef.runtime.origin,
lastSeenUrl: agentRef.runtime.origin,
initialPageURL: initialLocation,
lastSeenUrl: initialLocation,
lastSeenRouteName: null,
timerMap: {},
timerBudget: MAX_TIMER_BUDGET,
Expand Down
4 changes: 2 additions & 2 deletions src/features/spa/aggregate/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { getInfo } from '../../../common/config/info'
import { getRuntime } from '../../../common/config/runtime'
import { initialLocation } from '../../../common/constants/runtime'
import { gosNREUMOriginals } from '../../../common/window/nreum'
import { ee } from '../../../common/event-emitter/contextual-ee'
import { InteractionNode } from './interaction-node'
Expand Down Expand Up @@ -34,7 +34,7 @@ export function Interaction (eventName, timestamp, url, routeName, onFinished, a
var attrs = root.attrs

attrs.trigger = eventName
attrs.initialPageURL = getRuntime(agentIdentifier).origin
attrs.initialPageURL = initialLocation
attrs.oldRoute = routeName
attrs.newURL = attrs.oldURL = url
attrs.custom = {}
Expand Down
20 changes: 20 additions & 0 deletions tests/components/logging/aggregate.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getRuntime } from '../../../src/common/config/runtime'
import { initialLocation } from '../../../src/common/constants/runtime'
import { LOGGING_EVENT_EMITTER_CHANNEL } from '../../../src/features/logging/constants'
import { Instrument as Logging } from '../../../src/features/logging/instrument'
import { Log } from '../../../src/features/logging/shared/log'
Expand All @@ -7,6 +8,8 @@ import * as handleModule from '../../../src/common/event-emitter/handle'
import { resetAgent, setupAgent } from '../setup-agent'
import { getInfo } from '../../../src/common/config/info'

import { faker } from '@faker-js/faker'

let mainAgent, info, runtime

beforeAll(async () => {
Expand Down Expand Up @@ -182,6 +185,23 @@ describe('payloads', () => {
loggingAggregate.ee.emit(LOGGING_EVENT_EMITTER_CHANNEL, [1234, Symbol('test'), {}, 'error'])
expect(logs.pop().message).toEqual('Symbol(test)')
})

test('initialLocation should be in pageUrl of log object attributes', async () => {
cwli24 marked this conversation as resolved.
Show resolved Hide resolved
const currentUrl = faker.internet.url()
jest.spyOn(window, 'location', 'get').mockReturnValue(currentUrl)

const log = new Log(
Math.floor(runtime.timeKeeper.correctAbsoluteTimestamp(
runtime.timeKeeper.convertRelativeTimestamp(1234)
)),
ptang-nr marked this conversation as resolved.
Show resolved Hide resolved
'test message',
{ },
'error'
)
const expected = initialLocation.toString()

expect(log.attributes.pageUrl).toEqual(expected)
})
})

test('can harvest early', async () => {
Expand Down
Loading