-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload sourcemaps to sentry for workers-shared workers (#8094)
- Loading branch information
1 parent
1fdc88e
commit d83dd19
Showing
7 changed files
with
220 additions
and
24 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 @@ | ||
--- | ||
"@cloudflare/workers-shared": minor | ||
--- | ||
|
||
Provides sentry sourcemap generation and upload on production deploys. |
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
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,10 @@ | ||
// Generates a version tag which can be used with version upload and associated with sentry releases | ||
|
||
import { execSync } from "child_process"; | ||
|
||
try { | ||
const hash = execSync("git rev-parse --short=10 HEAD").toString().trim(); | ||
console.log(hash); | ||
} catch (error) { | ||
console.log("UNKNOWN"); | ||
} |
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 @@ | ||
// Creates a sentry release with associated sourcemaps | ||
import SentryCli from "@sentry/cli"; | ||
|
||
const requireEnvVar = (varName: string): string => { | ||
const varValue = process.env[varName]; | ||
if (varValue === undefined || varValue === "") { | ||
throw new Error(`Missing required environment variable: ${varName}`); | ||
} | ||
return varValue; | ||
}; | ||
|
||
const requireVar = (varName: string): string => { | ||
const args = process.argv.slice(2); | ||
|
||
for (let i = 0; i < args.length; i += 2) { | ||
if (args[i].startsWith("--") && args[i].substring(2) === varName) { | ||
return args[i + 1]; | ||
} | ||
} | ||
throw new Error(`Missing required variable: ${varName}`); | ||
}; | ||
|
||
// Vars | ||
const targetWorker = requireVar("worker"); | ||
const sentryRelease = requireVar("tag"); | ||
|
||
// EnvVars | ||
const sentryAuthToken = requireEnvVar("WORKERS_SHARED_SENTRY_AUTH_TOKEN"); | ||
const sentryAccessClientID = requireEnvVar("WORKERS_SHARED_SENTRY_ACCESS_ID"); | ||
const sentryAccessClientSecret = requireEnvVar( | ||
"WORKERS_SHARED_SENTRY_ACCESS_SECRET" | ||
); | ||
|
||
// Add a custom header to get through cf access | ||
const accessHeader = `cf-access-client-id: ${sentryAccessClientID} | ||
cf-access-client-secret: ${sentryAccessClientSecret}`; | ||
|
||
async function generateRelease(worker: string, release: string) { | ||
const dir = `./${worker}/dist`; | ||
console.log(`Dir path: ${dir}`); | ||
|
||
const sentryCli = new SentryCli(null, { | ||
org: "cloudflare", | ||
project: worker, | ||
url: "https://sentry10.cfdata.org/", | ||
authToken: sentryAuthToken, | ||
customHeader: accessHeader, | ||
}); | ||
|
||
console.log(`Creating release: ${release}`); | ||
await sentryCli.releases.new(release); | ||
|
||
console.log("Finalizing release"); | ||
await sentryCli.releases.finalize(release); | ||
|
||
console.log("Inject debug ids"); | ||
await sentryCli.execute(["sourcemaps", "inject", dir], true); | ||
|
||
console.log("Uploading sourcemaps"); | ||
await sentryCli.releases.uploadSourceMaps(release, { | ||
include: [dir], | ||
urlPrefix: "/", | ||
}); | ||
} | ||
|
||
generateRelease(targetWorker, sentryRelease) | ||
.then(() => | ||
console.log(`Successfully uploaded sourcemaps for ${targetWorker}`) | ||
) | ||
.catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.