How to use the @bugsnag/js.init function in @bugsnag/js

To help you get started, we’ve selected a few @bugsnag/js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bugsnag / bugsnag-js / examples / react / src / index.js View on Github external
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'

import Bugsnag from '@bugsnag/js'
import bugsnagReact from '@bugsnag/plugin-react'

Bugsnag.use(bugsnagReact, React)

const ErrorBoundary = Bugsnag.getPlugin('react')

const ErrorScreen = () =>
    <h1><span role="img" aria-label="warning icon">⚠️</span> Error <span role="img" aria-label="warning icon">⚠️</span></h1>
    <p><strong>Uh oh, there was an error in the component tree!</strong></p>
    <p>This <code>FallbackComponent</code> prop can be used to show something useful to your users when such errors occur.</p>

const onError = event => {
  // You can also provide an onError callback to run just on errors caught by
  // the error boundary. Maybe you want to attach some of the current state from
  // whatever model/store you're using (e.g redux)
  console.log('about to send this event', { event })
github bugsnag / bugsnag-js / examples / angular / src / app / app.module.ts View on Github external
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, ErrorHandler } from '@angular/core';
// import our Angular plugin
import { BugsnagErrorHandler } from '@bugsnag/plugin-angular';
// import the bugsnag-js client you initialized in bugsnag.ts
import Bugsnag from '@bugsnag/js';
import { AppComponent } from './app.component';


// There are certain errors within Angular that get caught by its own error handler
// and only logged to the console. These errors will never make it to Bugsnag by
// themselves and so require a little wiring up.
export function errorHandlerFactory() {
  return new BugsnagErrorHandler()

  declarations: [
  imports: [
  providers: [ { provide: ErrorHandler, useFactory: errorHandlerFactory } ],
github bugsnag / bugsnag-js / examples / typescript / src / app.ts View on Github external
// include Bugsnag from the installed dependencies
import Bugsnag from '@bugsnag/js'

const apiKey: string = process.env.BUGSNAG_API_KEY ? process.env.BUGSNAG_API_KEY : ''

// initialise Bugsnag with some basic options
  // this loads the apiKey from the environment so be sure to pass it in
  apiKey: apiKey,
  // setting the appVersion is useful to track when errors are introduced/fixed
  appVersion: '1.2.3',
  // using a combination of releaseStage/notifyReleaseStages you can ensure you
  // only get reports from the environments you care about
  releaseStage: 'production',
  enabledReleaseStages: [ 'staging', 'production' ],
  // you can set global metadata when you initialise Bugsnag
  metadata: {}

  Welcome to the plain TypeScript example app. Type one of the
  following keys, followed by enter, to perform each action:
github bugsnag / bugsnag-js / examples / nuxtjs / modules / bugsnag / client.js View on Github external
import Vue from 'vue'
import Bugsnag from '@bugsnag/js'
import bugsnagVue from '@bugsnag/plugin-vue'
Bugsnag.init('<%= options.apiKey %>')
Bugsnag.use(bugsnagVue, Vue)

export default function ({ app }, inject) {
  inject('Bugsnag', Bugsnag)
github bugsnag / bugsnag-js / examples / vue / src / main.js View on Github external
import Vue from 'vue'
import App from './App.vue'

import Bugsnag from '@bugsnag/js'
import bugsnagVue from '@bugsnag/plugin-vue'

Bugsnag.use(bugsnagVue, Vue)

Vue.config.productionTip = false

new Vue({
  render: h => h(App)
github bugsnag / bugsnag-js / examples / koa / app.js View on Github external
const Bugsnag = require('@bugsnag/js')
const Koa = require('koa')
const router = require('koa-router')
const serve = require('koa-static')
const mount = require('koa-mount')
const { readFileSync } = require('fs')


const app = new Koa()
const { requestHandler, errorHandler } = Bugsnag.getPlugin('koa')


app.use(mount('/static', serve(`${__dirname}/static`)))

const index = readFileSync('./views/index.html', 'utf8')

    .get('/', (ctx, next) => {
      ctx.body = index
github bugsnag / bugsnag-js / examples / nextjs / lib / bugsnag.js View on Github external
import React from 'react'
import Bugsnag from '@bugsnag/js'
import bugsnagReact from '@bugsnag/plugin-react'
import getConfig from 'next/config'
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()

  apiKey: serverRuntimeConfig.BUGSNAG_API_KEY || publicRuntimeConfig.BUGSNAG_API_KEY
Bugsnag.use(bugsnagReact, React)

export default Bugsnag
github bugsnag / bugsnag-js / examples / nuxtjs / modules / bugsnag / index.js View on Github external
export default function (options) {
  const logger = consola.withScope('Bugsnag')'Configuring')

  const bugsnagOptions = { ...this.options.bugsnag, ...options.bugsnag }'Adding browser plugin')
    src: join(__dirname, 'client.js'),
    options: { apiKey: bugsnagOptions.browserApiKey },
    ssr: false

  Bugsnag.init({ apiKey: bugsnagOptions.serverApiKey, logger })
  Bugsnag.use(bugsnagExpress)'Adding server handlers')
  this.nuxt.hook('render:setupMiddleware', app => app.use(Bugsnag.getPlugin('express').requestHandler))
  this.nuxt.hook('render:errorMiddleware', app => app.use(Bugsnag.getPlugin('express').errorHandler))
  this.nuxt.hook('generate:routeFailed', ({ route, errors }) => {
    errors.forEach(({ error }) => Bugsnag.notify(error, event => event.addMetadata('route', route)))


Universal Javascript error reporting. Automatically detect JavaScript errors in the browser and Node.js, with plugins for React, Vue, Angular, Express, Restify and Koa.

Latest version published 5 days ago

Package Health Score

89 / 100
Full package analysis