-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore (sync service): setup sentry (#2099)
This PR configures Electric to track errors with sentry. To enable sentry for the single tenant Electric app you need to pass a `SENTRY_DSN` env var. I've tested this with the cloud deploy and errors are tracked successfully in sentry. TODO: - [ ] add stack_id and request_id meta data to the recorded error events (*) (*) The easy way is to configure sentry to add the `stack_id` and `request_id` meta data to the event context. That way it will show up in the error's details but it won't be searchable filterable on those fields! So a better way would be to add that meta data as tags. But not sure if that is configurable out of the box, might need to write a custom LoggerHandler. Adding the meta data as tags is possible by extending all `Logger.metadata` calls (from @icehaunter's recent PR) with a `sentry: [tags: %{stack_id: stack_id, shape_handle: shape_handle}]` key. Cf. https://github.com/getsentry/sentry-elixir/blob/master/lib/sentry/logger_handler.ex#L205 for more info. --------- Co-authored-by: Ilia Borovitinov <[email protected]>
- Loading branch information
1 parent
d59c6d7
commit 95b61e7
Showing
10 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@core/sync-service": patch | ||
--- | ||
|
||
Configure sentry for error tracking. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Config | ||
|
||
# Sentry's source-context-related options need to be set in compile-time config files | ||
# cf. https://hexdocs.pm/sentry/Mix.Tasks.Sentry.PackageSourceCode.html | ||
config :sentry, | ||
enable_source_code_context: true, | ||
root_source_code_paths: [File.cwd!()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule Electric.Telemetry.Sentry do | ||
def add_logger_handler do | ||
:logger.add_handler(:electric_sentry_handler, Sentry.LoggerHandler, %{ | ||
config: %{metadata: :all} | ||
}) | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
packages/sync-service/lib/electric/telemetry/sentry_req_http_client.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Electric.Telemetry.SentryReqHTTPClient do | ||
@moduledoc """ | ||
A custom Sentry HTTP client implementation using Req. | ||
""" | ||
@behaviour Sentry.HTTPClient | ||
|
||
@impl true | ||
def post(url, headers, body) do | ||
case Req.post(url, headers: headers, body: body, decode_body: false) do | ||
{:ok, %Req.Response{status: status, headers: headers, body: body}} -> | ||
{:ok, status, headers |> Enum.into([], fn {k, [v]} -> {k, v} end), body} | ||
|
||
{:error, error} -> | ||
{:error, error} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters