Home

Awesome

Plugin Sentry

Facilitates the integration of the Sentry error tracking and monitoring service into the js-controller and adapters, allowing developers to monitor and track any errors occurring within ioBroker setups.

Purpose

By configuring Sentry.io, developers can receive real-time notifications and detailed reports of errors or exceptions in ioBroker systems, helping to identify and resolve issues promptly and ensuring the stability and reliability of home automation setups.

The integration with our Sentry server enables users to gather valuable information about the errors, including the stack trace, affected devices, and other relevant data. This information helps analyze and debug the problems effectively, leading to improved performance and stability of the ioBroker system.

Providing consent to iobroker GmbH to collect diagnostic data, results in the inclusion of an anonymous installation ID without any additional information about you, such as email or name, is included. This enables Sentry to group errors and gains insight into the number of unique users affected by a particular error. It's important to note that no IP addresses are present within crash reports, with all data deleted within 90 days at the latest.

All of these helps developers to provide an error-free smart home system that never crashes. :-)

Disabling error reporting

If you wish to deactivate the error reporting feature, you have a couple of options:

  1. Use the ioBroker CLI commands:

    • To disable Sentry for the current host, use:
      iobroker plugin disable sentry.
    • To disable Sentry for a specific adapter/instance, use:
      iobroker plugin disable sentry --instance adaptername.nr
  2. Adjust the corresponding state values:

    • For js-controller hosts, set the state "system.host.NAME.plugins.sentry.enabled" to false.
    • Set the state "system.adapter.NAME.INSTANCE.plugins.sentry.enabled" to false for adapter instances.

Upon making these changes, you should see a log message confirming the disabling of Sentry.

Note: Once the plugin is disabled, the automatic reporting of system crashes will cease. If you still want to report any issues, you must do so manually.

Plugin configuration

The minimal configuration required for inclusion in the common section of io-package.json is as follows:

"plugins": {
    "sentry": {
        "dsn": "https://...@.../..."
    }
}

Two additional optional configuration options that can be also provided if required:

"plugins": {
    "sentry": {
        "dsn": "https://...@.../...",
        "pathWhitelist": ["@iobroker", "iobroker.js-controller"],
        "pathBlacklist": ["scripts.js"],
        "errorBlacklist": ["SyntaxError"]
    }
}

The configuration includes the following settings:

Define configurations in either the "common" area of the io-package.json file or in iobroker.data/iobroker.json at the main level, specifically for the js-controller.

How can I get my Sentry account as a developer?

To obtain a Sentry account as a developer, you have a couple of options:

  1. Sentry.io: You can sign up for a free account on Sentry.io, which offers up to 5,000 monthly events at no cost. With this option, you have complete control over your account, but it's important to note that the service is hosted in the USA.

  2. Contact @Apollon77: Another option is to reach out to @Apollon77 to discuss the possibility of getting an account on the ioBroker own Sentry Server instance. However, please be aware that this option may be subject to limitations based on available server resources, so it cannot be guaranteed.

The basic process to use the ioBroker Sentry system is as follows:

  1. Contact @Apollon77 by creating an issue in this project for each adapter you require access to. Make sure to include the link to the adapter repository.
  2. We will conduct an enhanced adapter review, specifically focusing on error handling to ensure that adapters do not flood the Sentry system.
  3. We will need your email address to invite you to the Sentry instance, and you will need a Two-Factor-Authentication app (e.g., Google Authenticator) to secure your account.
  4. We will create the project on Sentry and assign it to you.
  5. We will provide you with the necessary Sentry DSN for your configuration.
  6. You must add the configuration to the io-package.json file and include a short information section in your README. Please add the following notice to the top of your README:
    **This adapter uses Sentry libraries to automatically report exceptions and code errors to the developers.** For more details and instructions on disabling error reporting, please refer to the [Sentry-Plugin Documentation](https://github.com/ioBroker/plugin-sentry#plugin-sentry)! Use of Sentry reporting starts with js-controller 3.0.
  7. We can discuss the details separately if you wish to transfer your own errors or other events.
  8. With everything finally set up, you can test and release your adapter.

Please follow these steps for smooth integration with the ioBroker Sentry system.

Plugin states

This plugin respects the "enabled" state created by system.adapter.name.X.plugins.sentry.enabled and will not initialize the error reporting if set to false.

Will not create additional states.

Usage

To catch uncaught exceptions and unhandled promises, add the configuration above to the common section of your io-package.json file. Once you have done that, you're all set. Automatic use of the plugin will occur when js-controller 3.0 is in use.

Send specific errors to Sentry

If you want to send current errors or errors you have already caught in your code to Sentry, you can use the following code in your adapter implementation. In the example, "error" refers to the Error object containing the error.

try {
    ...
    throw new Error('...');
} catch(error) {
    if (adapter.supportsFeature && adapter.supportsFeature('PLUGINS')) {
        const sentryInstance = adapter.getPluginInstance('sentry');
        if (sentryInstance) {
            sentryInstance.getSentryObject().captureException(error);
        }
    }
}

Send additional events to Sentry

You can also use other Sentry APIs offered by the JavaScript Sentry SDK to send additional events.

if (adapter.supportsFeature && adapter.supportsFeature('PLUGINS')) {
    const sentryInstance = adapter.getPluginInstance('sentry');
    if (sentryInstance) {
        const Sentry = sentryInstance.getSentryObject();
        Sentry && Sentry.withScope(scope => {
            scope.setLevel('info');
            scope.setExtra('key', 'value');
            Sentry.captureMessage('Event name', 'info'); // Level "info"
        });
    }
}

Test Sentry integration

The easiest way is to add an invalid call to your code, e.g.,

huhu();

or

setTimeout(huhu, 10000);

This should cause the adapter to crash and the exception to be shown in the sentry UI some seconds/minutes later

<!-- Placeholder for the next version (at the beginning of the line): ### **WORK IN PROGRESS** -->

Changelog

2.0.4 (2024-06-01)

Breaking Changes: Due to the port to Plugin Base v2, init now returns a promise instead of accepting a callback parameter, also the export has changed to a named export

1.2.1 (2023-06-15)

1.2.0 (2022-02-19)

1.1.10 (2021-02-09)

1.1.9 (2021-01-24)

1.1.8 (2021-01-21)

1.1.7 (2021-01-15)

1.1.6 (2020-12-28)

1.1.5 (2020-12-28)

1.1.4 (2020-06-08)

1.1.3 (2020-05-24)

1.1.2 (2020-05-12)

1.1.1 (2020-05-10)

1.1.0 (2020-05-09)

1.0.2 (2020-05-01)

1.0.0 (2020-04-26)

0.1.2 (2020-03-31)

0.1.1 (2020-03-29)

0.1.0 (2020-03-29)