Skip to content

Commit 42948de

Browse files
authored
Merge branch 'master' into sav/Switch-hackney-to-finch
2 parents 4d42eeb + 4827110 commit 42948de

File tree

130 files changed

+6140
-747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+6140
-747
lines changed

.dialyzer_ignore.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[
2-
{"test/support/example_plug_application.ex"}
2+
{"test/support/example_plug_application.ex"},
3+
{"test/support/test_helpers.ex"}
34
]

.github/workflows/main.yml

+53-28
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,29 @@ env:
1414
jobs:
1515
test:
1616
name: Test (Elixir ${{ matrix.elixir }}, OTP ${{ matrix.otp }})
17-
runs-on: ubuntu-20.04
17+
runs-on: ${{ matrix.os }}
18+
timeout-minutes: 10
1819
strategy:
1920
fail-fast: false
2021
matrix:
2122
# https://hexdocs.pm/elixir/compatibility-and-deprecations.html#compatibility-between-elixir-and-erlang-otp
2223
include:
2324
# Newest supported Elixir/Erlang pair.
24-
- elixir: '1.17'
25-
otp: '27.0'
25+
- elixir: '1.18'
26+
otp: '27.2'
2627
lint: true
2728
dialyzer: true
29+
os: ubuntu-latest
2830

2931
# One version before the last supported one.
30-
- elixir: '1.16'
32+
- elixir: '1.17'
3133
otp: '26.2'
34+
os: ubuntu-22.04
3235

3336
# Oldest supported Elixir/Erlang pair.
3437
- elixir: '1.13.4-otp-22'
3538
otp: '22.3.4'
39+
os: ubuntu-20.04
3640

3741
steps:
3842
- name: Check out this repository
@@ -44,53 +48,74 @@ jobs:
4448
elixir-version: ${{ matrix.elixir }}
4549
otp-version: ${{ matrix.otp }}
4650

47-
# We need to manually restore and then save, so that we can save the "_build" directory
48-
# *without* the Elixir compiled code in it.
49-
- name: Restore Mix dependencies cache
50-
uses: actions/cache/restore@v4
51-
id: mix-deps-cache
51+
- name: Cache downloaded dependencies
52+
uses: actions/cache@v4
53+
id: mix-downloaded-deps-cache
5254
with:
5355
path: |
54-
_build
5556
deps
57+
test_integrations/phoenix_app/deps
5658
key: |
57-
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
58-
restore-keys: |
59-
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-
59+
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-deps-${{ hashFiles('**/mix.lock') }}
6060
61-
- name: Install and compile Mix dependencies
62-
if: steps.mix-deps-cache.outputs.cache-hit != 'true'
63-
run: mix do deps.get --check-locked, deps.compile
61+
- name: Download Mix dependencies
62+
if: steps.mix-downloaded-deps-cache.outputs.cache-hit != 'true'
63+
run: |
64+
if [ ${{ matrix.elixir }} != '1.13.4-otp-22' ]; then
65+
mix deps.get --check-locked
66+
else
67+
mix deps.get
68+
fi
69+
70+
if [ ${{ matrix.elixir }} != '1.13.4-otp-22' ]; then
71+
cd test_integrations/phoenix_app
72+
73+
if [ ${{ matrix.lint }} == 'true' ]; then
74+
mix deps.get --check-locked
75+
else
76+
mix deps.get
77+
fi
78+
fi
6479
65-
- name: Save Mix dependencies cache
66-
uses: actions/cache/save@v4
67-
if: steps.mix-deps-cache.outputs.cache-hit != 'true'
80+
# We need to manually restore and then save, so that we can save the "_build" directory
81+
# *without* the Elixir compiled code in it.
82+
- name: Cache compiled Elixir code
83+
uses: actions/cache@v4
84+
id: mix-cache
6885
with:
6986
path: |
7087
_build
71-
deps
88+
test_integrations/phoenix_app/_build
7289
key: |
73-
${{ steps.mix-deps-cache.outputs.cache-primary-key }}
90+
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles('**/mix.lock') }}
91+
restore-keys: |
92+
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-
7493
75-
- name: Check formatting
94+
- name: Compile Elixir code (with --warnings-as-errors)
7695
if: matrix.lint
77-
run: mix format --check-formatted
96+
run: |
97+
mix compile --warnings-as-errors
98+
cd test_integrations/phoenix_app
99+
mix compile --warnings-as-errors
78100
79-
- name: Check compiler warnings
101+
- name: Check formatting
80102
if: matrix.lint
81-
run: mix compile --warnings-as-errors
103+
run: mix format --check-formatted
82104

83105
- name: Run tests
84106
run: mix test
85107

86-
- name: Retrieve PLT Cache
108+
- name: Run integration tests
109+
run: mix test.integrations
110+
111+
- name: Cache Dialyzer PLT
87112
uses: actions/cache@v4
88113
if: matrix.dialyzer
89114
id: plt-cache
90115
with:
91116
path: plts
92117
key: |
93-
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
118+
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('**/mix.lock')) }}
94119
restore-keys: |
95120
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-
96121
@@ -102,4 +127,4 @@ jobs:
102127
103128
- name: Run dialyzer
104129
if: matrix.dialyzer
105-
run: mix dialyzer --no-check --halt-exit-status
130+
run: mix dialyzer --no-check

