Skip to content

Commit 4220260

Browse files
author
Beatriz Rizental
authored
Merge pull request #1051 from brizental/1746375-less-is-more
Bug 1746375 - Apply various changes to make Glean.js bundle smaller
2 parents 3f1af35 + 01aa727 commit 4220260

File tree

30 files changed

+307
-374
lines changed

30 files changed

+307
-374
lines changed

benchmarks/size/max.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import QuantityMetricType from "@mozilla/glean/private/metrics/quantity";
1515
import StringMetricType from "@mozilla/glean/private/metrics/string";
1616
import TextMetricType from "@mozilla/glean/private/metrics/text";
1717
import TimespanMetricType from "@mozilla/glean/private/metrics/timespan";
18+
import RateMetricType from "@mozilla/glean/private/metrics/rate";
1819
import UUIDMetricType from "@mozilla/glean/private/metrics/uuid";
1920
import URLMetricType from "@mozilla/glean/private/metrics/url";
2021
// Plugins
@@ -33,6 +34,7 @@ console.log(
3334
JSON.stringify(StringMetricType),
3435
JSON.stringify(TextMetricType),
3536
JSON.stringify(TimespanMetricType),
37+
JSON.stringify(RateMetricType),
3638
JSON.stringify(UUIDMetricType),
3739
JSON.stringify(URLMetricType),
3840
JSON.stringify(PingEncryptionPlugin),

glean/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
"parser": "@typescript-eslint/parser",
9090
"parserOptions": {
9191
"project": ["./tsconfig.json"]
92+
},
93+
"rules": {
94+
"@typescript-eslint/no-namespace": "off"
9295
}
9396
},
9497
{

glean/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.29.0",
44
"description": "An implementation of the Glean SDK, a modern cross-platform telemetry client, for JavaScript environments.",
55
"type": "module",
6-
"sideEffects": "false",
6+
"sideEffects": false,
77
"exports": {
88
"./package.json": "./package.json",
99
"./private/metrics/*": "./dist/core/metrics/types/*.js",

glean/src/core/config.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ import { DEFAULT_TELEMETRY_ENDPOINT, GLEAN_MAX_SOURCE_TAGS } from "./constants.j
66
import type Plugin from "../plugins/index.js";
77
import { validateHeader, validateURL } from "./utils.js";
88
import type Uploader from "./upload/uploader.js";
9-
import type { DebugOptions } from "./debug_options.js";
109
import log, { LoggingLevel } from "./log.js";
1110
import { Context } from "./context.js";
1211

1312
const LOG_TAG = "core.Config";
1413

14+
/**
15+
* Lists Glean's debug options.
16+
*/
17+
export interface DebugOptions {
18+
// Whether or not lot log pings when they are collected.
19+
logPings?: boolean;
20+
// The value of the X-Debug-ID header to be included in every ping.
21+
debugViewTag?: string;
22+
// The value of the X-Source-Tags header to be included in every ping.
23+
sourceTags?: string[];
24+
}
25+
1526
/**
1627
* Describes how to configure Glean.
1728
*/
@@ -84,16 +95,24 @@ export class Configuration implements ConfigurationInterface {
8495
this.httpClient = config?.httpClient;
8596
}
8697

87-
get debugViewTag(): string {
88-
return this.debug.debugViewTag || "";
98+
get logPings(): boolean {
99+
return this.debug.logPings || false;
100+
}
101+
102+
set logPings(flag: boolean) {
103+
this.debug.logPings = flag;
104+
}
105+
106+
get debugViewTag(): string | undefined {
107+
return this.debug.debugViewTag;
89108
}
90109

91-
set debugViewTag(tag: string) {
92-
if (!validateHeader(tag)) {
110+
set debugViewTag(tag: string | undefined) {
111+
if (!validateHeader(tag || "")) {
93112
log(
94113
LOG_TAG,
95114
[
96-
`"${tag}" is not a valid \`debugViewTag\` value.`,
115+
`"${tag || ""}" is not a valid \`debugViewTag\` value.`,
97116
"Please make sure the value passed satisfies the regex `^[a-zA-Z0-9-]{1,20}$`."
98117
],
99118
LoggingLevel.Error
@@ -105,15 +124,15 @@ export class Configuration implements ConfigurationInterface {
105124
this.debug.debugViewTag = tag;
106125
}
107126

108-
get sourceTags(): string[] {
109-
return this.debug.sourceTags || [];
127+
get sourceTags(): string[] | undefined {
128+
return this.debug.sourceTags;
110129
}
111130

112-
set sourceTags(tags: string[]) {
113-
if (tags.length < 1 || tags.length > GLEAN_MAX_SOURCE_TAGS) {
131+
set sourceTags(tags: string[] | undefined) {
132+
if (!tags || tags.length < 1 || tags.length > GLEAN_MAX_SOURCE_TAGS) {
114133
log(
115134
LOG_TAG,
116-
`A list of tags cannot contain more than ${GLEAN_MAX_SOURCE_TAGS} elements.`,
135+
`A list of tags cannot contain more than ${GLEAN_MAX_SOURCE_TAGS} elements or less than one.`,
117136
LoggingLevel.Error
118137
);
119138
return;

glean/src/core/context.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import type { DebugOptions } from "./debug_options.js";
65
import type MetricsDatabase from "./metrics/database.js";
76
import type EventsDatabase from "./metrics/events_database/index.js";
87
import type PingsDatabase from "./pings/database.js";
98
import type ErrorManager from "./error/index.js";
109
import type Platform from "../platform/index.js";
1110
import Dispatcher from "./dispatcher.js";
1211
import log, { LoggingLevel } from "./log.js";
12+
import type { Configuration } from "./config.js";
1313

1414
const LOG_TAG = "core.Context";
1515

@@ -39,7 +39,7 @@ export class Context {
3939
private _pingsDatabase!: PingsDatabase;
4040
private _errorManager!: ErrorManager;
4141
private _applicationId!: string;
42-
private _debugOptions!: DebugOptions;
42+
private _config!: Configuration;
4343

4444
// Whether or not Glean is initialized.
4545
private _initialized = false;
@@ -191,22 +191,22 @@ export class Context {
191191
Context.instance._initialized = init;
192192
}
193193

194-
static get debugOptions(): DebugOptions {
195-
if (typeof Context.instance._debugOptions === "undefined") {
194+
static get config(): Configuration {
195+
if (typeof Context.instance._config === "undefined") {
196196
log(
197197
LOG_TAG,
198198
[
199-
"Attempted to access Context.debugOptions before it was set. This may cause unexpected behaviour.",
199+
"Attempted to access Context.config before it was set. This may cause unexpected behaviour.",
200200
],
201201
LoggingLevel.Trace
202202
);
203203
}
204204

205-
return Context.instance._debugOptions;
205+
return Context.instance._config;
206206
}
207207

208-
static set debugOptions(options: DebugOptions) {
209-
Context.instance._debugOptions = options;
208+
static set config(config: Configuration) {
209+
Context.instance._config = config;
210210
}
211211

212212
static get startTime(): Date {

glean/src/core/debug_options.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)