Skip to content

Commit 424b067

Browse files
committed
Merge branch 'release-v2.0.1' into release
2 parents f05d13a + f74a8a5 commit 424b067

File tree

7 files changed

+34
-14
lines changed

7 files changed

+34
-14
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Unreleased changes
22

3-
[Full changelog](https://github.com/mozilla/glean.js/compare/v2.0.0...main)
3+
[Full changelog](https://github.com/mozilla/glean.js/compare/v2.0.1...main)
4+
5+
# v2.0.1 (2023-08-11)
6+
7+
[Full changelog](https://github.com/mozilla/glean.js/compare/v2.0.0...v2.0.1)
8+
9+
* [#1751](https://github.com/mozilla/glean.js/pull/1751): Add a migration flag to initialize. If not explicitly set in the `config` object the migration from IndexedDB to LocalStorage will not occur. **The only projects that should ever set this flag are those that have used Glean.js in production with a version <v2.0.0 and have upgraded.**
410

511
# v2.0.0 (2023-08-03)
612

glean/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glean/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mozilla/glean",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "An implementation of the Glean SDK, a modern cross-platform telemetry client, for JavaScript environments.",
55
"type": "module",
66
"sideEffects": false,

glean/src/core/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export interface ConfigurationInterface {
5656
readonly osVersion?: string,
5757
// The build date, provided by glean_parser
5858
readonly buildDate?: Date,
59+
// Migrate from legacy storage (IndexedDB) to the new one (LocalStorage).
60+
// This should only be true for older projects that have existing data in IndexedDB.
61+
readonly migrateFromLegacyStorage?: boolean,
5962
}
6063

6164
// Important: the `Configuration` should only be used internally by the Glean singleton.
@@ -68,6 +71,7 @@ export class Configuration implements ConfigurationInterface {
6871
readonly osVersion?: string;
6972
readonly buildDate?: Date;
7073
readonly maxEvents: number;
74+
readonly migrateFromLegacyStorage?: boolean;
7175

7276
// Debug configuration.
7377
debug: DebugOptions;
@@ -82,6 +86,7 @@ export class Configuration implements ConfigurationInterface {
8286
this.osVersion = config?.osVersion;
8387
this.buildDate = config?.buildDate;
8488
this.maxEvents = config?.maxEvents || DEFAULT_MAX_EVENTS;
89+
this.migrateFromLegacyStorage = config?.migrateFromLegacyStorage;
8590

8691
this.debug = {};
8792

glean/src/core/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const GLEAN_SCHEMA_VERSION = 1;
88
//
99
// PACKAGE_VERSION is defined as a global by webpack,
1010
// we need a default here for testing when the app is not build with webpack.
11-
export const GLEAN_VERSION = "2.0.0";
11+
export const GLEAN_VERSION = "2.0.1";
1212

1313
// The name of a "ping" that will include Glean ping_info metrics,
1414
// such as ping sequence numbers.

glean/src/core/glean/sync.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
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 { CLIENT_INFO_STORAGE, KNOWN_CLIENT_ID } from "../constants.js";
65
import type { ConfigurationInterface } from "../config.js";
6+
import type PlatformSync from "../../platform/sync.js";
7+
8+
import { CLIENT_INFO_STORAGE, KNOWN_CLIENT_ID } from "../constants.js";
79
import { Configuration } from "../config.js";
810
import PingUploadManager from "../upload/manager/sync.js";
911
import { isBoolean, isString, sanitizeApplicationId } from "../utils.js";
@@ -13,7 +15,6 @@ import { DatetimeMetric } from "../metrics/types/datetime.js";
1315
import CorePings from "../internal_pings.js";
1416
import { registerPluginToEvent } from "../events/utils/sync.js";
1517
import ErrorManagerSync from "../error/sync.js";
16-
import type PlatformSync from "../../platform/sync.js";
1718
import { Lifetime } from "../metrics/lifetime.js";
1819
import { Context } from "../context.js";
1920
import log, { LoggingLevel } from "../log.js";
@@ -42,7 +43,15 @@ namespace Glean {
4243
*/
4344
function onUploadEnabled(): void {
4445
Context.uploadEnabled = true;
45-
(Context.coreMetrics as CoreMetricsSync).initialize();
46+
}
47+
48+
/**
49+
* Initialize core metrics: client_id, first_run_date, os, etc.
50+
*
51+
* @param migrateFromLegacy Whether or not to migrate data from legacy storage.
52+
*/
53+
function initializeCoreMetrics(migrateFromLegacy?: boolean): void {
54+
(Context.coreMetrics as CoreMetricsSync).initialize(migrateFromLegacy);
4655
}
4756

4857
/**
@@ -246,6 +255,7 @@ namespace Glean {
246255
// If upload is enabled,
247256
// just follow the normal code path to instantiate the core metrics.
248257
onUploadEnabled();
258+
initializeCoreMetrics(config?.migrateFromLegacyStorage);
249259
} else {
250260
// If upload is disabled, and we've never run before, only set the
251261
// client_id to KNOWN_CLIENT_ID, but do not send a deletion request
@@ -317,6 +327,7 @@ namespace Glean {
317327
if (Context.uploadEnabled !== flag) {
318328
if (flag) {
319329
onUploadEnabled();
330+
initializeCoreMetrics(Context.config.migrateFromLegacyStorage);
320331
} else {
321332
onUploadDisabled(false);
322333
}

glean/src/core/internal_metrics/sync.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class CoreMetricsSync {
125125
);
126126
}
127127

128-
initialize(): void {
128+
initialize(migrateFromLegacyStorage?: boolean): void {
129129
// The "sync" version of Glean.js is only meant to be used in the browser.
130130
// If we cannot access the window object, then we are unable to store
131131
// any of the metric data in `localStorage`.
@@ -140,11 +140,9 @@ export class CoreMetricsSync {
140140
// Currently we are interested in migrating two things
141141
// 1. The client_id - consistent clientId across all sessions.
142142
// 2. The first_run_date - the date when the client was first run.
143-
144-
// The migration is done only once per client. The flag is set in
145-
// LocalStorage to indicate that the migration has been completed.
146-
const migrationFlag = localStorage.getItem("GLEAN_MIGRATION_FLAG");
147-
if (migrationFlag !== "1") {
143+
if (!!migrateFromLegacyStorage && localStorage.getItem("GLEAN_MIGRATION_FLAG") !== "1") {
144+
// The migration is done only once per client. The flag is set in
145+
// LocalStorage to indicate that the migration has been completed.
148146
this.migrateCoreMetricsFromIdb();
149147
localStorage.setItem("GLEAN_MIGRATION_FLAG", "1");
150148
} else {

0 commit comments

Comments
 (0)