If you are building a gem that provides integration support for sentry-ruby, you can use the Sentry::Integrable module to simplify the process.
To use Sentry::Integrable, follow these requirements:
- Separate Requirement: You must explicitly
require "sentry/integrable". - Namespace: Your extension's module or class must be defined under the
Sentry namespace. - Extend: Your module must
extend Integrable. - Registration: Call
register_integration with a name and version to register it with the SDK core.
When registered, Sentry::Integrable automatically:
- Generates
.capture_exception and .capture_message methods on your module (e.g., Sentry::YourExtension.capture_exception). - Generates SDK metadata for the extension (e.g.,
{name: "sentry.ruby.your_extension", version: "1.0.0"}).
Important: Always use the generated helpers (capture_exception and capture_message) for integration-level events. These helpers inject { integration: "integration_name" } into event hints, allowing users to identify the source in before_send callbacks and ensuring the event carries the correct integration metadata.
require "sentry-ruby"
# 1. The integrable module needs to be required separately
require "sentry/integrable"
module Sentry
# 2. The module/class of the extension should be defined under the Sentry namespace
module MyExtension
# 3. Extend the module
extend Integrable
# 4. Use the register_integration method to register your extension to the SDK core
register_integration name: "my_extension", version: "1.0.0"
end
end
# Usage of generated helpers:
Sentry::MyExtension.capture_exception(StandardError.new("Something went wrong"))