Skip to content

Commit

Permalink
feat: add bugsnag reporting to the CLI application (#5640)
Browse files Browse the repository at this point in the history
* feat: add bugsnag reporting to the CLI application

* chore: only report error if it exits
  • Loading branch information
lukasholzer authored Apr 19, 2023
1 parent 30d9a4f commit 865e7a1
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 75 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: ['14.18.0', '*']
fail-fast: false
steps:
# Sets an output parameter if this is a release PR
- name: Check for release
Expand Down
43 changes: 43 additions & 0 deletions functions/error-reporting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import process from 'process'

import Bugsnag from '@bugsnag/js'
import { Handler } from '@netlify/functions'

Bugsnag.start({
apiKey: `${process.env.NETLIFY_BUGSNAG_API_KEY}`,
})

export const handler: Handler = async ({ body }) => {
try {
if (typeof body !== 'string') {
return { statusCode: 200 }
}
const {
cause,
cliVersion,
message,
name,
nodejsVersion,
osName,
severity = 'error',
stack,
user,
} = JSON.parse(body)
Bugsnag.notify({ name, message, stack, cause }, (event) => {
event.setUser(user.id, user.email, user.name)
event.severity = severity
event.device = {
osName,
runtimeVersions: {
nodejs: nodejsVersion,
cli: cliVersion,
},
}
})
} catch (error) {
Bugsnag.notify(error)
}
return {
statusCode: 200,
}
}
6 changes: 6 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
to = "/.netlify/functions/telemetry"
status = 200
force = true
[[redirects]]
# Bugsnag link
from = "/report-error"
to = "/.netlify/functions/error-reporting"
status = 200
force = true
[[redirects]]
# Old CLI download links.
from = "/download/latest/mac"
Expand Down
151 changes: 87 additions & 64 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"prettier": "--ignore-path .eslintignore --loglevel=warn \"{src,tools,scripts,site,tests,.github}/**/*.{mjs,cjs,js,md,yml,json,html}\" \"*.{mjs,cjs,js,yml,json,html}\" \".*.{mjs,cjs,js,yml,json,html}\" \"!CHANGELOG.md\" \"!**/*/package-lock.json\" \"!.github/**/*.md\""
},
"dependencies": {
"@bugsnag/js": "^7.20.0",
"@fastify/static": "^6.6.0",
"@netlify/build": "^29.9.2",
"@netlify/config": "^20.3.7",
Expand Down Expand Up @@ -186,6 +187,7 @@
"devDependencies": {
"@babel/preset-react": "^7.12.13",
"@netlify/eslint-config-node": "^7.0.0",
"@netlify/functions": "^1.4.0",
"@types/fs-extra": "^11.0.1",
"@types/prettyjson": "^0.0.30",
"@vitest/coverage-c8": "^0.30.1",
Expand Down
Loading

1 comment on commit 865e7a1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Package size: 302 MB

Please sign in to comment.