Skip to content

Instantly share code, notes, and snippets.

@jasonLaster
Last active October 12, 2021 15:55
Show Gist options
  • Save jasonLaster/76181fff4f1080eae4310f972bfcd69d to your computer and use it in GitHub Desktop.
Save jasonLaster/76181fff4f1080eae4310f972bfcd69d to your computer and use it in GitHub Desktop.
diff --git a/test/run.js b/test/run.js
index 15ef0c2c..c2002a84 100644
--- a/test/run.js
+++ b/test/run.js
@@ -9,6 +9,50 @@ const Manifest = require("./manifest");
const { findGeckoPath, createTestScript, tmpFile, spawnChecked, defer } = require("./utils");
const { listAllRecordings } = require("@recordreplay/recordings-cli");
+function isProductionEnvironment() {
+ // we should probably be able to check an env var to see if we're in github ci
+ // see .github/workflows directory and docs
+ return true;
+}
+
+// Notify the telemetry server about an event.
+// will probably extract this function at some point
+function pingTelemetry(event, tags) {
+ if (!isProductionEnvironment()) {
+ return;
+ }
+ const data = {
+ event,
+ ...tags,
+. commit: ???,
+ other fun metadata availble at the time (maybe author, maybe pr)
+ };
+ const text = JSON.stringify(data);
+
+ const headers = {
+ "Content-Type": "application/json",
+ "Content-Length": text.length,
+ };
+
+ // If we have an access token, include that in the header so that telemetry
+ // will associate the event with the specified user.
+ if (accessToken) {
+ headers.Authorization = `Bearer ${accessToken}`;
+ }
+
+ const options = {
+ hostname: "telemetry.replay.io",
+ por: 443,
+ path: "/",
+ method: "POST",
+ headers,
+ };
+
+ try {
+ const request = https.request(options, () => {});
+ request.on("error", e => {
+ log(`Error sending telemetry ping: ${e}`);
+ });
+ request.write(text);
+ request.end();
+ } catch (e) {}
+}
+
// This API key allows access to the whole team that holds all these test
// recordings. If someone wanted to, they could go in and delete the workspace
// or recordings in it or anything. While thats not great, it's also not
@@ -324,6 +368,11 @@ async function runTestViewer(path, local, timeout, env) {
msg += ` node https://app.replay.io/recording/${nodeRecordingId}`;
}
spawnChecked("echo", [msg], { stdio: "inherit" });
+
+ pingTelemetry("E2EFinished", {
+ success: false,
+ name: local,
+ });
}
gecko.stdout.on("data", processOutput);
@@ -338,6 +387,11 @@ async function runTestViewer(path, local, timeout, env) {
logFailure(`Exited with code ${code}`);
} else if (!passed) {
logFailure("Exited without passing test");
+ } else {
+ pingTelemetry("EndToEndTest", {
+ success: true,
+ name: local,
+ });
}
}
resolve();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment