Skip to content

Commit

Permalink
Honor Retry-After responses from Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Apr 21, 2024
1 parent 19e2477 commit 5bad4b5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/sentry/transport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ defmodule Sentry.Transport do
{:ok, id} ->
{:ok, id}

# If Sentry gives us a Retry-After header, we listen to that instead of our
# own retry.
{:retry_after, delay_ms} when retries_left != [] ->
Process.sleep(delay_ms)
post_envelope_with_retries(client, endpoint, headers, payload, tl(retries_left))

{:error, _reason} when retries_left != [] ->
[sleep_interval | retries_left] = retries_left
Process.sleep(sleep_interval)
Expand All @@ -57,6 +63,15 @@ defmodule Sentry.Transport do

{:error, "Received #{status} from Sentry server: #{error_header}"}

{:ok, 429, headers, _body} ->
with timeout when is_binary(timeout) <- :proplists.get_value("Retry-After", headers, nil),

Check failure on line 67 in lib/sentry/transport.ex

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.13.4-otp-22, OTP 22.3.4)

** (CompileError) lib/sentry/transport.ex:67: expected -> clauses for :else in "with"
{delay_ms, ""} <- Integer.parse(timeout) do
{:retry_after, delay_ms * 1000}
else
# https://develop.sentry.dev/sdk/rate-limiting/#stage-1-parse-response-headers
{:retry_after, 60_000}
end

{:error, reason} ->
{:error, reason}
end
Expand Down

0 comments on commit 5bad4b5

Please sign in to comment.