@newrelic/browser-agent 0.1.231 → 1.232.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cjs/common/config/state/configurable.js +27 -21
- package/dist/cjs/common/config/state/init.js +8 -0
- package/dist/cjs/common/config/state/runtime.js +24 -26
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/context/shared-context.js +2 -1
- package/dist/cjs/common/event-emitter/contextual-ee.test.js +2 -2
- package/dist/cjs/common/event-emitter/register-handler.test.js +1 -1
- package/dist/cjs/common/event-listener/event-listener-opts.js +4 -2
- package/dist/cjs/common/harvest/harvest-scheduler.js +14 -11
- package/dist/cjs/common/harvest/harvest.js +3 -1
- package/dist/cjs/common/session/constants.js +12 -0
- package/dist/cjs/common/session/session-entity.js +278 -0
- package/dist/cjs/common/session/session-entity.test.js +436 -0
- package/dist/cjs/common/storage/first-party-cookies.js +35 -0
- package/dist/cjs/common/storage/local-memory.js +35 -0
- package/dist/cjs/common/storage/local-memory.test.js +20 -0
- package/dist/cjs/common/storage/local-storage.js +33 -0
- package/dist/cjs/common/storage/local-storage.test.js +14 -0
- package/dist/cjs/common/timer/interaction-timer.js +78 -0
- package/dist/cjs/common/timer/interaction-timer.test.js +216 -0
- package/dist/cjs/common/timer/timer.js +32 -0
- package/dist/cjs/common/timer/timer.test.js +105 -0
- package/dist/cjs/common/unload/eol.js +2 -2
- package/dist/cjs/common/util/data-size.js +6 -0
- package/dist/cjs/common/util/data-size.test.js +47 -0
- package/dist/cjs/common/util/invoke.js +73 -0
- package/dist/cjs/common/util/invoke.test.js +49 -0
- package/dist/cjs/common/util/obfuscate.js +0 -4
- package/dist/cjs/common/window/page-visibility.js +3 -1
- package/dist/cjs/common/wrap/wrap-timer.js +1 -1
- package/dist/cjs/features/ajax/aggregate/index.js +2 -2
- package/dist/cjs/features/jserrors/aggregate/index.js +3 -3
- package/dist/cjs/features/metrics/aggregate/index.js +13 -2
- package/dist/cjs/features/page_action/aggregate/index.js +2 -2
- package/dist/cjs/features/page_view_event/aggregate/index.js +6 -3
- package/dist/cjs/features/page_view_timing/aggregate/index.js +6 -6
- package/dist/cjs/features/session_trace/aggregate/index.js +2 -2
- package/dist/cjs/features/spa/aggregate/index.js +6 -5
- package/dist/cjs/features/utils/agent-session.js +73 -0
- package/dist/cjs/features/utils/feature-base.js +1 -1
- package/dist/cjs/features/utils/instrument-base.js +7 -2
- package/dist/cjs/features/utils/lazy-loader.js +1 -1
- package/dist/cjs/loaders/agent.js +1 -1
- package/dist/cjs/loaders/api/api.js +1 -4
- package/dist/cjs/loaders/api/apiAsync.js +3 -2
- package/dist/cjs/loaders/configure/configure.js +0 -6
- package/dist/esm/common/config/state/configurable.js +26 -20
- package/dist/esm/common/config/state/init.js +8 -0
- package/dist/esm/common/config/state/runtime.js +24 -26
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/context/shared-context.js +2 -1
- package/dist/esm/common/event-emitter/contextual-ee.test.js +2 -2
- package/dist/esm/common/event-emitter/register-handler.test.js +1 -1
- package/dist/esm/common/event-listener/event-listener-opts.js +4 -2
- package/dist/esm/common/harvest/harvest-scheduler.js +14 -11
- package/dist/esm/common/harvest/harvest.js +3 -1
- package/dist/esm/common/session/constants.js +3 -0
- package/dist/esm/common/session/session-entity.js +271 -0
- package/dist/esm/common/session/session-entity.test.js +434 -0
- package/dist/esm/common/storage/first-party-cookies.js +28 -0
- package/dist/esm/common/storage/local-memory.js +28 -0
- package/dist/esm/common/storage/local-memory.test.js +18 -0
- package/dist/esm/common/storage/local-storage.js +26 -0
- package/dist/esm/common/storage/local-storage.test.js +12 -0
- package/dist/esm/common/timer/interaction-timer.js +71 -0
- package/dist/esm/common/timer/interaction-timer.test.js +214 -0
- package/dist/esm/common/timer/timer.js +25 -0
- package/dist/esm/common/timer/timer.test.js +103 -0
- package/dist/esm/common/unload/eol.js +1 -1
- package/dist/esm/common/util/data-size.js +7 -0
- package/dist/esm/common/util/data-size.test.js +45 -0
- package/dist/esm/common/util/invoke.js +66 -0
- package/dist/esm/common/util/invoke.test.js +47 -0
- package/dist/esm/common/util/obfuscate.js +0 -4
- package/dist/esm/common/window/page-visibility.js +3 -1
- package/dist/esm/common/wrap/wrap-timer.js +1 -1
- package/dist/esm/features/ajax/aggregate/index.js +2 -2
- package/dist/esm/features/jserrors/aggregate/index.js +3 -3
- package/dist/esm/features/metrics/aggregate/index.js +14 -3
- package/dist/esm/features/page_action/aggregate/index.js +2 -2
- package/dist/esm/features/page_view_event/aggregate/index.js +6 -3
- package/dist/esm/features/page_view_timing/aggregate/index.js +6 -6
- package/dist/esm/features/session_trace/aggregate/index.js +2 -2
- package/dist/esm/features/spa/aggregate/index.js +6 -5
- package/dist/esm/features/utils/agent-session.js +67 -0
- package/dist/esm/features/utils/feature-base.js +1 -1
- package/dist/esm/features/utils/instrument-base.js +7 -2
- package/dist/esm/features/utils/lazy-loader.js +1 -1
- package/dist/esm/loaders/agent.js +1 -1
- package/dist/esm/loaders/api/api.js +2 -5
- package/dist/esm/loaders/api/apiAsync.js +2 -1
- package/dist/esm/loaders/configure/configure.js +2 -8
- package/dist/types/common/config/state/configurable.d.ts.map +1 -1
- package/dist/types/common/config/state/init.d.ts.map +1 -1
- package/dist/types/common/config/state/runtime.d.ts.map +1 -1
- package/dist/types/common/context/shared-context.d.ts.map +1 -1
- package/dist/types/common/event-listener/event-listener-opts.d.ts +2 -2
- package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest-scheduler.d.ts +1 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest.d.ts.map +1 -1
- package/dist/types/common/session/constants.d.ts +4 -0
- package/dist/types/common/session/constants.d.ts.map +1 -0
- package/dist/types/common/session/session-entity.d.ts +72 -0
- package/dist/types/common/session/session-entity.d.ts.map +1 -0
- package/dist/types/common/storage/first-party-cookies.d.ts +8 -0
- package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -0
- package/dist/types/common/storage/local-memory.d.ts +8 -0
- package/dist/types/common/storage/local-memory.d.ts.map +1 -0
- package/dist/types/common/storage/local-storage.d.ts +6 -0
- package/dist/types/common/storage/local-storage.d.ts.map +1 -0
- package/dist/types/common/timer/interaction-timer.d.ts +11 -0
- package/dist/types/common/timer/interaction-timer.d.ts.map +1 -0
- package/dist/types/common/timer/timer.d.ts +12 -0
- package/dist/types/common/timer/timer.d.ts.map +1 -0
- package/dist/types/common/util/data-size.d.ts +7 -1
- package/dist/types/common/util/data-size.d.ts.map +1 -1
- package/dist/types/common/util/invoke.d.ts +35 -0
- package/dist/types/common/util/invoke.d.ts.map +1 -0
- package/dist/types/common/util/obfuscate.d.ts.map +1 -1
- package/dist/types/common/window/page-visibility.d.ts +1 -1
- package/dist/types/common/window/page-visibility.d.ts.map +1 -1
- package/dist/types/features/ajax/aggregate/index.d.ts +2 -2
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +2 -2
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/index.d.ts +2 -2
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_action/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_timing/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts +2 -2
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/spa/aggregate/index.d.ts +2 -2
- package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/utils/agent-session.d.ts +2 -0
- package/dist/types/features/utils/agent-session.d.ts.map +1 -0
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/features/utils/lazy-loader.d.ts +2 -2
- package/dist/types/features/utils/lazy-loader.d.ts.map +1 -1
- package/dist/types/loaders/api/api.d.ts.map +1 -1
- package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/common/config/state/configurable.js +26 -19
- package/src/common/config/state/init.js +7 -0
- package/src/common/config/state/runtime.js +22 -27
- package/src/common/context/shared-context.js +2 -1
- package/src/common/event-emitter/contextual-ee.test.js +2 -2
- package/src/common/event-emitter/register-handler.test.js +1 -1
- package/src/common/event-listener/event-listener-opts.js +4 -4
- package/src/common/harvest/harvest-scheduler.js +12 -8
- package/src/common/harvest/harvest.js +3 -1
- package/src/common/session/constants.js +3 -0
- package/src/common/session/session-entity.js +271 -0
- package/src/common/session/session-entity.test.js +317 -0
- package/src/common/storage/first-party-cookies.js +31 -0
- package/src/common/storage/local-memory.js +30 -0
- package/src/common/storage/local-memory.test.js +19 -0
- package/src/common/storage/local-storage.js +28 -0
- package/src/common/storage/local-storage.test.js +17 -0
- package/src/common/timer/interaction-timer.js +75 -0
- package/src/common/timer/interaction-timer.test.js +167 -0
- package/src/common/timer/timer.js +31 -0
- package/src/common/timer/timer.test.js +100 -0
- package/src/common/unload/eol.js +1 -1
- package/src/common/util/data-size.js +6 -0
- package/src/common/util/data-size.test.js +50 -0
- package/src/common/util/invoke.js +55 -0
- package/src/common/util/invoke.test.js +65 -0
- package/src/common/util/obfuscate.js +0 -4
- package/src/common/window/page-visibility.js +2 -2
- package/src/common/wrap/wrap-timer.js +1 -1
- package/src/features/ajax/aggregate/index.js +2 -2
- package/src/features/jserrors/aggregate/index.js +3 -3
- package/src/features/metrics/aggregate/index.js +18 -3
- package/src/features/page_action/aggregate/index.js +2 -2
- package/src/features/page_view_event/aggregate/index.js +6 -3
- package/src/features/page_view_timing/aggregate/index.js +6 -6
- package/src/features/session_trace/aggregate/index.js +2 -2
- package/src/features/spa/aggregate/index.js +5 -5
- package/src/features/utils/agent-session.js +68 -0
- package/src/features/utils/feature-base.js +1 -1
- package/src/features/utils/instrument-base.js +5 -2
- package/src/features/utils/lazy-loader.js +1 -1
- package/src/loaders/agent.js +1 -1
- package/src/loaders/api/api.js +2 -5
- package/src/loaders/api/apiAsync.js +2 -1
- package/src/loaders/configure/configure.js +2 -7
- package/dist/cjs/common/util/single.js +0 -23
- package/dist/cjs/common/window/session-storage.js +0 -87
- package/dist/cjs/features/utils/aggregate-base.js +0 -13
- package/dist/esm/common/util/single.js +0 -16
- package/dist/esm/common/window/session-storage.js +0 -77
- package/dist/esm/features/utils/aggregate-base.js +0 -6
- package/dist/types/common/util/single.d.ts +0 -2
- package/dist/types/common/util/single.d.ts.map +0 -1
- package/dist/types/common/window/session-storage.d.ts +0 -18
- package/dist/types/common/window/session-storage.d.ts.map +0 -1
- package/dist/types/features/utils/aggregate-base.d.ts +0 -4
- package/dist/types/features/utils/aggregate-base.d.ts.map +0 -1
- package/src/common/util/single.js +0 -18
- package/src/common/window/session-storage.js +0 -75
- package/src/features/utils/aggregate-base.js +0 -7
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { getRuntime } from '../../../common/config/config'
|
|
1
|
+
import { getRuntime, getInfo } from '../../../common/config/config'
|
|
2
2
|
import { registerHandler } from '../../../common/event-emitter/register-handler'
|
|
3
3
|
import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
|
|
4
|
-
import { AggregateBase } from '../../utils/aggregate-base'
|
|
5
4
|
import { FEATURE_NAME, SUPPORTABILITY_METRIC, CUSTOM_METRIC, SUPPORTABILITY_METRIC_CHANNEL, CUSTOM_METRIC_CHANNEL } from '../constants'
|
|
6
5
|
import { drain } from '../../../common/drain/drain'
|
|
7
6
|
import { getFrameworks } from '../../../common/metrics/framework-detection'
|
|
@@ -11,7 +10,10 @@ import { VERSION } from '../../../common/constants/env'
|
|
|
11
10
|
import { onDOMContentLoaded } from '../../../common/window/load'
|
|
12
11
|
import { windowAddEventListener } from '../../../common/event-listener/event-listener-opts'
|
|
13
12
|
import { isBrowserScope } from '../../../common/util/global-scope'
|
|
14
|
-
|
|
13
|
+
import { FeatureBase } from '../../utils/feature-base'
|
|
14
|
+
import { stringify } from '../../../common/util/stringify'
|
|
15
|
+
|
|
16
|
+
export class Aggregate extends FeatureBase {
|
|
15
17
|
static featureName = FEATURE_NAME
|
|
16
18
|
constructor (agentIdentifier, aggregator) {
|
|
17
19
|
super(agentIdentifier, aggregator, FEATURE_NAME)
|
|
@@ -96,6 +98,7 @@ export class Aggregate extends AggregateBase {
|
|
|
96
98
|
try {
|
|
97
99
|
if (this.resourcesSent) return
|
|
98
100
|
const agentRuntime = getRuntime(this.agentIdentifier)
|
|
101
|
+
const info = getInfo(this.agentIdentifier)
|
|
99
102
|
// make sure this only gets sent once
|
|
100
103
|
this.resourcesSent = true
|
|
101
104
|
// differentiate between internal+external and ajax+non-ajax
|
|
@@ -122,10 +125,22 @@ export class Aggregate extends AggregateBase {
|
|
|
122
125
|
)
|
|
123
126
|
})
|
|
124
127
|
|
|
128
|
+
// Capture per-agent query bytes sent for each endpoint (see harvest) and RUM call (see page_view_event aggregator).
|
|
129
|
+
Object.keys(agentRuntime.bytesSent).forEach(endpoint => {
|
|
130
|
+
this.storeSupportabilityMetrics(
|
|
131
|
+
`PageSession/Endpoint/${endpoint.charAt(0).toUpperCase() + endpoint.slice(1)}/QueryBytesSent`,
|
|
132
|
+
agentRuntime.queryBytesSent[endpoint]
|
|
133
|
+
)
|
|
134
|
+
})
|
|
135
|
+
|
|
125
136
|
// Capture metrics for session trace if active (`ptid` is set when returned by replay ingest).
|
|
126
137
|
if (agentRuntime.ptid) {
|
|
127
138
|
this.storeSupportabilityMetrics('PageSession/Feature/SessionTrace/DurationMs', Math.round(performance.now()))
|
|
128
139
|
}
|
|
140
|
+
|
|
141
|
+
// Capture metrics for size of custom attributes
|
|
142
|
+
const jsAttributes = stringify(info.jsAttributes)
|
|
143
|
+
this.storeSupportabilityMetrics('PageSession/Feature/CustomData/Bytes', jsAttributes === '{}' ? 0 : jsAttributes.length)
|
|
129
144
|
} catch (e) {
|
|
130
145
|
// do nothing
|
|
131
146
|
}
|
|
@@ -9,12 +9,12 @@ import { registerHandler as register } from '../../../common/event-emitter/regis
|
|
|
9
9
|
import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
|
|
10
10
|
import { cleanURL } from '../../../common/url/clean-url'
|
|
11
11
|
import { getConfigurationValue, getInfo, getRuntime } from '../../../common/config/config'
|
|
12
|
-
import { AggregateBase } from '../../utils/aggregate-base'
|
|
13
12
|
import { FEATURE_NAME } from '../constants'
|
|
14
13
|
import { drain } from '../../../common/drain/drain'
|
|
15
14
|
import { isBrowserScope } from '../../../common/util/global-scope'
|
|
15
|
+
import { FeatureBase } from '../../utils/feature-base'
|
|
16
16
|
|
|
17
|
-
export class Aggregate extends
|
|
17
|
+
export class Aggregate extends FeatureBase {
|
|
18
18
|
static featureName = FEATURE_NAME
|
|
19
19
|
constructor (agentIdentifier, aggregator) {
|
|
20
20
|
super(agentIdentifier, aggregator, FEATURE_NAME)
|
|
@@ -10,15 +10,15 @@ import { paintMetrics } from '../../../common/metrics/paint-metrics'
|
|
|
10
10
|
import { submitData } from '../../../common/util/submit-data'
|
|
11
11
|
import { getConfigurationValue, getInfo, getRuntime } from '../../../common/config/config'
|
|
12
12
|
import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
|
|
13
|
-
import { AggregateBase } from '../../utils/aggregate-base'
|
|
14
13
|
import * as CONSTANTS from '../constants'
|
|
15
14
|
import { getActivatedFeaturesFlags } from './initialized-features'
|
|
16
15
|
import { globalScope, isBrowserScope } from '../../../common/util/global-scope'
|
|
17
16
|
import { drain } from '../../../common/drain/drain'
|
|
17
|
+
import { FeatureBase } from '../../utils/feature-base'
|
|
18
18
|
|
|
19
19
|
const jsonp = 'NREUM.setToken'
|
|
20
20
|
|
|
21
|
-
export class Aggregate extends
|
|
21
|
+
export class Aggregate extends FeatureBase {
|
|
22
22
|
static featureName = CONSTANTS.FEATURE_NAME
|
|
23
23
|
constructor (agentIdentifier, aggregator) {
|
|
24
24
|
super(agentIdentifier, aggregator, CONSTANTS.FEATURE_NAME)
|
|
@@ -130,7 +130,10 @@ export class Aggregate extends AggregateBase {
|
|
|
130
130
|
var queryString = fromArray(chunksForQueryString, agentRuntime.maxBytes)
|
|
131
131
|
|
|
132
132
|
// Capture bytes sent to RUM call endpoint (currently `1`) as a supportability metric. See metrics aggregator (on unload).
|
|
133
|
-
agentRuntime.bytesSent[protocol] =
|
|
133
|
+
agentRuntime.bytesSent[protocol] = 0 // Set to zero for now until RUM is moved to POST
|
|
134
|
+
|
|
135
|
+
// Capture query bytes sent to RUM call endpoint (currently `1`) as a supportability metric. See metrics aggregator (on unload).
|
|
136
|
+
agentRuntime.queryBytesSent[protocol] = (agentRuntime.queryBytesSent[protocol] || 0) + queryString?.length || 0
|
|
134
137
|
|
|
135
138
|
const isValidJsonp = submitData.jsonp(
|
|
136
139
|
this.getScheme() + '://' + info.beacon + '/' + protocol + '/' + info.licenseKey + queryString,
|
|
@@ -14,12 +14,12 @@ import { registerHandler } from '../../../common/event-emitter/register-handler'
|
|
|
14
14
|
import { cleanURL } from '../../../common/url/clean-url'
|
|
15
15
|
import { handle } from '../../../common/event-emitter/handle'
|
|
16
16
|
import { getInfo, getConfigurationValue, getRuntime } from '../../../common/config/config'
|
|
17
|
-
import { AggregateBase } from '../../utils/aggregate-base'
|
|
18
17
|
import { FEATURE_NAME } from '../constants'
|
|
19
18
|
import { drain } from '../../../common/drain/drain'
|
|
20
19
|
import { FEATURE_NAMES } from '../../../loaders/features/features'
|
|
20
|
+
import { FeatureBase } from '../../utils/feature-base'
|
|
21
21
|
|
|
22
|
-
export class Aggregate extends
|
|
22
|
+
export class Aggregate extends FeatureBase {
|
|
23
23
|
static featureName = FEATURE_NAME
|
|
24
24
|
constructor (agentIdentifier, aggregator) {
|
|
25
25
|
super(agentIdentifier, aggregator, FEATURE_NAME)
|
|
@@ -29,7 +29,7 @@ export class Aggregate extends AggregateBase {
|
|
|
29
29
|
this.curSessEndRecorded = false
|
|
30
30
|
this.cls = null // this should be null unless set to a numeric value by web-vitals so that we differentiate if CLS is supported
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
/* ! This is the section that used to be in the loader portion: ! */
|
|
33
33
|
/* ------------------------------------------------------------ */
|
|
34
34
|
const pageStartedHidden = getRuntime(agentIdentifier).initHidden // our attempt at recapturing initial vis state since this code runs post-load time
|
|
35
35
|
this.alreadySent = new Set() // since we don't support timings on BFCache restores, this tracks and helps cap metrics that web-vitals report more than once
|
|
@@ -88,10 +88,10 @@ export class Aggregate extends AggregateBase {
|
|
|
88
88
|
attributes.eid = lcpEntry.id
|
|
89
89
|
|
|
90
90
|
if (lcpEntry.url) {
|
|
91
|
-
attributes
|
|
91
|
+
attributes.elUrl = cleanURL(lcpEntry.url)
|
|
92
92
|
}
|
|
93
93
|
if (lcpEntry.element?.tagName) {
|
|
94
|
-
attributes
|
|
94
|
+
attributes.elTag = lcpEntry.element.tagName
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -181,7 +181,7 @@ export class Aggregate extends AggregateBase {
|
|
|
181
181
|
Future: onCLS value changes should be reported directly & CLS separated into its own timing node so it's not beholden to 'pageHide' firing. It'd also be possible to report the real final CLS.
|
|
182
182
|
*/
|
|
183
183
|
if (this.cls !== null) {
|
|
184
|
-
attrs
|
|
184
|
+
attrs.cls = this.cls
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
this.timings.push({
|
|
@@ -11,12 +11,12 @@ import { supportsPerformanceObserver } from '../../../common/window/supports-per
|
|
|
11
11
|
import slice from 'lodash._slice'
|
|
12
12
|
import { getConfigurationValue, getInfo, getRuntime } from '../../../common/config/config'
|
|
13
13
|
import { now } from '../../../common/timing/now'
|
|
14
|
-
import { AggregateBase } from '../../utils/aggregate-base'
|
|
15
14
|
import { FEATURE_NAME } from '../constants'
|
|
16
15
|
import { drain } from '../../../common/drain/drain'
|
|
17
16
|
import { HandlerCache } from '../../utils/handler-cache'
|
|
17
|
+
import { FeatureBase } from '../../utils/feature-base'
|
|
18
18
|
|
|
19
|
-
export class Aggregate extends
|
|
19
|
+
export class Aggregate extends FeatureBase {
|
|
20
20
|
static featureName = FEATURE_NAME
|
|
21
21
|
constructor (agentIdentifier, aggregator) {
|
|
22
22
|
super(agentIdentifier, aggregator, FEATURE_NAME)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
/*eslint no-undef: "error"*/
|
|
5
|
+
/* eslint no-undef: "error" */
|
|
6
6
|
import { registerHandler as register } from '../../../common/event-emitter/register-handler'
|
|
7
7
|
import { parseUrl } from '../../../common/url/parse-url'
|
|
8
8
|
import { shouldCollectEvent } from '../../../common/deny-list/deny-list'
|
|
@@ -13,19 +13,19 @@ import { paintMetrics } from '../../../common/metrics/paint-metrics'
|
|
|
13
13
|
import { Interaction } from './interaction'
|
|
14
14
|
import { getConfigurationValue, getRuntime } from '../../../common/config/config'
|
|
15
15
|
import { eventListenerOpts } from '../../../common/event-listener/event-listener-opts'
|
|
16
|
-
import { AggregateBase } from '../../utils/aggregate-base'
|
|
17
16
|
import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
|
|
18
17
|
import { Serializer } from './serializer'
|
|
19
18
|
import { ee } from '../../../common/event-emitter/contextual-ee'
|
|
20
19
|
import * as CONSTANTS from '../constants'
|
|
21
20
|
import { drain } from '../../../common/drain/drain'
|
|
22
21
|
import { FEATURE_NAMES } from '../../../loaders/features/features'
|
|
22
|
+
import { FeatureBase } from '../../utils/feature-base'
|
|
23
23
|
|
|
24
24
|
const {
|
|
25
25
|
FEATURE_NAME, INTERACTION_EVENTS, MAX_TIMER_BUDGET, FN_START, FN_END, CB_START, INTERACTION_API, REMAINING,
|
|
26
26
|
INTERACTION, SPA_NODE, JSONP_NODE, FETCH_START, FETCH_DONE, FETCH_BODY, JSONP_END, originalSetTimeout
|
|
27
27
|
} = CONSTANTS
|
|
28
|
-
export class Aggregate extends
|
|
28
|
+
export class Aggregate extends FeatureBase {
|
|
29
29
|
static featureName = FEATURE_NAME
|
|
30
30
|
constructor (agentIdentifier, aggregator) {
|
|
31
31
|
super(agentIdentifier, aggregator, FEATURE_NAME)
|
|
@@ -67,7 +67,7 @@ export class Aggregate extends AggregateBase {
|
|
|
67
67
|
const scheduler = new HarvestScheduler('events', {
|
|
68
68
|
onFinished: onHarvestFinished,
|
|
69
69
|
retryDelay: state.harvestTimeSeconds
|
|
70
|
-
}, { agentIdentifier })
|
|
70
|
+
}, { agentIdentifier, ee: baseEE })
|
|
71
71
|
scheduler.harvest.on('events', onHarvestStarted)
|
|
72
72
|
|
|
73
73
|
// childTime is used when calculating exclusive time for a cb duration.
|
|
@@ -212,7 +212,7 @@ export class Aggregate extends AggregateBase {
|
|
|
212
212
|
if (evName === 'click') {
|
|
213
213
|
var value = getActionText(ev.target)
|
|
214
214
|
if (value) {
|
|
215
|
-
state.currentNode.attrs.custom
|
|
215
|
+
state.currentNode.attrs.custom.actionText = value
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { getConfigurationValue, getInfo, getRuntime, setInfo } from '../../common/config/config'
|
|
2
|
+
import { drain } from '../../common/drain/drain'
|
|
3
|
+
import { ee } from '../../common/event-emitter/contextual-ee'
|
|
4
|
+
import { registerHandler } from '../../common/event-emitter/register-handler'
|
|
5
|
+
import { isBrowserScope } from '../../common/util/global-scope'
|
|
6
|
+
import { SessionEntity } from '../../common/session/session-entity'
|
|
7
|
+
import { LocalStorage } from '../../common/storage/local-storage.js'
|
|
8
|
+
import { FirstPartyCookies } from '../../common/storage/first-party-cookies'
|
|
9
|
+
import { LocalMemory } from '../../common/storage/local-memory'
|
|
10
|
+
|
|
11
|
+
let ranOnce = 0
|
|
12
|
+
export function setupAgentSession (agentIdentifier) {
|
|
13
|
+
const agentRuntime = getRuntime(agentIdentifier)
|
|
14
|
+
if (ranOnce++) return agentRuntime.session
|
|
15
|
+
|
|
16
|
+
const sharedEE = ee.get(agentIdentifier)
|
|
17
|
+
|
|
18
|
+
// domain is a string that can be specified by customer.
|
|
19
|
+
// only way to keep the session object across subdomains is using first party cookies
|
|
20
|
+
// This determines which storage wrapper the session manager will use to keep state
|
|
21
|
+
let storageAPI
|
|
22
|
+
const cookiesEnabled = getConfigurationValue(agentIdentifier, 'privacy.cookies_enabled') === true
|
|
23
|
+
if (cookiesEnabled && isBrowserScope) {
|
|
24
|
+
storageAPI = getConfigurationValue(agentIdentifier, 'session.domain')
|
|
25
|
+
? new FirstPartyCookies(getConfigurationValue(agentIdentifier, 'session.domain'))
|
|
26
|
+
: new LocalStorage()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (cookiesEnabled) {
|
|
30
|
+
// defaults to "LocalMemory" if storageAPI is undefined, such as in Worker build
|
|
31
|
+
agentRuntime.session = new SessionEntity({
|
|
32
|
+
agentIdentifier,
|
|
33
|
+
key: 'SESSION',
|
|
34
|
+
storageAPI,
|
|
35
|
+
expiresMs: getConfigurationValue(agentIdentifier, 'session.expiresMs'),
|
|
36
|
+
inactiveMs: getConfigurationValue(agentIdentifier, 'session.inactiveMs')
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// The first time the agent runs on a page, it should put everything
|
|
41
|
+
// that's currently stored in the storage API into the local info.jsAttributes object
|
|
42
|
+
if (isBrowserScope) {
|
|
43
|
+
// retrieve & re-add all of the persisted setCustomAttribute|setUserId k-v from previous page load(s)
|
|
44
|
+
const customSessionData = agentRuntime.session?.read?.()?.custom
|
|
45
|
+
const agentInfo = getInfo(agentIdentifier)
|
|
46
|
+
if (customSessionData) {
|
|
47
|
+
setInfo(agentIdentifier, { ...agentInfo, jsAttributes: { ...agentInfo.jsAttributes, ...customSessionData } })
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// any calls to newrelic.setCustomAttribute(<persisted>) will need to be added to:
|
|
52
|
+
// local info.jsAttributes {}
|
|
53
|
+
// the session's storage API
|
|
54
|
+
registerHandler('api-setCustomAttribute', (time, key, value) => {
|
|
55
|
+
agentRuntime.session.syncCustomAttribute(key, value)
|
|
56
|
+
}, 'session', sharedEE)
|
|
57
|
+
|
|
58
|
+
// any calls to newrelic.setUserId(...) will need to be added to:
|
|
59
|
+
// local info.jsAttributes {}
|
|
60
|
+
// the session's storage API
|
|
61
|
+
registerHandler('api-setUserId', (time, key, value) => {
|
|
62
|
+
agentRuntime.session.syncCustomAttribute(key, value)
|
|
63
|
+
}, 'session', sharedEE)
|
|
64
|
+
|
|
65
|
+
drain(agentIdentifier, 'session')
|
|
66
|
+
|
|
67
|
+
return agentRuntime.session
|
|
68
|
+
}
|
|
@@ -28,7 +28,7 @@ export class FeatureBase {
|
|
|
28
28
|
* loader configurations may appear after the loader code is executed.
|
|
29
29
|
*/
|
|
30
30
|
checkConfiguration () {
|
|
31
|
-
// NOTE: This check has to happen at aggregator load time
|
|
31
|
+
// NOTE: This check has to happen at aggregator load time
|
|
32
32
|
if (!isConfigured(this.agentIdentifier)) {
|
|
33
33
|
let jsAttributes = { ...gosCDN().info?.jsAttributes }
|
|
34
34
|
try {
|
|
@@ -49,13 +49,16 @@ export class InstrumentBase extends FeatureBase {
|
|
|
49
49
|
* it's only responsible for aborting its one specific feature, rather than all.
|
|
50
50
|
*/
|
|
51
51
|
try {
|
|
52
|
+
// The session entity needs to be attached to the config internals before the aggregator chunk runs
|
|
53
|
+
const { setupAgentSession } = await import(/* webpackChunkName: "session-manager" */ './agent-session')
|
|
54
|
+
setupAgentSession(this.agentIdentifier)
|
|
55
|
+
// import and instantiate the aggregator chunk
|
|
52
56
|
const { lazyLoader } = await import(/* webpackChunkName: "lazy-loader" */ './lazy-loader')
|
|
53
57
|
const { Aggregate } = await lazyLoader(this.featureName, 'aggregate')
|
|
54
58
|
new Aggregate(this.agentIdentifier, this.aggregator)
|
|
55
59
|
} catch (e) {
|
|
56
|
-
warn(`Downloading ${this.featureName} failed
|
|
60
|
+
warn(`Downloading ${this.featureName} failed...`, e)
|
|
57
61
|
this.abortHandler?.() // undo any important alterations made to the page
|
|
58
|
-
|
|
59
62
|
// not supported yet but nice to do: "abort" this agent's EE for this feature specifically
|
|
60
63
|
}
|
|
61
64
|
}
|
|
@@ -9,7 +9,7 @@ import { FEATURE_NAMES } from '../../loaders/features/features'
|
|
|
9
9
|
* should be.
|
|
10
10
|
* @param featureName Name of the feature to import such as ajax or session_trace
|
|
11
11
|
* @param featurePart Name of the feature part to load; should be either instrument or aggregate
|
|
12
|
-
* @returns {Promise<InstrumentBase|
|
|
12
|
+
* @returns {Promise<InstrumentBase|FeatureBase|null>}
|
|
13
13
|
*/
|
|
14
14
|
export function lazyLoader (featureName, featurePart) {
|
|
15
15
|
if (featurePart === 'aggregate') {
|
package/src/loaders/agent.js
CHANGED
|
@@ -68,7 +68,7 @@ export class Agent {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
const newrelic = gosNREUM()
|
|
71
|
-
delete newrelic.initializedAgents[this.agentIdentifier]?.
|
|
71
|
+
delete newrelic.initializedAgents[this.agentIdentifier]?.api // prevent further calls to agent-specific APIs (see "configure.js")
|
|
72
72
|
delete newrelic.initializedAgents[this.agentIdentifier]?.[NR_FEATURES_REF_NAME] // GC mem used internally by features
|
|
73
73
|
delete this.sharedAggregator
|
|
74
74
|
// Keep the initialized agent object with its configs for troubleshooting purposes.
|
package/src/loaders/api/api.js
CHANGED
|
@@ -9,11 +9,10 @@ import { ee } from '../../common/event-emitter/contextual-ee'
|
|
|
9
9
|
import { now } from '../../common/timing/now'
|
|
10
10
|
import { drain, registerDrain } from '../../common/drain/drain'
|
|
11
11
|
import { onWindowLoad } from '../../common/window/load'
|
|
12
|
-
import {
|
|
12
|
+
import { isWorkerScope } from '../../common/util/global-scope'
|
|
13
13
|
import { warn } from '../../common/util/console'
|
|
14
14
|
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants'
|
|
15
15
|
import { gosCDN } from '../../common/window/nreum'
|
|
16
|
-
import { putInBrowserStorage, removeFromBrowserStorage } from '../../common/window/session-storage'
|
|
17
16
|
|
|
18
17
|
export const CUSTOM_ATTR_GROUP = 'CUSTOM/' // the subgroup items should be stored under in storage API
|
|
19
18
|
|
|
@@ -81,12 +80,10 @@ export function setAPI (agentIdentifier, forceDrain) {
|
|
|
81
80
|
const currentInfo = getInfo(agentIdentifier)
|
|
82
81
|
if (value === null) {
|
|
83
82
|
delete currentInfo.jsAttributes[key]
|
|
84
|
-
if (isBrowserScope) removeFromBrowserStorage(key, CUSTOM_ATTR_GROUP) // addToBrowserStorage flag isn't needed to unset keys from storage
|
|
85
83
|
} else {
|
|
86
84
|
setInfo(agentIdentifier, { ...currentInfo, jsAttributes: { ...currentInfo.jsAttributes, [key]: value } })
|
|
87
|
-
if (isBrowserScope && addToBrowserStorage) putInBrowserStorage(key, value, CUSTOM_ATTR_GROUP)
|
|
88
85
|
}
|
|
89
|
-
return apiCall(prefix, apiName, true)()
|
|
86
|
+
return apiCall(prefix, apiName, true, (!!addToBrowserStorage || value === null) ? 'session' : undefined)(key, value)
|
|
90
87
|
}
|
|
91
88
|
apiInterface.setCustomAttribute = function (name, value, persistAttribute = false) {
|
|
92
89
|
if (typeof name !== 'string') {
|
|
@@ -3,7 +3,7 @@ import { getConfigurationValue, getInfo, getRuntime } from '../../common/config/
|
|
|
3
3
|
import { ee } from '../../common/event-emitter/contextual-ee'
|
|
4
4
|
import { handle } from '../../common/event-emitter/handle'
|
|
5
5
|
import { registerHandler } from '../../common/event-emitter/register-handler'
|
|
6
|
-
import { single } from '../../common/util/
|
|
6
|
+
import { single } from '../../common/util/invoke'
|
|
7
7
|
import { submitData } from '../../common/util/submit-data'
|
|
8
8
|
import { isBrowserScope } from '../../common/util/global-scope'
|
|
9
9
|
import { CUSTOM_METRIC_CHANNEL } from '../../features/metrics/constants'
|
|
@@ -64,6 +64,7 @@ export function setAPI (agentIdentifier) {
|
|
|
64
64
|
cycle += 1
|
|
65
65
|
|
|
66
66
|
const agentInfo = getInfo(agentIdentifier)
|
|
67
|
+
const agentRuntime = getRuntime(agentIdentifier)
|
|
67
68
|
if (!agentInfo.beacon) return
|
|
68
69
|
|
|
69
70
|
var url = scheme + '://' + agentInfo.beacon + '/1/' + agentInfo.licenseKey
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { setAPI, setTopLevelCallers
|
|
1
|
+
import { setAPI, setTopLevelCallers } from '../api/api'
|
|
2
2
|
import { addToNREUM, gosCDN, gosNREUMInitializedAgents } from '../../common/window/nreum'
|
|
3
3
|
import { setConfiguration, setInfo, setLoaderConfig, setRuntime } from '../../common/config/config'
|
|
4
4
|
import { activateFeatures, activatedFeatures } from '../../common/util/feature-flags'
|
|
5
|
-
import {
|
|
6
|
-
import { getAllStorageItemsOfGroup } from '../../common/window/session-storage'
|
|
5
|
+
import { isWorkerScope } from '../../common/util/global-scope'
|
|
7
6
|
|
|
8
7
|
export function configure (agentIdentifier, opts = {}, loaderType, forceDrain) {
|
|
9
8
|
let { init, info, loader_config, runtime = { loaderType }, exposed = true } = opts
|
|
@@ -18,10 +17,6 @@ export function configure (agentIdentifier, opts = {}, loaderType, forceDrain) {
|
|
|
18
17
|
if (isWorkerScope) { // add a default attr to all worker payloads
|
|
19
18
|
info.jsAttributes.isWorker = true
|
|
20
19
|
}
|
|
21
|
-
if (isBrowserScope) { // retrieve & re-add all of the persisted setCustomAttribute|setUserId k-v from previous page load(s)
|
|
22
|
-
let prevPageSessionJsAttrs = getAllStorageItemsOfGroup(CUSTOM_ATTR_GROUP)
|
|
23
|
-
Object.assign(info.jsAttributes, prevPageSessionJsAttrs)
|
|
24
|
-
}
|
|
25
20
|
|
|
26
21
|
setInfo(agentIdentifier, info)
|
|
27
22
|
setConfiguration(agentIdentifier, init || {})
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.single = single;
|
|
7
|
-
var _lodash = _interopRequireDefault(require("lodash._slice"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
/*
|
|
10
|
-
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
11
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
function single(fn) {
|
|
15
|
-
var called = false;
|
|
16
|
-
var res;
|
|
17
|
-
return function () {
|
|
18
|
-
if (called) return res;
|
|
19
|
-
called = true;
|
|
20
|
-
res = fn.apply(this, (0, _lodash.default)(arguments));
|
|
21
|
-
return res;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getAllStorageItemsOfGroup = getAllStorageItemsOfGroup;
|
|
7
|
-
exports.getCurrentSessionIdOrMakeNew = getCurrentSessionIdOrMakeNew;
|
|
8
|
-
exports.putInBrowserStorage = putInBrowserStorage;
|
|
9
|
-
exports.removeFromBrowserStorage = removeFromBrowserStorage;
|
|
10
|
-
var _uniqueId = require("../ids/unique-id");
|
|
11
|
-
/**
|
|
12
|
-
* Interface for Agents' usage of the Window.sessionStorage as a replacement to third-party cookies.
|
|
13
|
-
* (All agents on a tab|window will share the same sessionStorage.)
|
|
14
|
-
*
|
|
15
|
-
* @design https://newrelic.atlassian.net/wiki/spaces/INST/pages/2522513791/JSESSIONID+Cookie+Change+Design+Document
|
|
16
|
-
* @environment Browser script
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
const AGENT_PREFIX = 'NRBA/';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @param {string} key
|
|
23
|
-
* @param {string} value
|
|
24
|
-
* @returns true, if item was set successfully. false, if storage is full or setItem threw an exception.
|
|
25
|
-
*/
|
|
26
|
-
function putInBrowserStorage(key, value) {
|
|
27
|
-
let subgroup = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
28
|
-
try {
|
|
29
|
-
window.sessionStorage.setItem(AGENT_PREFIX + subgroup + key, value);
|
|
30
|
-
return true;
|
|
31
|
-
} catch (ex) {
|
|
32
|
-
// Session storage may be full.
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem}
|
|
38
|
-
* @param {string} key
|
|
39
|
-
*/
|
|
40
|
-
function getFromBrowserStorage(key) {
|
|
41
|
-
let subgroup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
42
|
-
return window.sessionStorage.getItem(AGENT_PREFIX + subgroup + key);
|
|
43
|
-
}
|
|
44
|
-
function removeFromBrowserStorage(key) {
|
|
45
|
-
let subgroup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
46
|
-
try {
|
|
47
|
-
window.sessionStorage.removeItem(AGENT_PREFIX + subgroup + key);
|
|
48
|
-
} catch (e) {}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @returns {string} This tab|window's session identifier, or a new ID if not found in storage
|
|
53
|
-
*/
|
|
54
|
-
function getCurrentSessionIdOrMakeNew() {
|
|
55
|
-
try {
|
|
56
|
-
let sessionId;
|
|
57
|
-
if ((sessionId = getFromBrowserStorage('SESSION_ID')) === null) {
|
|
58
|
-
// Generate a new one if storage is empty (no previous ID was created or currently exists)
|
|
59
|
-
sessionId = (0, _uniqueId.generateRandomHexString)(16);
|
|
60
|
-
putInBrowserStorage('SESSION_ID', sessionId);
|
|
61
|
-
}
|
|
62
|
-
return sessionId;
|
|
63
|
-
} catch (ex) {
|
|
64
|
-
// The agent is running in a security context that does not allow access to the sessionStorage or is not in browser window context.
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Look through the page's sessionStorage items and gather the ones that was set under some grouping label, if applicable.
|
|
71
|
-
* @param {string} [subgroup] - empty string by default, which will return all items set by browser agent
|
|
72
|
-
* @returns An object of the key-value items from putInBrowserStorage calls from agents with access to the same storage space.
|
|
73
|
-
*/
|
|
74
|
-
function getAllStorageItemsOfGroup() {
|
|
75
|
-
let subgroup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
76
|
-
const prefixFilter = AGENT_PREFIX + subgroup;
|
|
77
|
-
const groupItems = {};
|
|
78
|
-
try {
|
|
79
|
-
for (let i = 0; i < window.sessionStorage.length; i++) {
|
|
80
|
-
let key = window.sessionStorage.key(i);
|
|
81
|
-
if (!key.startsWith(prefixFilter)) continue;else key = key.slice(prefixFilter.length); // this removes the "NRBA/<subgroup>" prefix so we get back the original key putInBrowserStorage
|
|
82
|
-
|
|
83
|
-
groupItems[key] = getFromBrowserStorage(key, subgroup);
|
|
84
|
-
}
|
|
85
|
-
} catch (ex) {}
|
|
86
|
-
return groupItems;
|
|
87
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AggregateBase = void 0;
|
|
7
|
-
var _featureBase = require("./feature-base");
|
|
8
|
-
class AggregateBase extends _featureBase.FeatureBase {
|
|
9
|
-
constructor(agentIdentifier, aggregator, featureName) {
|
|
10
|
-
super(agentIdentifier, aggregator, featureName);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.AggregateBase = AggregateBase;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import slice from 'lodash._slice';
|
|
7
|
-
export function single(fn) {
|
|
8
|
-
var called = false;
|
|
9
|
-
var res;
|
|
10
|
-
return function () {
|
|
11
|
-
if (called) return res;
|
|
12
|
-
called = true;
|
|
13
|
-
res = fn.apply(this, slice(arguments));
|
|
14
|
-
return res;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for Agents' usage of the Window.sessionStorage as a replacement to third-party cookies.
|
|
3
|
-
* (All agents on a tab|window will share the same sessionStorage.)
|
|
4
|
-
*
|
|
5
|
-
* @design https://newrelic.atlassian.net/wiki/spaces/INST/pages/2522513791/JSESSIONID+Cookie+Change+Design+Document
|
|
6
|
-
* @environment Browser script
|
|
7
|
-
*/
|
|
8
|
-
import { generateRandomHexString } from '../ids/unique-id';
|
|
9
|
-
const AGENT_PREFIX = 'NRBA/';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {string} key
|
|
13
|
-
* @param {string} value
|
|
14
|
-
* @returns true, if item was set successfully. false, if storage is full or setItem threw an exception.
|
|
15
|
-
*/
|
|
16
|
-
export function putInBrowserStorage(key, value) {
|
|
17
|
-
let subgroup = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
18
|
-
try {
|
|
19
|
-
window.sessionStorage.setItem(AGENT_PREFIX + subgroup + key, value);
|
|
20
|
-
return true;
|
|
21
|
-
} catch (ex) {
|
|
22
|
-
// Session storage may be full.
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem}
|
|
28
|
-
* @param {string} key
|
|
29
|
-
*/
|
|
30
|
-
function getFromBrowserStorage(key) {
|
|
31
|
-
let subgroup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
32
|
-
return window.sessionStorage.getItem(AGENT_PREFIX + subgroup + key);
|
|
33
|
-
}
|
|
34
|
-
export function removeFromBrowserStorage(key) {
|
|
35
|
-
let subgroup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
36
|
-
try {
|
|
37
|
-
window.sessionStorage.removeItem(AGENT_PREFIX + subgroup + key);
|
|
38
|
-
} catch (e) {}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @returns {string} This tab|window's session identifier, or a new ID if not found in storage
|
|
43
|
-
*/
|
|
44
|
-
export function getCurrentSessionIdOrMakeNew() {
|
|
45
|
-
try {
|
|
46
|
-
let sessionId;
|
|
47
|
-
if ((sessionId = getFromBrowserStorage('SESSION_ID')) === null) {
|
|
48
|
-
// Generate a new one if storage is empty (no previous ID was created or currently exists)
|
|
49
|
-
sessionId = generateRandomHexString(16);
|
|
50
|
-
putInBrowserStorage('SESSION_ID', sessionId);
|
|
51
|
-
}
|
|
52
|
-
return sessionId;
|
|
53
|
-
} catch (ex) {
|
|
54
|
-
// The agent is running in a security context that does not allow access to the sessionStorage or is not in browser window context.
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Look through the page's sessionStorage items and gather the ones that was set under some grouping label, if applicable.
|
|
61
|
-
* @param {string} [subgroup] - empty string by default, which will return all items set by browser agent
|
|
62
|
-
* @returns An object of the key-value items from putInBrowserStorage calls from agents with access to the same storage space.
|
|
63
|
-
*/
|
|
64
|
-
export function getAllStorageItemsOfGroup() {
|
|
65
|
-
let subgroup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
66
|
-
const prefixFilter = AGENT_PREFIX + subgroup;
|
|
67
|
-
const groupItems = {};
|
|
68
|
-
try {
|
|
69
|
-
for (let i = 0; i < window.sessionStorage.length; i++) {
|
|
70
|
-
let key = window.sessionStorage.key(i);
|
|
71
|
-
if (!key.startsWith(prefixFilter)) continue;else key = key.slice(prefixFilter.length); // this removes the "NRBA/<subgroup>" prefix so we get back the original key putInBrowserStorage
|
|
72
|
-
|
|
73
|
-
groupItems[key] = getFromBrowserStorage(key, subgroup);
|
|
74
|
-
}
|
|
75
|
-
} catch (ex) {}
|
|
76
|
-
return groupItems;
|
|
77
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"single.d.ts","sourceRoot":"","sources":["../../../../src/common/util/single.js"],"names":[],"mappings":"AAOA,yDAUC"}
|