forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelemetry.js
More file actions
76 lines (68 loc) · 2.08 KB
/
telemetry.js
File metadata and controls
76 lines (68 loc) · 2.08 KB
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
74
75
76
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
/**
* Usage:
*
* import { recordEvent } from "src/utils/telemetry";
*
* // Event without extra properties
* recordEvent("add_breakpoint");
*
* // Event with extra properties
* recordEvent("pause", {
* "reason": "debugger-statement",
* "collapsed_callstacks": 1
* });
*
* // If the properties are in multiple code paths and you can't send them all
* // in one go you will need to use the full telemetry API.
*
* import { Telemetry } from "devtools-modules";
*
* const telemetry = new Telemetry();
*
* // Prepare the event and define which properties to expect.
* //
* // NOTE: You CAN send properties before preparing the event.
* //
* telemetry.preparePendingEvent("devtools.main", "pause", "debugger", null, [
* "reason", "collapsed_callstacks"
* ]);
*
* // Elsewhere in another codepath send the reason property
* telemetry.addEventProperty(
* "devtools.main", "pause", "debugger", null, "reason", "debugger-statement"
* );
*
* // Elsewhere in another codepath send the collapsed_callstacks property
* telemetry.addEventProperty(
* "devtools.main", "pause", "debugger", null, "collapsed_callstacks", 1
* );
*/
// @flow
import { Telemetry } from "devtools-modules";
const telemetry = new Telemetry();
/**
* @memberof utils/telemetry
* @static
*/
export function recordEvent(eventName: string, fields: {} = {}) {
let sessionId = -1;
if (typeof window === "object" && window.parent.frameElement) {
sessionId = window.parent.frameElement.getAttribute("session_id");
}
if (typeof window === "object" && window.dbg) {
const events = window.dbg._telemetry.events;
if (!events[eventName]) {
events[eventName] = [];
}
events[eventName].push(fields);
}
/* eslint-disable camelcase */
telemetry.recordEvent("devtools.main", eventName, "debugger", null, {
session_id: sessionId,
...fields
});
/* eslint-enable camelcase */
}