-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add crash reports and diagnostic data collection
- Loading branch information
Showing
11 changed files
with
95 additions
and
30 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
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,21 @@ | ||
import { CaptureConsole } from '@sentry/integrations'; | ||
import * as Sentry from '@sentry/react'; | ||
import { BrowserTracing } from '@sentry/tracing'; | ||
import { version } from './version'; | ||
|
||
export const initSentry = (enabled?: boolean) => { | ||
Sentry.init({ | ||
dsn: 'https://[email protected]/6539228', | ||
integrations: [ | ||
new BrowserTracing(), | ||
new CaptureConsole({ | ||
levels: ['error'], | ||
}), | ||
], | ||
sampleRate: 1, | ||
tracesSampleRate: 0.2, | ||
enabled, | ||
environment: process.env.NODE_ENV, | ||
release: version, | ||
}); | ||
}; |
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,2 @@ | ||
export const name = '@lifi/widget'; | ||
export const version = '1.4.0'; |
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,13 @@ | ||
import { useEffect } from 'react'; | ||
import { initSentry } from '../config/sentry'; | ||
|
||
export const useTelemetry = (disabled?: boolean) => { | ||
useEffect(() => { | ||
if (disabled) { | ||
console.warn( | ||
'Enable crash reports and diagnostic data to be collected. This helps us to better understand how the widget is performing and where improvements need to be made.', | ||
); | ||
initSentry(false); | ||
} | ||
}, [disabled]); | ||
}; |
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,39 @@ | ||
/* eslint-disable no-prototype-builtins */ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const glob = require('fast-glob'); | ||
|
||
const packagesPath = path.join(process.cwd(), 'packages'); | ||
const directoryPackages = glob | ||
.sync('*/package.json', { cwd: path.join(process.cwd(), 'packages') }) | ||
.map(path.dirname); | ||
|
||
async function run() { | ||
directoryPackages.forEach(async (directoryPackage) => { | ||
const packageJsonPath = path.join( | ||
packagesPath, | ||
directoryPackage, | ||
'package.json', | ||
); | ||
|
||
const json = JSON.parse(fs.readFileSync(packageJsonPath).toString()); | ||
|
||
if (json.hasOwnProperty('private')) { | ||
if (process.argv[2] === 'before') { | ||
await fs.writeFile( | ||
packageJsonPath, | ||
JSON.stringify({ ...json, private: false }, null, 2), | ||
); | ||
console.log(`Change ${directoryPackage} private: false.`); | ||
} else { | ||
await fs.writeFile( | ||
packageJsonPath, | ||
JSON.stringify({ ...json, private: true }, null, 2), | ||
); | ||
console.log(`Change ${directoryPackage} private: true.`); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
run(); |
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