Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

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

* [#796](https://github.com/mozilla/glean.js/pull/796): Support setting the `app_channel` metric.
- As described in ["Release channels"](https://mozilla.github.io/glean/book/reference/general/initializing.html?highlight=channel#release-channels).

# v0.21.1 (2021-09-30)

[Full changelog](https://github.com/mozilla/glean.js/compare/v0.21.0...v0.21.1)
Expand Down
7 changes: 6 additions & 1 deletion glean/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ const LOG_TAG = "core.Config";
* Describes how to configure Glean.
*/
export interface ConfigurationInterface {
// Application release channel (e.g. "beta" or "nightly").
readonly channel?: string,
// The build identifier generated by the CI system (e.g. "1234/A").
readonly appBuild?: string,
// The user visible version string fro the application running Glean.js.
// The user visible version string for the application running Glean.js.
readonly appDisplayVersion?: string,
// The server pings are sent to.
readonly serverEndpoint?: string,
Expand All @@ -31,6 +33,8 @@ export interface ConfigurationInterface {

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

constructor(config?: ConfigurationInterface) {
this.channel = config?.channel;
this.appBuild = config?.appBuild;
this.appDisplayVersion = config?.appDisplayVersion;

Expand Down
13 changes: 13 additions & 0 deletions glean/src/core/internal_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export class CoreMetrics {
readonly architecture: StringMetricType;
readonly locale: StringMetricType;
// Provided by the user
readonly appChannel: StringMetricType;
readonly appBuild: StringMetricType;
readonly appDisplayVersion: StringMetricType;


constructor() {
this.clientId = new UUIDMetricType({
name: "client_id",
Expand Down Expand Up @@ -83,6 +85,14 @@ export class CoreMetrics {
disabled: false,
});

this.appChannel = new StringMetricType({
name: "app_channel",
category: "",
sendInPings: ["glean_client_info"],
lifetime: Lifetime.Application,
disabled: false,
});

this.appBuild = new StringMetricType({
name: "app_build",
category: "",
Expand All @@ -109,6 +119,9 @@ export class CoreMetrics {
await StringMetricType._private_setUndispatched(this.locale, await platform.info.locale());
await StringMetricType._private_setUndispatched(this.appBuild, config.appBuild || "Unknown");
await StringMetricType._private_setUndispatched(this.appDisplayVersion, config.appDisplayVersion || "Unknown");
if (config.channel) {
await StringMetricType._private_setUndispatched(this.appChannel, config.channel);
}
}

/**
Expand Down
6 changes: 4 additions & 2 deletions glean/tests/unit/core/pings/maker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe("PingMaker", function() {

// Initialize will also initialize core metrics that are part of the client info.
await Glean.testResetGlean(testAppId, true, {
channel: "channel",
appBuild:"build",
appDisplayVersion: "display version",
serverEndpoint: "http://localhost:8080"
Expand All @@ -94,8 +95,9 @@ describe("PingMaker", function() {
assert.ok("os_version" in clientInfo2);
assert.ok("architecture" in clientInfo2);
assert.ok("locale" in clientInfo2);
assert.ok("app_build" in clientInfo2);
assert.ok("app_display_version" in clientInfo2);
assert.strictEqual(clientInfo2["app_channel"], "channel");
assert.strictEqual(clientInfo2["app_build"], "build");
assert.strictEqual(clientInfo2["app_display_version"], "display version");
});

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