.github/workflows/release.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ jobs:
1515
runs-on: ubuntu-latest
1616
name: "Release a new version"
1717
steps:
18+
- name: Get auth token
19+
id: token
20+
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
21+
with:
22+
app-id: ${{ vars.SENTRY_RELEASE_BOT_CLIENT_ID }}
23+
private-key: ${{ secrets.SENTRY_RELEASE_BOT_PRIVATE_KEY }}
1824
- uses: actions/checkout@v3
1925
with:
20-
token: ${{ secrets.GH_RELEASE_PAT }}
26+
token: ${{ steps.token.outputs.token }}
2127
fetch-depth: 0
2228
- name: Prepare release
2329
uses: getsentry/action-prepare-release@v1
2430
env:
25-
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_PAT }}
31+
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
2632
with:
2733
version: ${{ github.event.inputs.version }}
2834
force: ${{ github.event.inputs.force }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ erl_crash.dump
1212

1313
# Generated by "mix sentry.package_source_code"
1414
/priv/sentry.map
15+
16+
test_integrations/phoenix_app/db

CHANGELOG.md

+61
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
# Changelog
22

3+
## 10.8.1
4+
5+
### Various fixes & improvements
6+
7+
- Update to LiveView 1.0 🎉 (#826) by @solnic
8+
- Replace release bot with GH app (#828) by @Jeffreyhung
9+
10+
## 10.8.0
11+
12+
This release bumps the minimum Elixir requirement to 1.13, fixes a few bugs, and introduces **client reports**. Client reports will be sent to Sentry by default, but you can disable them with:
13+
14+
```elixir
15+
config :sentry,
16+
# ...,
17+
send_client_reports: false
18+
```
19+
20+
### Improvements and new features
21+
22+
- Add support for [client reports](https://develop.sentry.dev/sdk/telemetry/client-reports/) (#801) by @savhappy
23+
- Add option for generating custom cron monitor slugs (#803) by @iautom8things
24+
- Improvements to documentation
25+
- Require Elixir 1.13+ (21f0f77e) by @whatyouhide
26+
- Validate that custom HTTP clients return correct stuff (#794) by @savhappy
27+
28+
### Bug fixes
29+
30+
- Fix stacktraces with no frames (#787) by @savhappy
31+
- Special-case Ranch errors in the logger handler for OTP 25 (#818) by @whatyouhide
32+
- Few fixes to `mix sentry.send_test_event`
33+
- Handle Bandit exception when fetching peer data (#814) by @ardhitama
34+
- Support non-exception error values from Oban jobs (#807) by @savhappy
35+
36+
## 10.7.1
37+
38+
### Various fixes & improvements
39+
40+
- Add `:monitor_config_defaults` integrations option (#782). — *@whatyouhide*
41+
- Allow `--no-compile`/`--no-check-deps` flags for `mix sentry.package_source_code` (#776). — *@razielgn*
42+
- Accept structs as structured logs in `Sentry.LoggerHandler` (#780). — *@mrdotb*
43+
- Fix a bug where we were accidentally sending the `:integration_meta` field (116140d6). — *@whatyouhide*
44+
- Reduce memory usage of source code maps (#777). — *@whatyouhide*
45+
46+
## 10.7.0
47+
48+
### Various fixes & improvements
49+
50+
New features:
51+
52+
- Add `Sentry.ClientError` for more structured client errors. You can use this to programmatically deal with errors when reporting events, if you need to. — *@savhappy*
53+
- Add `:integration_meta` key to `Sentry.Event`. — *(#771) by @savhappy*
54+
- Validate Sentry options even if DSN is not set. — *(#772) by @savhappy*
55+
56+
Bug fixes:
57+
58+
- Fix Sentry check-ins by internally mapping check-in IDs for "start" and "stop" events. — *@savhappy*
59+
- Fix `mix sentry.package_source_code` edge cases by compiling code before running the task. — *@whatyouhide*
60+
- Support structured logs in `Sentry.LoggerHandler`. — *(#765) by @martosaur*
61+
- Handle `nil` environment correctly in Sentry config — *(#753) by @fahchen*
62+
- Fix exceptions with an empty stacktrace. — *(#755) by @savhappy*
63+
364
## 10.6.2
465

566
### Various fixes & improvements

README.md

+68-13
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,35 @@ This is the official Sentry SDK for [Sentry].
1818

1919
### Install
2020

21-
To use Sentry in your project, add it as a dependency in your `mix.exs` file. Sentry does not install a JSON library nor HTTP client by itself. Sentry will default to trying to use [Jason] for JSON serialization and [Finch] for HTTP requests, but can be configured to use other ones. To use the default ones, do:
21+
To use Sentry in your project, add it as a dependency in your `mix.exs` file.
22+
23+
Sentry does not install a JSON library nor an HTTP client by itself. Sentry will default to the [built-in `JSON`](https://hexdocs.pm/elixir/JSON.html) for JSON and [Finch] for HTTP requests, but can be configured to use other ones. To use the default ones, do:
24+
2225

2326
```elixir
2427
defp deps do
2528
[
2629
# ...
27-
28-
{:sentry, "~> 10.0"},
30+
{:sentry, "~> 10.8"},
2931
{:jason, "~> 1.4"},
3032
{:finch, "~> 0.18"}
3133
]
3234
end
3335
```
3436

37+
> [!WARNING]
38+
> If you're using an Elixir version before 1.18, the Sentry SDK will default to [Jason] as the JSON library. However, you **must** add it to your dependencies:
39+
>
40+
> ```elixir
41+
> defp deps do
42+
> [
43+
> # ...
44+
> {:sentry, "~> 10.8.1"},
45+
> {:jason, "~> 1.4"}
46+
> ]
47+
> end
48+
> ```
49+
3550
### Configuration
3651
3752
Sentry has a range of configuration options, but most applications will have a configuration that looks like the following:
@@ -40,24 +55,65 @@ Sentry has a range of configuration options, but most applications will have a c
4055
# config/config.exs
4156
config :sentry,
4257
dsn: "https://[email protected]/1",
43-
environment_name: Mix.env(),
58+
environment_name: config_env(),
4459
enable_source_code_context: true,
4560
root_source_code_paths: [File.cwd!()]
4661
```
4762
4863
### Usage
4964

50-
This library comes with a [`:logger` handler][logger-handlers] to capture error messages coming from process crashes. To enable this, add the handler when your application starts:
65+
This library comes with a [`:logger` handler][logger-handlers] to capture error messages coming from process crashes. To enable this, add [`Sentry.LoggerHandler`](https://hexdocs.pm/sentry/Sentry.LoggerHandler.html) to your production configuration:
5166

52-
```diff
53-
def start(_type, _args) do
54-
+ :logger.add_handler(:sentry_handler, Sentry.LoggerHandler, %{})
67+
```elixir
68+
# config/prod.exs
69+
config :my_app, :logger, [
70+
{:handler, :my_sentry_handler, Sentry.LoggerHandler, %{
71+
config: %{
72+
metadata: [:file, :line],
73+
rate_limiting: [max_events: 10, interval: _1_second = 1_000],
74+
# Logs all messages with level `:error` and above to Sentry.
75+
# Remove :capture_log_messages and :level if you only want to report crashes.
76+
capture_log_messages: true,
77+
level: :error
78+
}
79+
}}
80+
]
5581

56-
# ...
57-
end
5882
```
5983

60-
The handler can also be configured to capture `Logger` metadata. See the documentation [here](https://hexdocs.pm/sentry/Sentry.LoggerBackend.html).
84+
And then add your logger when your application starts:
85+
86+
```elixir
87+
# lib/my_app/application.ex
88+
def start(_type, _args) do
89+
Logger.add_handlers(:my_app)
90+
91+
# ...
92+
end
93+
```
94+
95+
Alternatively, you can skip the `:logger` configuration and add the handler directly
96+
to your application's `start/2` callback:
97+
98+
```elixir
99+
# lib/my_app/application.ex
100+
def start(_type, _args) do
101+
:logger.add_handler(:my_sentry_handler, Sentry.LoggerHandler, %{
102+
config: %{
103+
metadata: [:file, :line],
104+
rate_limiting: [max_events: 10, interval: _1_second = 1_000],
105+
capture_log_messages: true,
106+
level: :error
107+
}
108+
})
109+
110+
# ...
111+
end
112+
```
113+
114+
See all logger configuration options [here](https://hexdocs.pm/sentry/Sentry.LoggerHandler.html).
115+
116+
#### Capture exceptions manually
61117

62118
Sometimes you want to capture specific exceptions manually. To do so, use [`Sentry.capture_exception/2`](https://hexdocs.pm/sentry/Sentry.html#capture_exception/2).
63119

@@ -130,10 +186,9 @@ Thanks to everyone who has contributed to this project so far.
130186
<img src="https://contributors-img.web.app/image?repo=getsentry/sentry-elixir" />
131187
</a>
132188

133-
134189
## Getting Help/Support
135190

136-
If you need help setting up or configuring the Python SDK (or anything else in the Sentry universe) please head over to the [Sentry Community on Discord](https://discord.com/invite/Ww9hbqr). There is a ton of great people in our Discord community ready to help you!
191+
If you need help setting up or configuring the Elixir SDK (or anything else in the Sentry universe) please head over to the [Sentry Community on Discord](https://discord.com/invite/Ww9hbqr). There is a ton of great people in our Discord community ready to help you!
137192

138193
## Resources
139194

config/config.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ if config_env() == :test do
1515
config :logger, backends: []
1616
end
1717

18-
config :phoenix, :json_library, Jason
18+
config :phoenix, :json_library, if(Code.ensure_loaded?(JSON), do: JSON, else: Jason)

0 commit comments

Comments
 (0)