Elixir error tracking and reporting to Sentry.
Tower reporter for Sentry.
Installation
Package can be installed by adding tower_sentry to your list of dependencies in mix.exs:
def deps do
[
{:tower_sentry, "~> 0.3.6"}
]
endSetup
Option A: Automated setup
$ mix tower_sentry.install
Option B: Manual setup
Tell Tower to inform TowerSentry reporter about errors.
# config/config.exs
config(
:tower,
:reporters,
[
# along any other possible reporters
TowerSentry
]
)And configure :tower_sentry (see below for details on the available configuration options).
# config/runtime.exs
if config_env() == :prod do
config :tower_sentry,
dsn: System.get_env("SENTRY_DSN"),
environment_name: System.get_env("DEPLOYMENT_ENV", to_string(config_env()))
endReporting
That's it. There's no extra source code needed to get reports in Sentry UI.
Tower will automatically report any errors (exceptions, throws or abnormal exits) occurring in your application. That includes errors in any plug call (including Phoenix), Oban jobs, async task or any other Elixir process.
Some HTTP request data will automatically be included in the report if a Plug.Conn if available when Tower handles
the error, e.g. when an exception occurs in a web request.
Manual reporting
You can manually report errors just by informing Tower about any manually caught exceptions, throws or abnormal exits.
try do
# possibly crashing code
rescue
exception ->
Tower.report_exception(exception, __STACKTRACE__)
endMore details on https://hexdocs.pm/tower/Tower.html#module-manual-reporting.
Configuration
TowerSentry supports the following configuration options:
:dsn(String.t/0) - The DSN for your Sentry project. Setting this option is mandatory. Learn more about DSNs in the official Sentry documentation.:environment_name(String.t/0oratom/0) - The current environment name. The default value is"production". Learn more about environments in the official Sentry documentation.
Note on configuring the :sentry app directly
TowerSentry currently depends on the official Sentry SDK for Elixir for some internal
functionality. It is however considered to be an implementation detail of TowerSentry.
This means that while setting some config options in the :sentry application directly will work and affect the
reported event (outside of the options listed above, which TowerSentry overrides), you are doing so at your own
risk; the :sentry dependency could be removed at any time in favor of a home grown implementation.
Also note that setting :sentry configuration options that affect event collection or filtering will have no effect
as this is entirely handled by Tower.
License
Copyright 2024 Mimiquate
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.