Elixir error tracking and reporting to Sentry.
Tower reporter for Sentry.
Package can be installed by adding tower_sentry to your list of dependencies in mix.exs:
def deps do
[
{:tower_sentry, "~> 0.3.5"}
]
end$ mix tower_sentry.installTell 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()))
endThat'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.
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.
TowerSentry supports the following configuration options:
:dsn(t: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(t:String.t/0ort:atom/0) - The current environment name. The default value is"production". Learn more about environments in the official Sentry documentation.
TowerSentrycurrently depends on the official Sentry SDK for Elixir for some internal functionality. It is however considered to be an implementation detail ofTowerSentry.This means that while setting some config options in the
:sentryapplication directly will work and affect the reported event (outside of the options listed above, whichTowerSentryoverrides), you are doing so at your own risk; the:sentrydependency could be removed at any time in favor of a home grown implementation.Also note that setting
:sentryconfiguration options that affect event collection or filtering will have no effect as this is entirely handled by Tower.
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.0
Unless 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.