Skip to content

Commit

Permalink
Overhaul SDK metrics (#5830)
Browse files Browse the repository at this point in the history
* Overhaul SDK metrics
  • Loading branch information
kneth committed Jun 9, 2023
1 parent ca790be commit 710cbf7
Show file tree
Hide file tree
Showing 10 changed files with 398 additions and 320 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
* Upgraded React Native from 0.71.4 to 0.71.7. ([#5761](https://github.com/realm/realm-js/pull/5761))
* Upgraded Realm Core from v13.10.1 to v13.11.0. ([#5811](https://github.com/realm/realm-js/issues/5811))
* Bump sync protocol to v9 to indicate client has fix for client reset error during async open. ([realm/realm-core#6609](https://github.com/realm/realm-core/issues/6609))
* Aligning analytics with other Realm SDKs. You can still disable the submission by setting environment variable `REALM_DISABLE_ANALYTICS`, and you can print out what is submitted by setting the environment variable `REALM_PRINT_ANALYTICS`.
* Disabling sync session multiplexing by default in the SDK, since Core's default changed to enabled with v13.11.0. ([#5831](https://github.com/realm/realm-js/pull/5831))

## 12.0.0-alpha.2 (2023-04-05)
Expand Down
61 changes: 45 additions & 16 deletions integration-tests/tests/src/node/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,66 @@
import * as os from "os";
import * as process from "process";
import * as path from "path";
import { fileURLToPath } from "url";

import { expect } from "chai";
import { collectPlatformData } from "realm/scripts/submit-analytics";
import { readFileSync } from "node:fs";

type Fixture = "node" | "react-native" | "electron";
import fse from "fs-extra";

// emulate old __dirname: https://flaviocopes.com/fix-dirname-not-defined-es-module-scope/
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

type Fixture = "node" | "react-native" | "electron" | "ts-node";

// TODO: Update this to use ESM friendly APIs
describe.skip("Analytics", () => {
describe("Analytics", () => {
function resolvePath(fixture: Fixture) {
return path.resolve(__dirname, "fixtures", fixture);
}

function getRealmVersion() {
const realmPath = path.resolve(__dirname, "../../../../package.json");
const realmPackageContent = readFileSync(realmPath, { encoding: "utf8" });
const realmPackageJson = JSON.parse(realmPackageContent);
return realmPackageJson["version"];
const packageJsonPath = path.resolve(__dirname, "../../../../packages/realm/package.json");
const packageJson = fse.readJsonSync(packageJsonPath);
return packageJson["version"];
}

function expectCommon(data: Record<string, unknown>) {
expect(data["JS Analytics Version"]).equals(2);
expect(data.Binding).equals("javascript");
expect(data.Language).equals("javascript");
expect(data["JS Analytics Version"]).equals(3);
expect(data.Binding).equals("Javascript");
expect(data["Host OS Type"]).equals(os.platform());
expect(data["Host OS Version"]).equals(os.release());
expect(data["Node.js version"]).equals(process.version);
expect(data["Node.js version"]).equals(process.version.slice(1)); // remove 'v'
expect(data["Realm Version"]).equals(getRealmVersion());
expect(data.token).equals("ce0fac19508f6c8f20066d345d360fd0");
expect(data["Anonymized Builder Id"]).is.not.undefined;
expect(data["Core Version"]).is.not.undefined;
expect((data["Core Version"] as string).match(/[0-9]+\.[0-9]+\.[0-9]+/)?.length).equal(1); // expect X.Y.Z
expect(data["Installation Method"]).equals("npm"); // we run our tests with NPM
}

it("parses node.js package.json", async () => {
const data = await collectPlatformData(resolvePath("node"));
expectCommon(data);
expect(data.Version).equals("1.2.3");
expect(data.Framework).equals("node.js");
expect(data["Framework Version"]).equals(process.version);
expect(data["JavaScript Engine"]).equals("v8");
expect(data["Framework Version"]).equals(process.version.slice(1)); // remove 'v'
expect(data["Runtime Engine"]).equals("v8");
expect(data["Anonymized Bundle Id"]).equals("TfvqclDWR/+6sIPfZc73MetEj0DLskCtWXjWXXXIg6k=");
expect(data.Language).equals("javascript");
expect(data["Language Version"]).equals("unknown");
});

it("parses typescript/node package.json", async () => {
const data = await collectPlatformData(resolvePath("ts-node"));
expectCommon(data);
expect(data.Version).equals("1.2.3");
expect(data.Framework).equals("node.js");
expect(data["Framework Version"]).equals(process.version.slice(1)); // remove 'v'
expect(data["Runtime Engine"]).equals("v8");
expect(data["Anonymized Bundle Id"]).equals("ajQjGK7Tztb3WeVhmPitQFDRV24loZVttnXWSlXUjEc=");
expect(data.Language).equals("typescript");
expect(data["Language Version"]).equals("3.2.1");
});

it("parses electron package.json", async () => {
Expand All @@ -64,7 +87,10 @@ describe.skip("Analytics", () => {
expect(data.Version).equals("1.2.3");
expect(data.Framework).equals("electron");
expect(data["Framework Version"]).equals("1.0.1");
expect(data["JavaScript Engine"]).equals("v8");
expect(data["Runtime Engine"]).equals("v8");
expect(data["Anonymized Bundle Id"]).equals("B4vmI2GL8s/WLRIvDt7ffHn1TeiJxNRzUPsgRfqhNOU=");
expect(data.Language).equals("javascript");
expect(data["Language Version"]).equals("unknown");
});

it("parses rn package.json", async () => {
Expand All @@ -73,6 +99,9 @@ describe.skip("Analytics", () => {
expect(data.Version).equals("1.2.3");
expect(data.Framework).equals("react-native");
expect(data["Framework Version"]).equals("1.0.1");
expect(data["JavaScript Engine"]).equals("unknown");
expect(data["Runtime Engine"]).equals("unknown");
expect(data["Anonymized Bundle Id"]).equals("1RmJBlqbKuzyRiPm4AsdIIxe8xlRUntGcGFEwUnUh6A=");
expect(data.Language).equals("javascript");
expect(data["Language Version"]).equals("unknown");
});
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "fake-ts-node-package",
"version": "1.2.3",
"devDependencies": {
"typescript": "3.2.1"
}
}
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/realm/dependencies.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REALM_CORE_VERSION=13.10.1
4 changes: 3 additions & 1 deletion packages/realm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"build:ios:debug:ios": "wireit",
"build:ios:debug:catalyst": "wireit",
"install": "prebuild-install --runtime napi || echo 'Failed to download prebuild for Realm'",
"docs": "wireit"
"docs": "wireit",
"postinstall": "node ./scripts/submit-analytics.mjs"
},
"wireit": {
"test": {
Expand Down Expand Up @@ -259,6 +260,7 @@
"dependencies": {
"debug": "^4.3.4",
"node-fetch": "^2.6.9",
"node-machine-id": "^1.1.12",
"prebuild-install": "^7.1.1"
},
"peerDependencies": {
Expand Down
Loading

0 comments on commit 710cbf7

Please sign in to comment.