Skip to content

Commit

Permalink
fixup! feat: initialize sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyslbw committed Oct 1, 2024
1 parent 36d03c3 commit 65fedc5
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copy this file as .env
# It's used for authentication when uploading source maps.
SENTRY_AUTH_TOKEN=
SENTRY_ORG=
SENTRY_PROJECT=
SENTRY_DSN=
6 changes: 0 additions & 6 deletions .env.template.sentry-build-plugin

This file was deleted.

7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ jobs:
run: npm test
- name: Generates Secrets File
run: |
echo "export default { PROJECT_ID_MAINNET: '${{ secrets.PROJECT_ID_MAINNET }}', PROJECT_ID_PREVIEW: '${{ secrets.PROJECT_ID_PREVIEW }}', PROJECT_ID_PREPROD: '${{ secrets.PROJECT_ID_PREPROD }}', SENTRY_DSN: '${{ secrets.SENTRY_DSN }}'};" > secrets.production.js
echo "export default { PROJECT_ID_MAINNET: '${{ secrets.PROJECT_ID_MAINNET }}', PROJECT_ID_PREVIEW: '${{ secrets.PROJECT_ID_PREVIEW }}', PROJECT_ID_PREPROD: '${{ secrets.PROJECT_ID_PREPROD }}'};" > secrets.production.js
- name: Build
run: npm run build
with:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
- name: Upload build
uses: actions/upload-artifact@v4
with:
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand All @@ -23,6 +24,3 @@ secrets.development.js

# IDEs
.idea

# Sentry Config File
.env.sentry-build-plugin
19 changes: 19 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.8.1",
"dotenv-defaults": "^5.0.2",
"eslint": "^8.54.0",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-flowtype": "^8.0.3",
Expand Down
1 change: 0 additions & 1 deletion secrets.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export default {
PROJECT_ID_TESTNET: 'DUMMY_TESTNET',
PROJECT_ID_PREVIEW: 'DUMMY_PREVIEW',
PROJECT_ID_PREPROD: 'DUMMY_PREPROD',
SENTRY_DSN: 'DUMMY_SENTRY_DSN'
};
3 changes: 1 addition & 2 deletions src/features/sentry.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as Sentry from '@sentry/react';
import secrets from 'secrets';

Sentry.init({
environment: process.env.NODE_ENV,
dsn: secrets.SENTRY_DSN,
dsn: process.env.SENTRY_DSN,
integrations: [
Sentry.browserTracingIntegration(),
Sentry.browserProfilingIntegration(),
Expand Down
2 changes: 1 addition & 1 deletion src/ui/app/tabs/createWallet.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* hw.jsx is the entry point for the hardware wallet extension tab
* hw.jsx is the entry point for the harware wallet extension tab
*/

import React from 'react';
Expand Down
2 changes: 1 addition & 1 deletion src/ui/app/tabs/hw.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* hw.jsx is the entry point for the hardware wallet extension tab
* hw.jsx is the entry point for the harware wallet extension tab
*/

import React from 'react';
Expand Down
43 changes: 26 additions & 17 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ var alias = {};
// load the secrets
var secretsPath = path.join(__dirname, 'secrets.' + env.NODE_ENV + '.js');

require('dotenv-defaults').config({
path: './.env',
encoding: 'utf8'
});

var fileExtensions = [
'jpg',
'jpeg',
Expand All @@ -37,12 +42,16 @@ if (fileSystem.existsSync(secretsPath)) {
const isDevelopment = process.env.NODE_ENV === 'development';

const hasSentryConfig =
process.env.SENTRY_AUTH_TOKEN &&
process.env.SENTRY_ORG &&
process.env.SENTRY_PROJECT
!!process.env.SENTRY_AUTH_TOKEN &&
!!process.env.SENTRY_ORG &&
!!process.env.SENTRY_PROJECT &&
!!process.env.SENTRY_DSN

const withMaybeSentry = (p) => hasSentryConfig ? [ path.join(__dirname, 'src', 'features', 'sentry.js'), p ] : p;

const envsToExpose = ['NODE_ENV'];
if (hasSentryConfig) envsToExpose.push('SENTRY_DSN');

var options = {
devtool: 'source-map',
experiments: {
Expand All @@ -54,24 +63,24 @@ var options = {
internalPopup: withMaybeSentry(path.join(__dirname, 'src', 'ui', 'indexInternal.jsx')),
hwTab: withMaybeSentry(path.join(__dirname, 'src', 'ui', 'app', 'tabs', 'hw.jsx')),
createWalletTab: withMaybeSentry(path.join(
__dirname,
'src',
'ui',
'app',
'tabs',
'createWallet.jsx'
)),
__dirname,
'src',
'ui',
'app',
'tabs',
'createWallet.jsx'
)),
trezorTx: withMaybeSentry(path.join(__dirname, 'src', 'ui', 'app', 'tabs', 'trezorTx.jsx')),
background: withMaybeSentry(path.join(__dirname, 'src', 'pages', 'Background', 'index.js')),
contentScript: withMaybeSentry(path.join(__dirname, 'src', 'pages', 'Content', 'index.js')),
injected: withMaybeSentry(path.join(__dirname, 'src', 'pages', 'Content', 'injected.js')),
trezorContentScript: withMaybeSentry(path.join(
__dirname,
'src',
'pages',
'Content',
'trezorContentScript.js'
))
__dirname,
'src',
'pages',
'Content',
'trezorContentScript.js'
))
},
chromeExtensionBoilerplate: {
notHotReload: ['contentScript', 'devtools', 'injected'],
Expand Down Expand Up @@ -179,7 +188,7 @@ var options = {
cleanStaleWebpackAssets: true,
}),
// expose and write the allowed env vars on the compiled bundle
new webpack.EnvironmentPlugin(['NODE_ENV']),
new webpack.EnvironmentPlugin(envsToExpose),
new CopyWebpackPlugin({
patterns: [
{
Expand Down

0 comments on commit 65fedc5

Please sign in to comment.