mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
fix(infra): Inline sentry logging config (#8031)
It appears that something is initializing the Sentry.LoggerHandler
before we try to load it when starting:
```
Invalid logger handler config: {:logger,
{:invalid_handler, {:function_not_exported, {Sentry.LoggerHandler, :log, 2}}}}
```
This doesn't seem to actually inhibit the Sentry logger at all,
presumably because it initializes just fine in the application start
callback.
Instead of defining the config in the `config/` directory, we can pass
it directly to `:logger` on start which solves the above issue.
This commit is contained in:
@@ -8,7 +8,14 @@ defmodule Domain.Application do
|
||||
_ = OpentelemetryLoggerMetadata.setup()
|
||||
_ = OpentelemetryEcto.setup([:domain, :repo])
|
||||
|
||||
Logger.add_handlers(:logger)
|
||||
# Configure Sentry to capture Logger messages
|
||||
:logger.add_handler(:sentry, Sentry.LoggerHandler, %{
|
||||
config: %{
|
||||
level: :warning,
|
||||
metadata: :all,
|
||||
capture_log_messages: true
|
||||
}
|
||||
})
|
||||
|
||||
# Can be uncommented when this bug is fixed: https://github.com/open-telemetry/opentelemetry-erlang-contrib/issues/327
|
||||
# _ = OpentelemetryFinch.setup()
|
||||
|
||||
@@ -232,17 +232,6 @@ config :logger, :default_formatter,
|
||||
format: "$time $metadata[$level] $message\n",
|
||||
metadata: :all
|
||||
|
||||
config :logger, :logger, [
|
||||
{:handler, :sentry, Sentry.LoggerHandler,
|
||||
%{
|
||||
config: %{
|
||||
level: :warning,
|
||||
metadata: :all,
|
||||
capture_log_messages: true
|
||||
}
|
||||
}}
|
||||
]
|
||||
|
||||
# Use Jason for JSON parsing in Phoenix
|
||||
config :phoenix, :json_library, Jason
|
||||
|
||||
|
||||
@@ -236,34 +236,36 @@ if config_env() == :prod do
|
||||
|
||||
# Sentry
|
||||
|
||||
api_external_url_host = URI.parse(compile_config!(:api_external_url)).host
|
||||
|
||||
sentry_environment_name =
|
||||
case api_external_url_host do
|
||||
"api.firezone.dev" -> :production
|
||||
"api.firez.one" -> :staging
|
||||
_ -> :unknown
|
||||
end
|
||||
|
||||
sentry_dsn =
|
||||
case api_external_url_host do
|
||||
"api.firezone.dev" ->
|
||||
"https://29f4ab7c6c473c17bc01f8aeffb0ac16@o4507971108339712.ingest.us.sentry.io/4508756715569152"
|
||||
|
||||
"api.firez.one" ->
|
||||
"https://29f4ab7c6c473c17bc01f8aeffb0ac16@o4507971108339712.ingest.us.sentry.io/4508756715569152"
|
||||
|
||||
_ ->
|
||||
nil
|
||||
end
|
||||
|
||||
# Base Sentry config
|
||||
config :sentry,
|
||||
dsn: sentry_dsn,
|
||||
environment_name: sentry_environment_name,
|
||||
dsn:
|
||||
"https://29f4ab7c6c473c17bc01f8aeffb0ac16@o4507971108339712.ingest.us.sentry.io/4508756715569152",
|
||||
environment_name: :unknown,
|
||||
enable_source_code_context: true,
|
||||
root_source_code_paths: [
|
||||
Path.join(File.cwd!(), "apps/domain"),
|
||||
Path.join(File.cwd!(), "apps/web"),
|
||||
Path.join(File.cwd!(), "apps/api")
|
||||
]
|
||||
|
||||
# Environment-specific Sentry overrides
|
||||
if api_external_url = compile_config!(:api_external_url) do
|
||||
api_external_url_host = URI.parse(api_external_url).host
|
||||
|
||||
# Set environment_name based on which API URL we're using
|
||||
sentry_environment_name =
|
||||
case api_external_url_host do
|
||||
"api.firezone.dev" -> :production
|
||||
"api.firez.one" -> :staging
|
||||
_ -> :unknown
|
||||
end
|
||||
|
||||
config :sentry, :environment_name, sentry_environment_name
|
||||
|
||||
# Disable Sentry for unknown environments
|
||||
# Comment this out to enable Sentry in development and test environments
|
||||
if sentry_environment_name == :unknown do
|
||||
config :sentry, :dsn, nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user