@crimson-education/browser-logger 3.0.0 → 3.0.1-pinpoint-middleware.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/lib/index.d.ts +12 -12
- package/lib/index.js +69 -69
- package/lib/logger/consoleTransport.d.ts +36 -36
- package/lib/logger/consoleTransport.js +80 -80
- package/lib/logger/datadogTransport.d.ts +7 -7
- package/lib/logger/datadogTransport.js +20 -20
- package/lib/logger/index.d.ts +15 -15
- package/lib/logger/index.js +147 -147
- package/lib/logger/index.test.d.ts +1 -1
- package/lib/logger/index.test.js +59 -59
- package/lib/logger/utils.d.ts +14 -14
- package/lib/logger/utils.js +31 -31
- package/lib/reporters/amplifyReporter.d.ts +83 -77
- package/lib/reporters/amplifyReporter.d.ts.map +1 -1
- package/lib/reporters/amplifyReporter.js +162 -150
- package/lib/reporters/amplifyReporter.js.map +1 -1
- package/lib/reporters/amplifyReporter.test.d.ts +1 -1
- package/lib/reporters/amplifyReporter.test.js +50 -50
- package/lib/reporters/datadogReporter.d.ts +76 -76
- package/lib/reporters/datadogReporter.js +122 -122
- package/lib/reporters/gtmReporter.d.ts +8 -8
- package/lib/reporters/gtmReporter.js +56 -56
- package/lib/reporters/index.d.ts +66 -66
- package/lib/reporters/index.js +212 -212
- package/lib/reporters/logReporter.d.ts +34 -34
- package/lib/reporters/logReporter.js +61 -61
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.js +18 -18
- package/lib/types/logger.d.ts +77 -77
- package/lib/types/logger.js +10 -10
- package/lib/types/reporter.d.ts +154 -154
- package/lib/types/reporter.js +2 -2
- package/lib/utils.d.ts +9 -9
- package/lib/utils.js +31 -31
- package/lib/utils.test.d.ts +1 -1
- package/lib/utils.test.js +31 -31
- package/package.json +1 -1
- package/src/reporters/amplifyReporter.ts +22 -1
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { IReporter, ServiceInfo, ReporterConfigBase } from '../types';
|
|
2
|
-
import { DefaultPrivacyLevel } from '@datadog/browser-rum';
|
|
3
|
-
import { DatadogLogTransportConfig } from '../logger/datadogTransport';
|
|
4
|
-
export interface DatadogReporterConfig extends ReporterConfigBase {
|
|
5
|
-
/** The RUM application ID. */
|
|
6
|
-
applicationId: string;
|
|
7
|
-
/** A Datadog client token (Generated in the RUM Page) */
|
|
8
|
-
clientToken: string;
|
|
9
|
-
/** The Datadog site parameter of your organization. */
|
|
10
|
-
site: string;
|
|
11
|
-
/** The Application's version (Overrides the browser logger version) */
|
|
12
|
-
version?: string;
|
|
13
|
-
/** Optional proxy URL */
|
|
14
|
-
proxyUrl?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Controls the percentage of overall sessions being tracked. It defaults to 100, so every session is tracked by default.
|
|
17
|
-
*/
|
|
18
|
-
sampleRate?: number;
|
|
19
|
-
/**
|
|
20
|
-
* Applied after the overall sample rate, and controls the percentage of sessions tracked as Browser RUM & Session Replay.
|
|
21
|
-
* It defaults to 100, so every session is tracked as Browser RUM & Session Replay by default.
|
|
22
|
-
*/
|
|
23
|
-
replaySampleRate?: number;
|
|
24
|
-
/**
|
|
25
|
-
* Use a secure session cookie. This disables RUM events sent on insecure (non-HTTPS) connections.
|
|
26
|
-
*/
|
|
27
|
-
useSecureSessionCookie?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Use a secure cross-site session cookie.
|
|
30
|
-
* This allows the RUM Browser SDK to run when the site is loaded from another one (iframe). Implies `useSecureSessionCookie`
|
|
31
|
-
*/
|
|
32
|
-
useCrossSiteSessionCookie?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Preserve the session across subdomains for the same site.
|
|
35
|
-
*/
|
|
36
|
-
trackSessionAcrossSubdomains?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Forward console.error logs, uncaught exceptions and network errors to Datadog.
|
|
39
|
-
* Defaults to false.
|
|
40
|
-
*/
|
|
41
|
-
forwardConsoleLogs?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Enables automatic collection of users actions.
|
|
44
|
-
*/
|
|
45
|
-
trackInteractions?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Enables automatic collection of user frustrations. Implies `trackInteractions`: true.
|
|
48
|
-
*/
|
|
49
|
-
trackFrustrations?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Allows you to control RUM views creation.
|
|
52
|
-
* You will need to call `Logger.setPageName()` to create a new view.
|
|
53
|
-
*/
|
|
54
|
-
trackViewsManually?: boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Specify your own attribute to be used to name actions.
|
|
57
|
-
* Defaults to `data-analytics-name` to coincide with analytics attributes used across reporters.
|
|
58
|
-
*/
|
|
59
|
-
actionNameAttribute?: string;
|
|
60
|
-
/**
|
|
61
|
-
* Toggles/configures the Datadog Log Transport.
|
|
62
|
-
* Defaults to true.
|
|
63
|
-
*/
|
|
64
|
-
logTransport?: boolean | DatadogLogTransportConfig;
|
|
65
|
-
/**
|
|
66
|
-
* By enabling Session Replay, you can automatically mask sensitive elements from being recorded through the RUM Browser SDK.
|
|
67
|
-
*
|
|
68
|
-
* See https://docs.datadoghq.com/real_user_monitoring/session_replay/privacy_options
|
|
69
|
-
*/
|
|
70
|
-
defaultPrivacyLevel?: DefaultPrivacyLevel;
|
|
71
|
-
/**
|
|
72
|
-
* A list of request origins used to inject tracing headers, to be able to connect RUM and backend tracing.
|
|
73
|
-
*/
|
|
74
|
-
allowedTracingOrigins?: (string | RegExp)[];
|
|
75
|
-
}
|
|
76
|
-
export declare function datadogReporter(info: ServiceInfo, config: DatadogReporterConfig): IReporter;
|
|
1
|
+
import { IReporter, ServiceInfo, ReporterConfigBase } from '../types';
|
|
2
|
+
import { DefaultPrivacyLevel } from '@datadog/browser-rum';
|
|
3
|
+
import { DatadogLogTransportConfig } from '../logger/datadogTransport';
|
|
4
|
+
export interface DatadogReporterConfig extends ReporterConfigBase {
|
|
5
|
+
/** The RUM application ID. */
|
|
6
|
+
applicationId: string;
|
|
7
|
+
/** A Datadog client token (Generated in the RUM Page) */
|
|
8
|
+
clientToken: string;
|
|
9
|
+
/** The Datadog site parameter of your organization. */
|
|
10
|
+
site: string;
|
|
11
|
+
/** The Application's version (Overrides the browser logger version) */
|
|
12
|
+
version?: string;
|
|
13
|
+
/** Optional proxy URL */
|
|
14
|
+
proxyUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Controls the percentage of overall sessions being tracked. It defaults to 100, so every session is tracked by default.
|
|
17
|
+
*/
|
|
18
|
+
sampleRate?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Applied after the overall sample rate, and controls the percentage of sessions tracked as Browser RUM & Session Replay.
|
|
21
|
+
* It defaults to 100, so every session is tracked as Browser RUM & Session Replay by default.
|
|
22
|
+
*/
|
|
23
|
+
replaySampleRate?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Use a secure session cookie. This disables RUM events sent on insecure (non-HTTPS) connections.
|
|
26
|
+
*/
|
|
27
|
+
useSecureSessionCookie?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Use a secure cross-site session cookie.
|
|
30
|
+
* This allows the RUM Browser SDK to run when the site is loaded from another one (iframe). Implies `useSecureSessionCookie`
|
|
31
|
+
*/
|
|
32
|
+
useCrossSiteSessionCookie?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Preserve the session across subdomains for the same site.
|
|
35
|
+
*/
|
|
36
|
+
trackSessionAcrossSubdomains?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Forward console.error logs, uncaught exceptions and network errors to Datadog.
|
|
39
|
+
* Defaults to false.
|
|
40
|
+
*/
|
|
41
|
+
forwardConsoleLogs?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Enables automatic collection of users actions.
|
|
44
|
+
*/
|
|
45
|
+
trackInteractions?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Enables automatic collection of user frustrations. Implies `trackInteractions`: true.
|
|
48
|
+
*/
|
|
49
|
+
trackFrustrations?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Allows you to control RUM views creation.
|
|
52
|
+
* You will need to call `Logger.setPageName()` to create a new view.
|
|
53
|
+
*/
|
|
54
|
+
trackViewsManually?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Specify your own attribute to be used to name actions.
|
|
57
|
+
* Defaults to `data-analytics-name` to coincide with analytics attributes used across reporters.
|
|
58
|
+
*/
|
|
59
|
+
actionNameAttribute?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Toggles/configures the Datadog Log Transport.
|
|
62
|
+
* Defaults to true.
|
|
63
|
+
*/
|
|
64
|
+
logTransport?: boolean | DatadogLogTransportConfig;
|
|
65
|
+
/**
|
|
66
|
+
* By enabling Session Replay, you can automatically mask sensitive elements from being recorded through the RUM Browser SDK.
|
|
67
|
+
*
|
|
68
|
+
* See https://docs.datadoghq.com/real_user_monitoring/session_replay/privacy_options
|
|
69
|
+
*/
|
|
70
|
+
defaultPrivacyLevel?: DefaultPrivacyLevel;
|
|
71
|
+
/**
|
|
72
|
+
* A list of request origins used to inject tracing headers, to be able to connect RUM and backend tracing.
|
|
73
|
+
*/
|
|
74
|
+
allowedTracingOrigins?: (string | RegExp)[];
|
|
75
|
+
}
|
|
76
|
+
export declare function datadogReporter(info: ServiceInfo, config: DatadogReporterConfig): IReporter;
|
|
77
77
|
//# sourceMappingURL=datadogReporter.d.ts.map
|
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.datadogReporter = void 0;
|
|
4
|
-
const browser_logs_1 = require("@datadog/browser-logs");
|
|
5
|
-
const browser_rum_1 = require("@datadog/browser-rum");
|
|
6
|
-
const logger_1 = require("../logger");
|
|
7
|
-
const datadogTransport_1 = require("../logger/datadogTransport");
|
|
8
|
-
function datadogReporter(info, config) {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
10
|
-
const isLocalhost = window.location.hostname === 'localhost';
|
|
11
|
-
// Don't forward error logs by default, do enable the log transport by default
|
|
12
|
-
// forwardErrorsToLogs incorrectly is called forwardConsoleLogs, this is for backwards compatibility
|
|
13
|
-
const forwardErrorsToLogs = (_a = config.forwardConsoleLogs) !== null && _a !== void 0 ? _a : false;
|
|
14
|
-
const enableLogTransport = config.logTransport !== false;
|
|
15
|
-
// Only init datadog logs if something is using it.
|
|
16
|
-
if (forwardErrorsToLogs !== true && enableLogTransport !== true) {
|
|
17
|
-
browser_logs_1.datadogLogs.init({
|
|
18
|
-
site: config.site,
|
|
19
|
-
proxyUrl: config.proxyUrl,
|
|
20
|
-
clientToken: config.clientToken,
|
|
21
|
-
service: info.service,
|
|
22
|
-
env: info.environment,
|
|
23
|
-
version: (_b = config.version) !== null && _b !== void 0 ? _b : info.version,
|
|
24
|
-
sampleRate: (_c = config.sampleRate) !== null && _c !== void 0 ? _c : 100,
|
|
25
|
-
useSecureSessionCookie: (_d = config.useSecureSessionCookie) !== null && _d !== void 0 ? _d : !isLocalhost,
|
|
26
|
-
useCrossSiteSessionCookie: (_e = config.useCrossSiteSessionCookie) !== null && _e !== void 0 ? _e : false,
|
|
27
|
-
trackSessionAcrossSubdomains: config.trackSessionAcrossSubdomains,
|
|
28
|
-
forwardErrorsToLogs,
|
|
29
|
-
});
|
|
30
|
-
browser_logs_1.datadogLogs.logger.setHandler(browser_logs_1.HandlerType.http);
|
|
31
|
-
}
|
|
32
|
-
// Add the datadog log transport
|
|
33
|
-
if (enableLogTransport) {
|
|
34
|
-
logger_1.logTransports.push((0, datadogTransport_1.datadogTransport)(typeof config.logTransport === 'boolean' ? {} : config.logTransport));
|
|
35
|
-
}
|
|
36
|
-
browser_rum_1.datadogRum.init({
|
|
37
|
-
site: config.site,
|
|
38
|
-
proxyUrl: config.proxyUrl,
|
|
39
|
-
clientToken: config.clientToken,
|
|
40
|
-
applicationId: config.applicationId,
|
|
41
|
-
service: info.service,
|
|
42
|
-
env: info.environment,
|
|
43
|
-
version: (_f = config.version) !== null && _f !== void 0 ? _f : info.version,
|
|
44
|
-
sampleRate: (_g = config.sampleRate) !== null && _g !== void 0 ? _g : 100,
|
|
45
|
-
replaySampleRate: (_h = config.replaySampleRate) !== null && _h !== void 0 ? _h : 100,
|
|
46
|
-
useSecureSessionCookie: (_j = config.useSecureSessionCookie) !== null && _j !== void 0 ? _j : !isLocalhost,
|
|
47
|
-
useCrossSiteSessionCookie: (_k = config.useCrossSiteSessionCookie) !== null && _k !== void 0 ? _k : false,
|
|
48
|
-
trackSessionAcrossSubdomains: config.trackSessionAcrossSubdomains,
|
|
49
|
-
trackInteractions: (_l = config.trackInteractions) !== null && _l !== void 0 ? _l : false,
|
|
50
|
-
trackFrustrations: (_m = config.trackFrustrations) !== null && _m !== void 0 ? _m : false,
|
|
51
|
-
trackViewsManually: (_o = config.trackViewsManually) !== null && _o !== void 0 ? _o : false,
|
|
52
|
-
actionNameAttribute: (_p = config.actionNameAttribute) !== null && _p !== void 0 ? _p : 'data-analytics-name',
|
|
53
|
-
defaultPrivacyLevel: (_q = config.defaultPrivacyLevel) !== null && _q !== void 0 ? _q : 'mask-user-input',
|
|
54
|
-
allowedTracingOrigins: config.allowedTracingOrigins,
|
|
55
|
-
});
|
|
56
|
-
const reporter = {
|
|
57
|
-
trackEvent: function (event) {
|
|
58
|
-
browser_rum_1.datadogRum.addAction(event.message, {
|
|
59
|
-
level: event.level,
|
|
60
|
-
...event.metadata,
|
|
61
|
-
...event.tags,
|
|
62
|
-
...event.metrics,
|
|
63
|
-
});
|
|
64
|
-
},
|
|
65
|
-
addBreadcrumb: function (breadcrumb) {
|
|
66
|
-
browser_rum_1.datadogRum.addAction(breadcrumb.message, {
|
|
67
|
-
...breadcrumb.metadata,
|
|
68
|
-
category: breadcrumb.category,
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
addMetadata: function (metadata) {
|
|
72
|
-
for (const [key, value] of Object.entries(metadata)) {
|
|
73
|
-
if (value !== null) {
|
|
74
|
-
browser_rum_1.datadogRum.addRumGlobalContext(key, value);
|
|
75
|
-
// Note, this will add duplicate context data in logs.
|
|
76
|
-
// But this is valuable for logs ingested outside of the browser logger.
|
|
77
|
-
browser_logs_1.datadogLogs.addLoggerGlobalContext(key, value);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
browser_rum_1.datadogRum.removeRumGlobalContext(key);
|
|
81
|
-
// But this is valuable for logs ingested outside of the browser logger.
|
|
82
|
-
browser_logs_1.datadogLogs.removeLoggerGlobalContext(key);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
setUser: function (user) {
|
|
87
|
-
var _a;
|
|
88
|
-
if (user) {
|
|
89
|
-
browser_rum_1.datadogRum.setUser({
|
|
90
|
-
id: user.id,
|
|
91
|
-
email: user.email,
|
|
92
|
-
name: (_a = user.name) !== null && _a !== void 0 ? _a : user.email,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
browser_rum_1.datadogRum.removeUser();
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
setRouteName: function (routeName) {
|
|
100
|
-
reporter.addMetadata({ routeName });
|
|
101
|
-
},
|
|
102
|
-
setPageName: function (pageName) {
|
|
103
|
-
if (config.trackViewsManually) {
|
|
104
|
-
browser_rum_1.datadogRum.startView(pageName);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
reporter.addMetadata({ pageName });
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
reportError: function (error, metadata) {
|
|
111
|
-
browser_rum_1.datadogRum.addError(error, metadata);
|
|
112
|
-
},
|
|
113
|
-
recordSession: function () {
|
|
114
|
-
browser_rum_1.datadogRum.startSessionReplayRecording();
|
|
115
|
-
},
|
|
116
|
-
recordSessionStop: function () {
|
|
117
|
-
browser_rum_1.datadogRum.stopSessionReplayRecording();
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
return reporter;
|
|
121
|
-
}
|
|
122
|
-
exports.datadogReporter = datadogReporter;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.datadogReporter = void 0;
|
|
4
|
+
const browser_logs_1 = require("@datadog/browser-logs");
|
|
5
|
+
const browser_rum_1 = require("@datadog/browser-rum");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
const datadogTransport_1 = require("../logger/datadogTransport");
|
|
8
|
+
function datadogReporter(info, config) {
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
10
|
+
const isLocalhost = window.location.hostname === 'localhost';
|
|
11
|
+
// Don't forward error logs by default, do enable the log transport by default
|
|
12
|
+
// forwardErrorsToLogs incorrectly is called forwardConsoleLogs, this is for backwards compatibility
|
|
13
|
+
const forwardErrorsToLogs = (_a = config.forwardConsoleLogs) !== null && _a !== void 0 ? _a : false;
|
|
14
|
+
const enableLogTransport = config.logTransport !== false;
|
|
15
|
+
// Only init datadog logs if something is using it.
|
|
16
|
+
if (forwardErrorsToLogs !== true && enableLogTransport !== true) {
|
|
17
|
+
browser_logs_1.datadogLogs.init({
|
|
18
|
+
site: config.site,
|
|
19
|
+
proxyUrl: config.proxyUrl,
|
|
20
|
+
clientToken: config.clientToken,
|
|
21
|
+
service: info.service,
|
|
22
|
+
env: info.environment,
|
|
23
|
+
version: (_b = config.version) !== null && _b !== void 0 ? _b : info.version,
|
|
24
|
+
sampleRate: (_c = config.sampleRate) !== null && _c !== void 0 ? _c : 100,
|
|
25
|
+
useSecureSessionCookie: (_d = config.useSecureSessionCookie) !== null && _d !== void 0 ? _d : !isLocalhost,
|
|
26
|
+
useCrossSiteSessionCookie: (_e = config.useCrossSiteSessionCookie) !== null && _e !== void 0 ? _e : false,
|
|
27
|
+
trackSessionAcrossSubdomains: config.trackSessionAcrossSubdomains,
|
|
28
|
+
forwardErrorsToLogs,
|
|
29
|
+
});
|
|
30
|
+
browser_logs_1.datadogLogs.logger.setHandler(browser_logs_1.HandlerType.http);
|
|
31
|
+
}
|
|
32
|
+
// Add the datadog log transport
|
|
33
|
+
if (enableLogTransport) {
|
|
34
|
+
logger_1.logTransports.push((0, datadogTransport_1.datadogTransport)(typeof config.logTransport === 'boolean' ? {} : config.logTransport));
|
|
35
|
+
}
|
|
36
|
+
browser_rum_1.datadogRum.init({
|
|
37
|
+
site: config.site,
|
|
38
|
+
proxyUrl: config.proxyUrl,
|
|
39
|
+
clientToken: config.clientToken,
|
|
40
|
+
applicationId: config.applicationId,
|
|
41
|
+
service: info.service,
|
|
42
|
+
env: info.environment,
|
|
43
|
+
version: (_f = config.version) !== null && _f !== void 0 ? _f : info.version,
|
|
44
|
+
sampleRate: (_g = config.sampleRate) !== null && _g !== void 0 ? _g : 100,
|
|
45
|
+
replaySampleRate: (_h = config.replaySampleRate) !== null && _h !== void 0 ? _h : 100,
|
|
46
|
+
useSecureSessionCookie: (_j = config.useSecureSessionCookie) !== null && _j !== void 0 ? _j : !isLocalhost,
|
|
47
|
+
useCrossSiteSessionCookie: (_k = config.useCrossSiteSessionCookie) !== null && _k !== void 0 ? _k : false,
|
|
48
|
+
trackSessionAcrossSubdomains: config.trackSessionAcrossSubdomains,
|
|
49
|
+
trackInteractions: (_l = config.trackInteractions) !== null && _l !== void 0 ? _l : false,
|
|
50
|
+
trackFrustrations: (_m = config.trackFrustrations) !== null && _m !== void 0 ? _m : false,
|
|
51
|
+
trackViewsManually: (_o = config.trackViewsManually) !== null && _o !== void 0 ? _o : false,
|
|
52
|
+
actionNameAttribute: (_p = config.actionNameAttribute) !== null && _p !== void 0 ? _p : 'data-analytics-name',
|
|
53
|
+
defaultPrivacyLevel: (_q = config.defaultPrivacyLevel) !== null && _q !== void 0 ? _q : 'mask-user-input',
|
|
54
|
+
allowedTracingOrigins: config.allowedTracingOrigins,
|
|
55
|
+
});
|
|
56
|
+
const reporter = {
|
|
57
|
+
trackEvent: function (event) {
|
|
58
|
+
browser_rum_1.datadogRum.addAction(event.message, {
|
|
59
|
+
level: event.level,
|
|
60
|
+
...event.metadata,
|
|
61
|
+
...event.tags,
|
|
62
|
+
...event.metrics,
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
addBreadcrumb: function (breadcrumb) {
|
|
66
|
+
browser_rum_1.datadogRum.addAction(breadcrumb.message, {
|
|
67
|
+
...breadcrumb.metadata,
|
|
68
|
+
category: breadcrumb.category,
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
addMetadata: function (metadata) {
|
|
72
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
73
|
+
if (value !== null) {
|
|
74
|
+
browser_rum_1.datadogRum.addRumGlobalContext(key, value);
|
|
75
|
+
// Note, this will add duplicate context data in logs.
|
|
76
|
+
// But this is valuable for logs ingested outside of the browser logger.
|
|
77
|
+
browser_logs_1.datadogLogs.addLoggerGlobalContext(key, value);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
browser_rum_1.datadogRum.removeRumGlobalContext(key);
|
|
81
|
+
// But this is valuable for logs ingested outside of the browser logger.
|
|
82
|
+
browser_logs_1.datadogLogs.removeLoggerGlobalContext(key);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
setUser: function (user) {
|
|
87
|
+
var _a;
|
|
88
|
+
if (user) {
|
|
89
|
+
browser_rum_1.datadogRum.setUser({
|
|
90
|
+
id: user.id,
|
|
91
|
+
email: user.email,
|
|
92
|
+
name: (_a = user.name) !== null && _a !== void 0 ? _a : user.email,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
browser_rum_1.datadogRum.removeUser();
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
setRouteName: function (routeName) {
|
|
100
|
+
reporter.addMetadata({ routeName });
|
|
101
|
+
},
|
|
102
|
+
setPageName: function (pageName) {
|
|
103
|
+
if (config.trackViewsManually) {
|
|
104
|
+
browser_rum_1.datadogRum.startView(pageName);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
reporter.addMetadata({ pageName });
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
reportError: function (error, metadata) {
|
|
111
|
+
browser_rum_1.datadogRum.addError(error, metadata);
|
|
112
|
+
},
|
|
113
|
+
recordSession: function () {
|
|
114
|
+
browser_rum_1.datadogRum.startSessionReplayRecording();
|
|
115
|
+
},
|
|
116
|
+
recordSessionStop: function () {
|
|
117
|
+
browser_rum_1.datadogRum.stopSessionReplayRecording();
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
return reporter;
|
|
121
|
+
}
|
|
122
|
+
exports.datadogReporter = datadogReporter;
|
|
123
123
|
//# sourceMappingURL=datadogReporter.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IReporter, ServiceInfo, ReporterConfigBase } from '../types';
|
|
2
|
-
export declare type GTMReporterConfig = ReporterConfigBase;
|
|
3
|
-
declare global {
|
|
4
|
-
interface Window {
|
|
5
|
-
dataLayer?: Record<string, any>[];
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export declare function gtmReporter(info: ServiceInfo, config: GTMReporterConfig): IReporter;
|
|
1
|
+
import { IReporter, ServiceInfo, ReporterConfigBase } from '../types';
|
|
2
|
+
export declare type GTMReporterConfig = ReporterConfigBase;
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
dataLayer?: Record<string, any>[];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare function gtmReporter(info: ServiceInfo, config: GTMReporterConfig): IReporter;
|
|
9
9
|
//# sourceMappingURL=gtmReporter.d.ts.map
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gtmReporter = void 0;
|
|
4
|
-
function gtmReporter(info, config) {
|
|
5
|
-
let loadedDataLayer = !!window.dataLayer;
|
|
6
|
-
const baseMetadata = {
|
|
7
|
-
service: info.service,
|
|
8
|
-
domain: window.location.host,
|
|
9
|
-
environment: info.environment,
|
|
10
|
-
version: info.version,
|
|
11
|
-
};
|
|
12
|
-
const reporter = {
|
|
13
|
-
...config,
|
|
14
|
-
addMetadata: function (metadata) {
|
|
15
|
-
if (window.dataLayer) {
|
|
16
|
-
// Lazy load base metadata, e.g. if GTM isn't ready yet.
|
|
17
|
-
if (!loadedDataLayer) {
|
|
18
|
-
window.dataLayer.push(baseMetadata);
|
|
19
|
-
loadedDataLayer = true;
|
|
20
|
-
}
|
|
21
|
-
window.dataLayer.push(metadata);
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
trackEvent: function (event) {
|
|
25
|
-
reporter.addMetadata({
|
|
26
|
-
...event.metadata,
|
|
27
|
-
...event.tags,
|
|
28
|
-
...event.metrics,
|
|
29
|
-
event: event.message,
|
|
30
|
-
level: event.level,
|
|
31
|
-
});
|
|
32
|
-
},
|
|
33
|
-
addBreadcrumb: function (breadcrumb) {
|
|
34
|
-
reporter.addMetadata({
|
|
35
|
-
...breadcrumb.metadata,
|
|
36
|
-
event: breadcrumb.message,
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
setUser: function (user) {
|
|
40
|
-
if (user) {
|
|
41
|
-
reporter.addMetadata({ user });
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
setRouteName: function (routeName) {
|
|
45
|
-
reporter.addMetadata({ routeName });
|
|
46
|
-
},
|
|
47
|
-
setPageName: function (pageName) {
|
|
48
|
-
reporter.addMetadata({ pageName });
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
if (loadedDataLayer) {
|
|
52
|
-
reporter.addMetadata(baseMetadata);
|
|
53
|
-
}
|
|
54
|
-
return reporter;
|
|
55
|
-
}
|
|
56
|
-
exports.gtmReporter = gtmReporter;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gtmReporter = void 0;
|
|
4
|
+
function gtmReporter(info, config) {
|
|
5
|
+
let loadedDataLayer = !!window.dataLayer;
|
|
6
|
+
const baseMetadata = {
|
|
7
|
+
service: info.service,
|
|
8
|
+
domain: window.location.host,
|
|
9
|
+
environment: info.environment,
|
|
10
|
+
version: info.version,
|
|
11
|
+
};
|
|
12
|
+
const reporter = {
|
|
13
|
+
...config,
|
|
14
|
+
addMetadata: function (metadata) {
|
|
15
|
+
if (window.dataLayer) {
|
|
16
|
+
// Lazy load base metadata, e.g. if GTM isn't ready yet.
|
|
17
|
+
if (!loadedDataLayer) {
|
|
18
|
+
window.dataLayer.push(baseMetadata);
|
|
19
|
+
loadedDataLayer = true;
|
|
20
|
+
}
|
|
21
|
+
window.dataLayer.push(metadata);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
trackEvent: function (event) {
|
|
25
|
+
reporter.addMetadata({
|
|
26
|
+
...event.metadata,
|
|
27
|
+
...event.tags,
|
|
28
|
+
...event.metrics,
|
|
29
|
+
event: event.message,
|
|
30
|
+
level: event.level,
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
addBreadcrumb: function (breadcrumb) {
|
|
34
|
+
reporter.addMetadata({
|
|
35
|
+
...breadcrumb.metadata,
|
|
36
|
+
event: breadcrumb.message,
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
setUser: function (user) {
|
|
40
|
+
if (user) {
|
|
41
|
+
reporter.addMetadata({ user });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
setRouteName: function (routeName) {
|
|
45
|
+
reporter.addMetadata({ routeName });
|
|
46
|
+
},
|
|
47
|
+
setPageName: function (pageName) {
|
|
48
|
+
reporter.addMetadata({ pageName });
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
if (loadedDataLayer) {
|
|
52
|
+
reporter.addMetadata(baseMetadata);
|
|
53
|
+
}
|
|
54
|
+
return reporter;
|
|
55
|
+
}
|
|
56
|
+
exports.gtmReporter = gtmReporter;
|
|
57
57
|
//# sourceMappingURL=gtmReporter.js.map
|