Sentry's method cannot be called in this.$century

usacoasts
0
usacoasts
commented 5 months ago

Hello ! Thank you for the nice module

An error occurs when trying to invoke a method on an instance
Notifications are sent to sentry when an error occurs.

@ sentry / browser module' method can not be used because it can not be sent with user information etc., I am in trouble

Would you please help me?

Thank you

(example)
this.$sentry.setUserContext({{
id: 1,
username: 'test',
email: '[email protected]'
}})

this.$sentry.captureException(new Error('error test'))

Exception

TypeError: this.$sentry.setUserContext is not a function
at VueComponent.mounted (/nuxt/pages/product/id.js:1740:18)
at callHook (/nuxt/commons.app.js:13354:21) at Object.insert (/nuxt/commons.app.js:14587:7)
at invokeInsertHook (/_nuxt/commons.app.js:16382:28)
at Vue.patch as patch

(13 additional frame(s) were not displayed)
Exception

TypeError: Cannot read property 'captureException' of undefined
at VueComponent.mounted (/nuxt/pages/product/id.fa1f7c3d171eb5ab5250.hot-update.js:160:17)
at callHook (/nuxt/commons.app.js:13354:21) at insert (/nuxt/commons.app.js:14587:7)
at Object.invoker as insert
at invokeInsertHook (/_nuxt/commons.app.js:16382:28)

(8 additional frame(s) were not displayed)
package.json

"@nuxtjs/sentry": "^2.0.0",
"nuxt": "^2.2.0",
nuxt.config.js

0
aldarund
588
aldarund
commented 5 months ago

@usacoasts u can try

this.$sentry.configureScope(scope => {
  scope.setTag("a", "b");
});

Let me know if that worked

1
DiederikvandenB
395
DiederikvandenB
commented 5 months ago

Please update your question. Add formatting and provide more of your code. From what you provided, it's hard to determine the context of your code.

0
usacoasts
0
usacoasts
commented 5 months ago

@DiederikvandenB
Thank you for your response.
Add the code.
Thank you

nuxt.config.js

modules: [
'@nuxtjs/sentry'
],

sentry: {
publickey: '', projectid: '',
dsn: 'https://………[email protected]/……..',
config: {
logger: 'javascript'
},

},

_id.vue

< script >
export default {
data(){
return {
form: {
productid: null, rate: null, username: null,
comment: null
}
}
},
methods: {
async onCreate() {
try {
await this.$store.dispatch('reviews/store', this.form)
this.$router.push('/product/review/'+this.$route.params.id)
} catch(e) {
this.formError = e.message
this.$sentry.setUserContext({{id: 1, username: 'test', email: '[email protected]'}})
}
}
}
}
< /script >

0
aldarund
588
aldarund
commented 5 months ago

there no setUserContext method in last sentry sdk.

0
usacoasts
0
usacoasts
commented 5 months ago

@aldarund
Thank you for your response.
Is there an alternative method other than setUserContext ()?

0
aldarund
588
aldarund
commented 5 months ago

@usacoasts u can try

this.$sentry.configureScope(scope => {
  scope.setTag("a", "b");
});

Let me know if that worked

1
usacoasts
0
usacoasts
commented 5 months ago

@aldarund
Thank you for your response.
Thanks to you I solved it!
I was able to transmit user info using scope.setUser() method!
I appreciate very much.

this.$sentry.configureScope(scope => {
//scope.setTag("a", "b");
scope.setUser( {id: 1, username: 'test', email: '[email protected]'} )
});

0
Informations
QuestionResolved
#c30 - Created 5 months ago