Skip to content

Commit bed098f

Browse files
author
Beatriz Rizental
authored
Merge pull request #796 from brizental/1734197-channel
Bug 1734197 - Support setting the product's channel
2 parents 2207a8f + 55db841 commit bed098f

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.21.1...main)
44

5+
* [#796](https://github.com/mozilla/glean.js/pull/796): Support setting the `app_channel` metric.
6+
- As described in ["Release channels"](https://mozilla.github.io/glean/book/reference/general/initializing.html?highlight=channel#release-channels).
7+
58
# v0.21.1 (2021-09-30)
69

710
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.21.0...v0.21.1)

glean/src/core/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ const LOG_TAG = "core.Config";
1515
* Describes how to configure Glean.
1616
*/
1717
export interface ConfigurationInterface {
18+
// Application release channel (e.g. "beta" or "nightly").
19+
readonly channel?: string,
1820
// The build identifier generated by the CI system (e.g. "1234/A").
1921
readonly appBuild?: string,
20-
// The user visible version string fro the application running Glean.js.
22+
// The user visible version string for the application running Glean.js.
2123
readonly appDisplayVersion?: string,
2224
// The server pings are sent to.
2325
readonly serverEndpoint?: string,
@@ -31,6 +33,8 @@ export interface ConfigurationInterface {
3133

3234
// Important: the `Configuration` should only be used internally by the Glean singleton.
3335
export class Configuration implements ConfigurationInterface {
36+
// Application release channel (e.g. "beta" or "nightly").
37+
readonly channel?: string;
3438
// The build identifier generated by the CI system (e.g. "1234/A").
3539
readonly appBuild?: string;
3640
// The user visible version string fro the application running Glean.js.
@@ -43,6 +47,7 @@ export class Configuration implements ConfigurationInterface {
4347
httpClient?: Uploader;
4448

4549
constructor(config?: ConfigurationInterface) {
50+
this.channel = config?.channel;
4651
this.appBuild = config?.appBuild;
4752
this.appDisplayVersion = config?.appDisplayVersion;
4853

glean/src/core/internal_metrics.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ export class CoreMetrics {
3131
readonly architecture: StringMetricType;
3232
readonly locale: StringMetricType;
3333
// Provided by the user
34+
readonly appChannel: StringMetricType;
3435
readonly appBuild: StringMetricType;
3536
readonly appDisplayVersion: StringMetricType;
3637

38+
3739
constructor() {
3840
this.clientId = new UUIDMetricType({
3941
name: "client_id",
@@ -83,6 +85,14 @@ export class CoreMetrics {
8385
disabled: false,
8486
});
8587

88+
this.appChannel = new StringMetricType({
89+
name: "app_channel",
90+
category: "",
91+
sendInPings: ["glean_client_info"],
92+
lifetime: Lifetime.Application,
93+
disabled: false,
94+
});
95+
8696
this.appBuild = new StringMetricType({
8797
name: "app_build",
8898
category: "",
@@ -109,6 +119,9 @@ export class CoreMetrics {
109119
await StringMetricType._private_setUndispatched(this.locale, await platform.info.locale());
110120
await StringMetricType._private_setUndispatched(this.appBuild, config.appBuild || "Unknown");
111121
await StringMetricType._private_setUndispatched(this.appDisplayVersion, config.appDisplayVersion || "Unknown");
122+
if (config.channel) {
123+
await StringMetricType._private_setUndispatched(this.appChannel, config.channel);
124+
}
112125
}
113126

114127
/**

glean/tests/unit/core/pings/maker.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ describe("PingMaker", function() {
8181

8282
// Initialize will also initialize core metrics that are part of the client info.
8383
await Glean.testResetGlean(testAppId, true, {
84+
channel: "channel",
8485
appBuild:"build",
8586
appDisplayVersion: "display version",
8687
serverEndpoint: "http://localhost:8080"
@@ -94,8 +95,9 @@ describe("PingMaker", function() {
9495
assert.ok("os_version" in clientInfo2);
9596
assert.ok("architecture" in clientInfo2);
9697
assert.ok("locale" in clientInfo2);
97-
assert.ok("app_build" in clientInfo2);
98-
assert.ok("app_display_version" in clientInfo2);
98+
assert.strictEqual(clientInfo2["app_channel"], "channel");
99+
assert.strictEqual(clientInfo2["app_build"], "build");
100+
assert.strictEqual(clientInfo2["app_display_version"], "display version");
99101
});
100102

101103
it("collectPing must return `undefined` if ping that must not be sent if empty, is empty", async function() {

0 commit comments

Comments
 (0)