Skip to content

Commit

Permalink
feat: more options
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Oct 17, 2017
1 parent 9f16c0a commit cbca975
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
58 changes: 54 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,73 @@ The module enables error logging through [Sentry](http://sentry.io).
```js
{
modules: [
['@nuxtjs/sentry', {
'@nuxtjs/sentry',
],

sentry: {
public_key: '',
private_key: '',
project_id: '',
config: {
environment: process.env.NODE_ENV !== 'production' ? 'development' : 'production',
// Additional config
},
}],
]
}
}
```

## Usage

Enter your DSN in the NuxtJS config file. Additional config settings can be found [here](https://docs.sentry.io/clients/javascript/config/).

## Options

Options can be passed using either environment variables or `sentry` section in `nuxt.config.js`.
Normally setting required DSN information would be enough.

### dsn
- Type: `String`
- Default: `process.env.SENTRY_DSN`

### public_dsn
- Type: `String`
- Default: `process.env.SENTRY_PUBLIC_DSN`

If value omitted it will be generated using `dsn` value, by removing private key part.

### public_key
- Type: `String`
- Default: `process.env.SENTRY_PUBLIC_KEY`

Will be ignored if `dsn` provided.

### private_key
- Type: `String`
- Default: `process.env.SENTRY_PRIVATE_KEY`

Will be ignored if `dsn` provided.

### host
- Type: `String`
- Default: `process.env.SENTRY_HOST || 'sentry.io'`

Will be ignored if `dsn` provided.
### protocol
- Type: `String`
- Default: `process.env.SENTRY_PROTOCOL || 'https'`

Will be ignored if `dsn` provided.

### project_Id
- Type: `String`
- Default: `process.env.SENTRY_PROJECT_ID || ''`

Will be ignored if `dsn` provided.
### path
- Type: `String`
- Default: `process.env.SENTRY_PATH || '/'`

Will be ignored if `dsn` provided.

## License

[MIT License](./LICENSE)
Expand Down
36 changes: 33 additions & 3 deletions lib/sentry.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
const Raven = require('raven')
const path = require('path')

module.exports = async function sentry (options) {
module.exports = async function sentry (moduleOptions) {
// Merge options
const options = Object.assign({
dsn: process.env.SENTRY_DSN || null,
public_dsn: process.env.SENTRY_PUBLIC_DSN || null,
public_key: process.env.SENTRY_PUBLIC_KEY || null,
private_key: process.env.SENTRY_PRIVATE_KEY || null,
host: process.env.SENTRY_HOST || 'sentry.io',
protocol: process.env.SENTRY_PROTOCOL || 'https',
project_id: process.env.SENTRY_PROJECT_ID || '',
path: process.env.SENTRY_PATH || '/',
config: {
environment: this.options.dev ? 'development' : 'production'
}
}, this.options.sentry, moduleOptions)

// Generate DSN
// https://docs.sentry.io/quickstart/#about-the-dsn
if (!options.dsn || !options.dsn.length) {
options.dsn = `${options.protocol}://${options.public_key}:${options.private_key}@${options.host}${options.path}${options.project_id}`
}

// Public DSN (without private key)
if (!options.public_dsn || !options.public_dsn.length) {
options.public_dsn = options.dsn.replace(/:\w+@/, '@')
}

// Setup raven
Raven.config(`https://${options.public_key}:${options.private_key}@sentry.io/${options.project_id}`, options.config).install()
Raven.config(options.dsn, options.config).install()

// Register the client plugin
this.addPlugin({ src: path.resolve(__dirname, 'templates/sentry-client.js'), options })
this.addPlugin({
src: path.resolve(__dirname, 'templates/sentry-client.js'),
fileName: 'sentry-client.js',
options
})

// Hook in to Nuxt renderer
this.nuxt.plugin('renderer', (renderer) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/sentry-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import Raven from 'raven-js'
import RavenVue from 'raven-js/plugins/vue'

Raven
.config(`https://${options.public_key}@sentry.io/${options.project_id}`, <%= serialize(options.config) %>)
.config('<%= options.public_dsn %>', <%= serialize(options.config) %>)
.addPlugin(RavenVue, Vue)
.install()

0 comments on commit cbca975

Please sign in to comment.