Skip to content

Commit 0cf619d

Browse files
feat: add support for elixir 1.15
Elixir 1.15 hard-depcreates Logger.warn. Custom logger backends that still use the legacy custom backend API must translate the log level to avoid emitting a deprecation warning. Co-authored-by: José Valim <[email protected]>
1 parent b915794 commit 0cf619d

File tree

7 files changed

+42
-18
lines changed

7 files changed

+42
-18
lines changed

.github/workflows/main.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,25 @@ jobs:
1616
strategy:
1717
matrix:
1818
# https://hexdocs.pm/elixir/1.14/compatibility-and-deprecations.html#compatibility-between-elixir-and-erlang-otp
19-
elixir: ['1.12.x', '1.13.x', '1.14.x']
20-
otp: ['22.3.x', '23.3.x', '24.3.x', '25.2.x']
19+
elixir: ['1.12.x', '1.13.x', '1.14.x', '1.15.x']
20+
otp: ['22.3.x', '23.3.x', '24.3.x', '25.2.x', '26.0.x']
2121
exclude:
2222
- elixir: '1.12.x'
2323
otp: '25.2.x'
24+
- elixir: '1.12.x'
25+
otp: '26.0.x'
26+
- elixir: '1.13.x'
27+
otp: '25.2.x'
28+
- elixir: '1.13.x'
29+
otp: '26.0.x'
2430
- elixir: '1.14.x'
2531
otp: '22.3.x'
32+
- elixir: '1.14.x'
33+
otp: '26.0.x'
34+
- elixir: '1.15.x'
35+
otp: '22.3.x'
36+
- elixir: '1.15.x'
37+
otp: '23.3.x'
2638
include:
2739
- elixir: '1.10.x'
2840
otp: '22.3.x'
@@ -55,7 +67,7 @@ jobs:
5567
mix deps.get
5668
- name: Check Formatting
5769
run: mix format --check-formatted
58-
if: matrix.elixir == '1.14.x'
70+
if: matrix.elixir == '1.15.x'
5971

6072
- name: Check Compile Warnings
6173
run: mix compile --warnings-as-errors
@@ -66,16 +78,16 @@ jobs:
6678
- name: Retrieve PLT Cache
6779
uses: actions/cache@v1
6880
id: plt-cache
69-
if: matrix.elixir == '1.14.x'
81+
if: matrix.elixir == '1.15.x'
7082
with:
7183
path: priv/plts
7284
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
7385

