Skip to content

Commit

Permalink
feat: sentryを導入(Vue)
Browse files Browse the repository at this point in the history
`yarn add @sentry/vue @sentry/tracing dotenv`

## 申し送り事項

- 環境変数SENTRY_DSNを設定してください
(開発環境用にdotenvを導入したので、開発環境では`.env`に指定してください)
  • Loading branch information
IkumaTadokoro committed Apr 29, 2022
1 parent a19bd54 commit 749bfb5
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/javascript/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,28 @@ import App from './App.vue'
import Maska from 'maska'
import router from './router/router'
import globalStore, { GlobalStoreKey } from './store/global'
import * as Sentry from '@sentry/vue'
import { BrowserTracing } from '@sentry/tracing'

document.addEventListener('DOMContentLoaded', () => {
const selector = '#app'
const app = document.querySelector(selector)
if (app) {
const app = createApp(App)
Sentry.init({
app,
dsn: process.env.SENTRY_DSN,
integrations: [
new BrowserTracing({
routingInstrumentation: Sentry.vueRouterInstrumentation(router),
tracingOrigins: ["localhost", "my-site-url.com", /^\//],
}),
],
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
})
app.use(Maska)
app.use(router)
app.provide(GlobalStoreKey, globalStore())
Expand Down
13 changes: 13 additions & 0 deletions config/webpack/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { environment } = require('@rails/webpacker')
const { VueLoaderPlugin } = require('vue-loader')
const vue = require('./loaders/vue')
const { DefinePlugin } = require('webpack')
const webpack = require('webpack')
const dotenv = require('dotenv')

function hotfixPostcssLoaderConfig(subloader) {
const subloaderName = subloader.loader
Expand Down Expand Up @@ -35,6 +37,17 @@ environment.config.merge({
}
})

const dotenvFiles = ['.env']
dotenvFiles.forEach((dotenvFile) => {
dotenv.config({ path: dotenvFile, silent: true})
})

environment.plugins.prepend('Environment',
new webpack.EnvironmentPlugin(
JSON.parse(JSON.stringify(process.env))
)
)

environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())
environment.plugins.prepend(
'Define',
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"@hennge/vue3-pagination": "^1.0.17",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "5.4.3",
"@sentry/tracing": "^6.19.7",
"@sentry/vue": "^6.19.7",
"@vue/compiler-sfc": "^3.2.26",
"@vueuse/core": "^7.6.2",
"autoprefixer": "^10.4.0",
Expand Down Expand Up @@ -44,6 +46,7 @@
"@vue/test-utils": "^2.0.0-rc.17",
"@vue/vue3-jest": "27.0.0-alpha.4",
"babel-jest": "^27.5.1",
"dotenv": "^16.0.0",
"eslint": "^8.5.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-cypress": "^2.12.1",
Expand Down
82 changes: 81 additions & 1 deletion yarn.lock

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

0 comments on commit 749bfb5

Please sign in to comment.