Opbeat for JavaScript API

To get started, take a look at our framework specific documentation for either AngularJS or custom stacks.

config()

_opbeat('config', options);

Configure the Opbeat agent.

The available configuration options are listed below. Any configuration option can be set either in the options object or by using hyphen-separated attributes on the opbeat.js script tag.

The only required parameters are appId and orgId.

Example usage configuring appId and orgId:

_opbeat('config', {
    orgId: '<ORGANIZATION-ID>',
    appId: '<APP-ID>'
});

appId

  • Type: String

Your Opbeat app id. Required unless set via the data-app-id attribute.

orgId

  • Type: String

Your Opbeat orgainization id. Required unless set via the data-org-id attribute.

debug

  • Type: Boolean
  • Default: false

Enables logging of debug information to the console. This makes it easier for Opbeat support to troubleshoot issues.

captureException()

Send an error to Opbeat:

try {
    return multiply(add(a, b), a, b) / c
} catch (error) {
    _opbeat('captureException', error)
}

The error argument must be an Error object.

setUserContext()

To ease debugging it’s possible to send data about the user with each error or transaction you send to Opbeat.

Here is an example:

// Sending some extra details about the user
_opbeat('setUserContext', {
    username: "{{ user_name }}",
    email: "{{ user_email }}",
    id: "{{ user_id }}"
});

The following fields are allowed:

  • is_authenticated
  • id
  • username
  • email

setExtraContext()

You can also send extra data with errors or transactions:

// Sending some abitrary extra details using the `extra` field
_opbeat('setExtraContext', {
    user_type: "{{ user.type }}",
    org_name: "{{ organization.name }}",
    org_plan: "{{ organization.billing.plan }}"
});

AngularJS specific

performance

  • Type: Object
performance: {
    enable: true,
    enableStackFrames: false
}

performance.enable

  • Type: Boolean
  • Default: true

Option to enable or disable performance monitoring.

performance.enableStackFrames

  • Type: Boolean
  • Default: false

Option to enable or disable gathering stack traces for performance monitoring.

libraryPathPattern

  • Type: String
  • Default: '(node_modules|bower_components|webpack)'

Set this to paths that should be identified as libraries in stack traces. Libraries are grouped in Opbeat.