7486
- name: Create PLTs
75-
if: steps.plt-cache.outputs.cache-hit != 'true' && matrix.elixir == '1.14.x'
87+
if: steps.plt-cache.outputs.cache-hit != 'true' && matrix.elixir == '1.15.x'
7688
run: |
7789
mkdir -p priv/plts
7890
mix dialyzer --plt
7991
- name: Run dialyzer
8092
run: mix dialyzer --no-check --halt-exit-status
81-
if: matrix.elixir == '1.14.x'
93+
if: matrix.elixir == '1.15.x'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ The full range of options is the following:
175175
| `source_code_path_pattern` | False | `"**/*.ex"` | |
176176
| `filter` | False | | Module where the filter rules are defined (see [Filtering Exceptions](https://hexdocs.pm/sentry/Sentry.html#module-filtering-exceptions)) |
177177
| `json_library` | False | `Jason` | |
178-
| `log_level` | False | `:warn` | This sets the log level used when Sentry fails to send an event due to an invalid event or API error |
178+
| `log_level` | False | `:warning` | This sets the log level used when Sentry fails to send an event due to an invalid event or API error |
179179
| `max_breadcrumbs` | False | 100 | This sets the maximum number of breadcrumbs to send to Sentry when creating an event |
180180

181181
Sentry uses the [hackney HTTP client](https://github.com/benoitc/hackney) for HTTP requests. Sentry starts its own hackney pool named `:sentry_pool` with a default connection pool of 50, and a connection timeout of 5000 milliseconds. The pool can be configured with the `hackney_pool_max_connections` and `hackney_pool_timeout` configuration keys. If you need to set other [hackney configurations](https://github.com/benoitc/hackney/blob/master/doc/hackney.md#request5) for things like a proxy, using your own pool or response timeouts, the `hackney_opts` configuration is passed directly to hackney for each request.

lib/sentry/config.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ defmodule Sentry.Config do
1818

1919
@permitted_log_level_values ~w(debug info warning warn error)a
2020

21+
@warning_log_level if Version.compare(System.version(), "1.11.0") != :lt, do: :warning, else: :warn
22+
2123
def validate_config! do
2224
end
2325

@@ -198,8 +200,9 @@ defmodule Sentry.Config do
198200
get_config(:json_library, default: Jason, check_dsn: false)
199201
end
200202

203+
201204
def log_level do
202-
get_config(:log_level, default: :warn, check_dsn: false)
205+
get_config(:log_level, default: @warning_log_level, check_dsn: false)
203206
end
204207

205208
def max_breadcrumbs do

lib/sentry/logger_backend.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ defmodule Sentry.LoggerBackend do
3434
Example:
3535
3636
config :logger, Sentry.LoggerBackend,
37-
# Also send warn messages
38-
level: :warn,
37+
# Also send warning messages
38+
level: :warning,
3939
# Send messages from Plug/Cowboy
4040
excluded_domains: [],
4141
# Include metadata added with `Logger.metadata([foo_bar: "value"])`
@@ -70,6 +70,8 @@ defmodule Sentry.LoggerBackend do
7070
end
7171

7272
def handle_event({level, _gl, {Logger, msg, _ts, meta}}, state) do
73+
level = maybe_ensure_warning_level(level)
74+
7375
if Logger.compare_levels(level, state.level) != :lt and
7476
not excluded_domain?(meta[:domain], state) do
7577
log(level, msg, meta, state)
@@ -189,4 +191,10 @@ defmodule Sentry.LoggerBackend do
189191
"debug"
190192
end
191193
end
194+
195+
if Version.compare(System.version(), "1.11.0") != :lt do
196+
defp maybe_ensure_warning_level(:warn), do: :warning
197+
end
198+
199+
defp maybe_ensure_warning_level(level), do: level
192200
end

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"plug_cowboy": {:hex, :plug_cowboy, "2.4.1", "779ba386c0915027f22e14a48919a9545714f849505fa15af2631a0d298abf0f", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d72113b6dff7b37a7d9b2a5b68892808e3a9a752f2bf7e503240945385b70507"},
2727
"plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
2828
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
29-
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
29+
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
3030
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5", "2e73e068cd6393526f9fa6d399353d7c9477d6886ba005f323b592d389fb47be", [:make], []},
3131
"telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},
3232
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},

test/event_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ defmodule Sentry.EventTest do
5252
%{
5353
context_line: nil,
5454
filename: "timer.erl",
55-
function: ":timer.tc/1",
55+
function: ":timer.tc" <> _arity,
5656
in_app: false,
5757
lineno: _,
5858
module: :timer,

test/logger_backend_test.exs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ defmodule Sentry.LoggerBackendTest do
66

77
alias Sentry.Envelope
88

9+
@warning_log_level if Version.compare(System.version(), "1.11.0") != :lt, do: :warning, else: :warn
10+
911
setup do
1012
{:ok, _} = Logger.add_backend(Sentry.LoggerBackend)
1113

@@ -399,8 +401,8 @@ defmodule Sentry.LoggerBackendTest do
399401
Logger.configure_backend(Sentry.LoggerBackend, capture_log_messages: false)
400402
end
401403

402-
test "sends warning messages when configured to :warn" do
403-
Logger.configure_backend(Sentry.LoggerBackend, level: :warn, capture_log_messages: true)
404+
test "sends warning messages when configured to #{@warning_log_level}" do
405+
Logger.configure_backend(Sentry.LoggerBackend, level: @warning_log_level, capture_log_messages: true)
404406
bypass = Bypass.open()
405407
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
406408
pid = self()
@@ -421,7 +423,7 @@ defmodule Sentry.LoggerBackendTest do
421423

422424
capture_log(fn ->
423425
Sentry.Context.set_user_context(%{user_id: 3})
424-
Logger.warn("testing")
426+
Logger.log(@warning_log_level, "testing")
425427
assert_receive("API called")
426428
end)
427429
after
@@ -546,7 +548,7 @@ defmodule Sentry.LoggerBackendTest do
546548
end
547549

548550
test "sets event level to Logger message level" do
549-
Logger.configure_backend(Sentry.LoggerBackend, level: :warn, capture_log_messages: true)
551+
Logger.configure_backend(Sentry.LoggerBackend, level: @warning_log_level, capture_log_messages: true)
550552
bypass = Bypass.open()
551553
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
552554
pid = self()
@@ -566,8 +568,7 @@ defmodule Sentry.LoggerBackendTest do
566568
end)
567569

568570
capture_log(fn ->
569-
Logger.warn("warn")
570-
571+
Logger.log(@warning_log_level, "warn")
571572
assert_receive("API called")
572573
end)
573574
after

0 commit comments

Comments
 (0)