-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload data related to browser crashes (#503)
* Upload data related to browser crashes * switch to `os.homedir` * cleanup reportBrowserCrash * merge iterations in `findMostRecentFile`
- Loading branch information
Showing
18 changed files
with
167 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"replayio": patch | ||
--- | ||
|
||
Added automatic browser crash reporting to the Replay team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/replayio/src/utils/authentication/refreshAccessTokenOrThrow.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { readFile, writeFileSync } from "fs-extra"; | ||
import { fetch, File, FormData } from "undici"; | ||
import { replayApiServer } from "../../config"; | ||
import { findMostRecentFile } from "../../utils/findMostRecentFile"; | ||
import { getReplayPath } from "../../utils/getReplayPath"; | ||
import { getUserAgent } from "../../utils/getUserAgent"; | ||
import { checkAuthentication } from "../../utils/initialization/checkAuthentication"; | ||
import { getCurrentRuntimeMetadata } from "../../utils/initialization/getCurrentRuntimeMetadata"; | ||
import { runtimeMetadata } from "../../utils/installation/config"; | ||
import { debug } from "./debug"; | ||
|
||
export async function reportBrowserCrash(stderr: string) { | ||
const errorLogPath = getReplayPath("recorder-crash.log"); | ||
writeFileSync(errorLogPath, stderr, "utf8"); | ||
|
||
const accessToken = await checkAuthentication(); | ||
|
||
if (!accessToken) { | ||
return { | ||
errorLogPath, | ||
uploaded: false, | ||
}; | ||
} | ||
|
||
const userAgent = getUserAgent(); | ||
|
||
const formData = new FormData(); | ||
|
||
formData.set("buildId", getCurrentRuntimeMetadata("chromium")?.buildId ?? "unknown"); | ||
formData.set("createdAt", new Date().toISOString()); | ||
formData.set("userAgent", userAgent); | ||
|
||
formData.append( | ||
"log", | ||
new File([await readFile(errorLogPath)], "log.txt", { type: "text/plain" }) | ||
); | ||
|
||
const latestCrashpad = | ||
runtimeMetadata.crashpadDirectory && | ||
(await findMostRecentFile(runtimeMetadata.crashpadDirectory, fileName => | ||
fileName.endsWith(".dmp") | ||
)); | ||
if (latestCrashpad) { | ||
formData.append( | ||
"crashpad", | ||
new File([await readFile(latestCrashpad)], "crash.dmp", { type: "application/octet-stream" }) | ||
); | ||
} | ||
|
||
try { | ||
const response = await fetch(`${replayApiServer}/v1/browser-crash`, { | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
"User-Agent": userAgent, | ||
}, | ||
body: formData, | ||
}); | ||
if (response.status >= 200 && response.status < 300) { | ||
return { | ||
errorLogPath, | ||
uploaded: true, | ||
}; | ||
} | ||
} catch (err) { | ||
debug("Crash data failed to be uploaded: %o", err); | ||
} | ||
|
||
return { | ||
errorLogPath, | ||
uploaded: false, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { readdir, stat } from "fs-extra"; | ||
import { join } from "path"; | ||
|
||
export async function findMostRecentFile( | ||
directory: string, | ||
predicate: (fileName: string) => boolean = () => true | ||
) { | ||
let mostRecent = undefined as string | undefined; | ||
let mostRecentMtimeMs = 0; | ||
|
||
await Promise.all( | ||
( | ||
await readdir(directory) | ||
).map(async fileName => { | ||
const filePath = join(directory, fileName); | ||
let stats; | ||
|
||
try { | ||
stats = await stat(filePath); | ||
} catch { | ||
return; | ||
} | ||
|
||
if ( | ||
!stats.isFile() || | ||
!predicate(fileName) || | ||
(mostRecent && stats.mtimeMs < mostRecentMtimeMs) | ||
) { | ||
return; | ||
} | ||
|
||
mostRecent = filePath; | ||
mostRecentMtimeMs = stats.mtimeMs; | ||
}) | ||
); | ||
|
||
return mostRecent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/replayio/src/utils/initialization/checkForNpmUpdate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
packages/replayio/src/utils/installation/getLatestReleases.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/replayio/src/utils/recordings/metadata/legacy/source.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.