-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
292 additions
and
2 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,31 @@ | ||
--- | ||
title: BugSnag | ||
{{ .EditURL }} | ||
--- | ||
|
||
The frontend code in Clutch allows a user to utilize BugSnag for their bug catching abilities. The setup when using a Gateway or the normal clutch app is quite simple as it just requires the usage of environment variables. | ||
|
||
An example is below | ||
|
||
## Structure | ||
``` | ||
frontend | ||
├─ package.json | ||
├─ .env.production | ||
├─ ... | ||
``` | ||
|
||
### Example Script in package.json | ||
```json | ||
"upload-sourcemaps": "yarn workspace @clutch-sh/tools uploadSourcemaps $PWD build/static .env.production --" | ||
``` | ||
|
||
### Example .env.production | ||
```bash | ||
REACT_APP_SERVICE_NAME=<app> | ||
REACT_APP_BUGSNAG_API_TOKEN=.... | ||
REACT_APP_BASE_URL=https://<app>.net | ||
APPLICATION_ENV=production | ||
``` | ||
|
||
And thats it, after setting up these few items Clutch will wrap the application in a BugSnag error boundary and report errors as it catches them. |
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
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,49 @@ | ||
/* eslint-disable no-console */ | ||
const { browser } = require("@bugsnag/source-maps"); | ||
const { config } = require("dotenv"); | ||
|
||
const srcDir = process.argv[2]; | ||
const buildDir = process.argv[3]; | ||
const envFile = process.argv[4]; | ||
|
||
const dotEnvFile = `${srcDir}/${envFile}`; | ||
|
||
config({ path: dotEnvFile }); | ||
|
||
const uploadToBugsnag = async ({ apiKey, baseUrl, distDir: directory }) => { | ||
try { | ||
await browser.uploadMultiple({ | ||
apiKey, | ||
baseUrl, | ||
directory, | ||
overwrite: true, | ||
}); | ||
console.info(`[BugSnag] Successfully uploaded source maps ${directory} to BugSnag`); | ||
} catch (err) { | ||
console.error(`[BugSnag] Error uploading source maps to BugSnag: ${err}`); | ||
} | ||
}; | ||
|
||
const uploadBugsnagSourcemaps = () => { | ||
const apiKey = process.env.REACT_APP_BUGSNAG_API_TOKEN || ""; | ||
const baseUrl = process.env.REACT_APP_BASE_URL || ""; | ||
if (!apiKey) { | ||
console.error(`[BugSnag] No API token found in ${dotEnvFile} file. Skipping upload.`); | ||
return Promise.reject(new Error("[BugSnag] API Key missing")); | ||
} | ||
|
||
if (!baseUrl) { | ||
console.error( | ||
`[BugSnag] No BaseUrl defined in process.env.BASE_URL in ${dotEnvFile}. Skipping Upload` | ||
); | ||
return Promise.reject(new Error("[BugSnag] BaseUrl missing")); | ||
} | ||
|
||
return uploadToBugsnag({ | ||
apiKey, | ||
baseUrl: `${baseUrl}${process.env.REACT_APP_BASE_URL_PATH ?? "/static/js/"}`, | ||
distDir: process.env.SOURCEMAPS_DIR || `${srcDir}/${buildDir}`, | ||
}); | ||
}; | ||
|
||
uploadBugsnagSourcemaps(); |
Oops, something went wrong.