|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +// This file is the actual entry point file for Glean.js in QML, that users will interact with. |
| 6 | +// |
| 7 | +// I was not able to figure out a way to simply use the Webpack generated file to |
| 8 | +// be the entry point in Qt, because of the unusual syntax allowed in Qt Javascript. |
| 9 | +// Thus, we compile the Glean.js library normaly into the `glean.lib.js` file and then |
| 10 | +// we have this file which interacts opaquely with the Webpack generated one. |
| 11 | +// |
| 12 | +// **All functions and variables defined here are public.** |
| 13 | + |
| 14 | +.pragma library |
| 15 | + |
| 16 | +.import "glean.lib.js" as Glean |
| 17 | + |
| 18 | +/** |
| 19 | + * Initialize Glean. This method should only be called once, subsequent calls will be no-op. |
| 20 | + * |
| 21 | + * @param applicationId The application ID (will be sanitized during initialization). |
| 22 | + * @param uploadEnabled Determines whether telemetry is enabled. |
| 23 | + * If disabled, all persisted metrics, events and queued pings (except |
| 24 | + * first_run_date) are cleared. |
| 25 | + * @param config Glean configuration options. |
| 26 | + */ |
| 27 | +function initialize(applicationId, uploadEnabled, config) { |
| 28 | + Glean.Glean.default.initialize(applicationId, uploadEnabled, config); |
| 29 | +} |
| 30 | + |
| 31 | +/** |
| 32 | + * Sets whether upload is enabled or not. |
| 33 | + * |
| 34 | + * When uploading is disabled, metrics aren't recorded at all and no data is uploaded. |
| 35 | + * |
| 36 | + * When disabling, all pending metrics, events and queued pings are cleared. |
| 37 | + * |
| 38 | + * When enabling, the core Glean metrics are recreated. |
| 39 | + * |
| 40 | + * If the value of this flag is not actually changed, this is a no-op. |
| 41 | + * |
| 42 | + * If Glean has not been initialized yet, this is also a no-op. |
| 43 | + * |
| 44 | + * @param flag When true, enable metric collection. |
| 45 | + */ |
| 46 | +function setUploadEnabled(flag) { |
| 47 | + Glean.Glean.default.setUploadEnabled(flag); |
| 48 | +} |
| 49 | + |
| 50 | +/** |
| 51 | + * Sets the `logPings` flag. |
| 52 | + * |
| 53 | + * When this flag is `true` pings will be logged |
| 54 | + * to the console right before they are collected. |
| 55 | + * |
| 56 | + * @param flag Whether or not to log pings. |
| 57 | + */ |
| 58 | +function setLogPings(flag) { |
| 59 | + Glean.Glean.default.setLogPings(flag); |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * Sets the `debugViewTag` debug option. |
| 64 | + * |
| 65 | + * When this property is set, all subsequent outgoing pings will include the `X-Debug-ID` header |
| 66 | + * which will redirect them to the ["Ping Debug Viewer"](https://debug-ping-preview.firebaseapp.com/). |
| 67 | + * |
| 68 | + * To unset the `debugViewTag` call `Glean.unsetDebugViewTag(); |
| 69 | + * |
| 70 | + * @param value The value of the header. |
| 71 | + * This value must satify the regex `^[a-zA-Z0-9-]{1,20}$` otherwise it will be ignored. |
| 72 | + */ |
| 73 | +function setDebugViewTag(value) { |
| 74 | + Glean.Glean.default.setDebugViewTag(value); |
| 75 | +} |
| 76 | + |
| 77 | +/** |
| 78 | + * Sets the `sourceTags` debug option. |
| 79 | + * |
| 80 | + * Ping tags will show in the destination datasets, after ingestion. |
| 81 | + * |
| 82 | + * Note** Setting `sourceTags` will override all previously set tags. |
| 83 | + * |
| 84 | + * To unset the `sourceTags` call `Glean.unsetSourceTags(); |
| 85 | + * |
| 86 | + * @param value A vector of at most 5 valid HTTP header values. |
| 87 | + * Individual tags must match the regex: "[a-zA-Z0-9-]{1,20}". |
| 88 | + */ |
| 89 | +function setSourceTags(value) { |
| 90 | + Glean.Glean.default.setSourceTags(value); |
| 91 | +} |
| 92 | + |
| 93 | +const _private = Glean.Glean.default._private; |
0 commit comments