Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ if config_env() == :test do
test_mode: true,
traces_sample_rate: 1.0

config :logger, backends: []
if System.version() > "1.16.0" do
config :logger, :default_handler, false

config :sentry, :logger, [
{:handler, :file_log, :logger_std_h,
%{
config: %{file: ~c"log/tests.log"},
formatter: Logger.Formatter.new()
}}
]
else
config :logger, backends: []
end

config :opentelemetry, span_processor: {Sentry.OpenTelemetry.SpanProcessor, []}

Expand Down
9 changes: 5 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule Sentry.Mixfile do
deps: deps(),
elixirc_paths: elixirc_paths(Mix.env()),
test_paths: test_paths(System.get_env("SENTRY_INTEGRATION")),
test_ignore_filters: [~r|/fixtures/|],
dialyzer: [
flags: [:unmatched_returns, :error_handling, :extra_return],
plt_file: {:no_warn, "plts/dialyzer.plt"},
Expand All @@ -22,10 +23,6 @@ defmodule Sentry.Mixfile do
plt_add_apps: [:mix, :ex_unit]
],
test_coverage: [tool: ExCoveralls],
preferred_cli_env: [
"coveralls.html": :test,
"test.integrations": :test
],
name: "Sentry",
docs: [
extra_section: "Guides",
Expand Down Expand Up @@ -84,6 +81,10 @@ defmodule Sentry.Mixfile do
]
end

def cli do
[preferred_envs: ["coveralls.html": :test, "test.integrations": :test]]
end

defp extra_applications(:test), do: [:logger, :opentelemetry]
defp extra_applications(_other), do: [:logger]

Expand Down
4 changes: 2 additions & 2 deletions test/sentry/client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ defmodule Sentry.ClientTest do
end)

put_test_config(
before_send: fn event ->
before_send: fn %Event{} = event ->
metadata = Map.new(Logger.metadata())
{user_id, rest_metadata} = Map.pop(metadata, :user_id)

%Event{
%{
event
| extra: Map.merge(event.extra, rest_metadata),
user: Map.put(event.user, :id, user_id)
Comment on lines +235 to 238
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The before_send callback returns a plain map instead of an Event struct, preventing Sentry events from being sent.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The before_send callback in test/sentry/client_test.exs (lines 235-238) returns a plain map %{...} instead of an %Event{} struct. This causes the with block in Client.send_event/2 to fail its pattern match {:ok, %Event{} = event}, preventing the event from being sent to the Sentry server. Consequently, the Bypass.expect in the test fails due to no HTTP request being made.

💡 Suggested Fix

Modify the before_send callback to ensure it returns an %Event{} struct, not a plain map. Update the existing event struct and return it directly.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: test/sentry/client_test.exs#L235-L238

Potential issue: The `before_send` callback in `test/sentry/client_test.exs` (lines
235-238) returns a plain map `%{...}` instead of an `%Event{}` struct. This causes the
`with` block in `Client.send_event/2` to fail its pattern match `{:ok, %Event{} =
event}`, preventing the event from being sent to the Sentry server. Consequently, the
`Bypass.expect` in the test fails due to no HTTP request being made.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 4581160

Expand Down