Skip to content

Conversation

@solnic
Copy link
Collaborator

@solnic solnic commented Jan 6, 2026

I'll update changelog for the entire feature when preparing changelog for 12.0.0.

#skip-changelog

Closes #909

@solnic solnic force-pushed the 906-sentry-logger-handler-for-structured-logging branch from bcb816d to 094f947 Compare January 6, 2026 12:31
@solnic solnic force-pushed the 909-support-for-filtering-logs-via-before_send_log branch 3 times, most recently from ee5ba83 to 741163f Compare January 6, 2026 12:39
@solnic solnic force-pushed the 906-sentry-logger-handler-for-structured-logging branch from 094f947 to 9e1f449 Compare January 7, 2026 07:49
@solnic solnic force-pushed the 909-support-for-filtering-logs-via-before_send_log branch from 741163f to 4ffe87b Compare January 7, 2026 07:50
@solnic solnic force-pushed the 906-sentry-logger-handler-for-structured-logging branch from 9e1f449 to 3258a25 Compare January 7, 2026 10:17
@solnic solnic force-pushed the 909-support-for-filtering-logs-via-before_send_log branch from 4ffe87b to 542b9dc Compare January 7, 2026 10:18
@solnic solnic force-pushed the 906-sentry-logger-handler-for-structured-logging branch 2 times, most recently from 7c929ff to 515fa87 Compare January 8, 2026 09:27
@solnic solnic force-pushed the 909-support-for-filtering-logs-via-before_send_log branch from 542b9dc to 245b462 Compare January 16, 2026 12:58
Base automatically changed from 906-sentry-logger-handler-for-structured-logging to master January 23, 2026 11:10
@solnic solnic force-pushed the 909-support-for-filtering-logs-via-before_send_log branch from 245b462 to 8ff9aa2 Compare January 23, 2026 11:12
@solnic solnic marked this pull request as ready for review January 23, 2026 11:16
@solnic solnic linked an issue Jan 23, 2026 that may be closed by this pull request
Comment on lines +183 to +189
defp call_before_send_log(log_event, function) when is_function(function, 1) do
function.(log_event)
end

defp call_before_send_log(log_event, {mod, fun}) do
apply(mod, fun, [log_event])
end
Copy link

Choose a reason for hiding this comment

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

Bug: An unhandled exception in a before_send_log callback will crash the background task, causing the entire batch of logs to be silently lost.
Severity: HIGH

Suggested Fix

Wrap the execution of the user-provided callback within a try/rescue block inside the call_before_send_log function. If an exception is caught, it should be logged appropriately without crashing the task, allowing the remaining logs in the batch to be processed and sent.

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: lib/sentry/client.ex#L183-L189

Potential issue: The `before_send_log` callback is executed within a background task
spawned by `Task.Supervisor.start_child()`. The function `call_before_send_log` does not
include any exception handling, such as a `try/rescue` block. If a user-provided
callback raises an exception, it will cause this background task to crash. Because the
task crashes before the logs are sent via an HTTP request, the entire batch of logs
being processed will be silently lost. The application will not be notified of the
failure, and the error will only be visible in Elixir's task error logs, making it a
difficult issue to debug in production.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for filtering logs via before_send_log

2 participants