-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathinfo.js
73 lines (67 loc) · 2.31 KB
/
info.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { defaults as nrDefaults, getNREUMInitializedAgent } from '../window/nreum'
import { getModeledObject } from './configurable'
/**
* @typedef {Object} Info
* @property {string} [beacon]
* @property {string} [errorBeacon] - Base URL endpoint for all data harvested by the agent. Proxies should be defined in the init instead.
* @property {string} licenseKey - New Relic license key provided by the website in user account.
* @property {string} applicationID - New Relic application ID provided when creating a browser entity in the UI.
* @property {number} [sa]
* @property {number} [queueTime]
* @property {number} [applicationTime]
* @property {string} [ttGuid]
* @property {string} [user]
* @property {string} [account]
* @property {string} [product]
* @property {string} [extra]
* @property {Object} [jsAttributes] - Custom attributes that are added to majority of agent's payloads. The `setCustomAttribute` API method affects this.
* @property {string} [userAttributes]
* @property {string} [atts]
* @property {string} [transactionName]
* @property {string} [tNamePlain]
*/
const model = {
// preset defaults
beacon: nrDefaults.beacon,
errorBeacon: nrDefaults.errorBeacon,
// others must be populated by user
licenseKey: undefined,
applicationID: undefined,
sa: undefined,
queueTime: undefined,
applicationTime: undefined,
ttGuid: undefined,
user: undefined,
account: undefined,
product: undefined,
extra: undefined,
jsAttributes: {},
userAttributes: undefined,
atts: undefined,
transactionName: undefined,
tNamePlain: undefined
}
const _cache = {}
export function isValid (id) {
try {
const info = getInfo(id)
return (!!info.licenseKey && !!info.errorBeacon && !!info.applicationID)
} catch (err) {
return false
}
}
export function getInfo (id) {
if (!id) throw new Error('All info objects require an agent identifier!')
if (!_cache[id]) throw new Error(`Info for ${id} was never set`)
return _cache[id]
}
export function setInfo (id, obj) {
if (!id) throw new Error('All info objects require an agent identifier!')
_cache[id] = getModeledObject(obj, model)
const agentInst = getNREUMInitializedAgent(id)
if (agentInst) agentInst.info = _cache[id]
}