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.3"}
]
end
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("SENTRY_ENVIRONMENT")
end
That's it.
It will try report any errors (exceptions, throws or abnormal exits) within your application. That includes errors in any plug call (including Phoenix), Oban job, 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 handling the error.
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__)
end
More 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/0
ort:atom/0
) - The current environment name. The default value is"production"
. Learn more about environments in the official Sentry documentation.
TowerSentry
currently 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
:sentry
application directly will work and affect the reported event (outside of the options listed above, whichTowerSentry
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.
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.