Skip to content

Commit 7f539ac

Browse files
Merge pull request #249 from getsentry/add-update-typespecs
Add/update typespecs
2 parents aa00bad + 7cc579b commit 7f539ac

File tree

7 files changed

+26
-17
lines changed

7 files changed

+26
-17
lines changed

lib/sentry.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ defmodule Sentry do
9191
See `Sentry.Logger`
9292
"""
9393

94-
@type task :: {:ok, Task.t()} | :error | :excluded | :ignored
94+
@type send_result :: Sentry.Client.send_result() | :excluded | :ignored
9595

9696
def start(_type, _opts) do
9797
children = [
@@ -112,7 +112,7 @@ defmodule Sentry do
112112
Parses and submits an exception to Sentry if current environment is in included_environments.
113113
`opts` argument is passed as the second argument to `Sentry.send_event/2`.
114114
"""
115-
@spec capture_exception(Exception.t(), Keyword.t()) :: task
115+
@spec capture_exception(Exception.t(), Keyword.t()) :: send_result
116116
def capture_exception(exception, opts \\ []) do
117117
filter_module = Config.filter()
118118
{source, opts} = Keyword.pop(opts, :event_source)
@@ -131,7 +131,7 @@ defmodule Sentry do
131131
132132
`opts` argument is passed as the second argument to `Sentry.send_event/2`.
133133
"""
134-
@spec capture_message(String.t(), Keyword.t()) :: task
134+
@spec capture_message(String.t(), Keyword.t()) :: send_result
135135
def capture_message(message, opts \\ []) do
136136
opts
137137
|> Keyword.put(:message, message)
@@ -144,7 +144,7 @@ defmodule Sentry do
144144
145145
`opts` argument is passed as the second argument to `send_event/2` of the configured `Sentry.HTTPClient`. See `Sentry.Client.send_event/2` for more information.
146146
"""
147-
@spec send_event(Event.t(), Keyword.t()) :: task
147+
@spec send_event(Event.t(), Keyword.t()) :: send_result
148148
def send_event(event, opts \\ [])
149149

150150
def send_event(%Event{message: nil, exception: nil}, _opts) do

lib/sentry/client.ex

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ defmodule Sentry.Client do
3838

3939
require Logger
4040

41-
@type get_dsn :: {String.t(), String.t(), Integer.t()}
41+
@type dsn :: {String.t(), String.t(), String.t()}
42+
@type send_event_result :: {:ok, Task.t() | String.t() | pid()} | :error | :unsampled
4243
@sentry_version 5
4344
@max_attempts 4
4445
@hackney_pool_name :sentry_pool
@@ -56,7 +57,7 @@ defmodule Sentry.Client do
5657
* `:result` - Allows specifying how the result should be returned. Options include `:sync`, `:none`, and `:async`. `:sync` will make the API call synchronously, and return `{:ok, event_id}` if successful. `:none` sends the event from an unlinked child process under `Sentry.TaskSupervisor` and will return `{:ok, ""}` regardless of the result. `:async` will start an unlinked task and return a tuple of `{:ok, Task.t}` on success where the Task can be awaited upon to receive the result asynchronously. When used in an OTP behaviour like GenServer, the task will send a message that needs to be matched with `GenServer.handle_info/2`. See `Task.Supervisor.async_nolink/2` for more information. `:async` is the default.
5758
* `:sample_rate` - The sampling factor to apply to events. A value of 0.0 will deny sending any events, and a value of 1.0 will send 100% of events.
5859
"""
59-
@spec send_event(Event.t()) :: {:ok, Task.t() | String.t()} | :error | :unsampled
60+
@spec send_event(Event.t()) :: send_event_result
6061
def send_event(%Event{} = event, opts \\ []) do
6162
result = Keyword.get(opts, :result, :async)
6263
sample_rate = Keyword.get(opts, :sample_rate) || Config.sample_rate()
@@ -125,7 +126,7 @@ defmodule Sentry.Client do
125126
{:ok, id} ->
126127
{:ok, id}
127128

128-
_ ->
129+
:error ->
129130
sleep(current_attempt)
130131
try_request(method, url, headers, body, current_attempt + 1)
131132
end
@@ -136,6 +137,8 @@ defmodule Sentry.Client do
136137
137138
Hackney options can be set via the `hackney_opts` configuration option.
138139
"""
140+
@spec request(atom(), String.t(), list({String.t(), String.t()}), String.t()) ::
141+
{:ok, String.t()} | :error
139142
def request(method, url, headers, body) do
140143
hackney_opts =
141144
Config.hackney_opts()
@@ -191,7 +194,7 @@ defmodule Sentry.Client do
191194
@doc """
192195
Get a Sentry DSN which is simply a URI.
193196
"""
194-
@spec get_dsn! :: get_dsn
197+
@spec get_dsn! :: dsn
195198
def get_dsn! do
196199
# {PROTOCOL}://{PUBLIC_KEY}:{SECRET_KEY}@{HOST}/{PATH}{PROJECT_ID}
197200
%URI{userinfo: userinfo, host: host, port: port, path: path, scheme: protocol} =
@@ -205,6 +208,7 @@ defmodule Sentry.Client do
205208
{endpoint, public_key, secret_key}
206209
end
207210

211+
@spec maybe_call_after_send_event(send_event_result, Event.t()) :: Event.t()
208212
def maybe_call_after_send_event(result, event) do
209213
case Config.after_send_event() do
210214
function when is_function(function, 2) ->
@@ -224,6 +228,7 @@ defmodule Sentry.Client do
224228
result
225229
end
226230

231+
@spec maybe_call_before_send_event(Event.t()) :: Event.t()
227232
def maybe_call_before_send_event(event) do
228233
case Config.before_send_event() do
229234
function when is_function(function, 1) ->
@@ -253,6 +258,7 @@ defmodule Sentry.Client do
253258
exception. If the event does not have stacktrace frames, it should not
254259
be included in the JSON body.
255260
"""
261+
@spec render_event(Event.t()) :: map()
256262
def render_event(%Event{} = event) do
257263
map = %{
258264
event_id: event.event_id,

lib/sentry/event.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ defmodule Sentry.Event do
234234
key in the map would be the name of the variable, but we don't have that
235235
available.
236236
"""
237-
@spec args_from_stacktrace(Exception.stacktrace()) :: String.t() | nil
237+
@spec args_from_stacktrace(Exception.stacktrace()) :: map()
238238
def args_from_stacktrace([{_m, _f, a, _} | _]) when is_list(a) do
239239
Enum.with_index(a)
240240
|> Enum.map(fn {arg, index} ->

lib/sentry/util.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Sentry.Util do
66
@doc """
77
Generates a unix timestamp
88
"""
9-
@spec unix_timestamp :: Integer.t()
9+
@spec unix_timestamp :: pos_integer()
1010
def unix_timestamp do
1111
:os.system_time(:seconds)
1212
end
@@ -22,6 +22,7 @@ defmodule Sentry.Util do
2222
|> String.trim_trailing("Z")
2323
end
2424

25+
@spec mix_deps_to_map([Mix.Dep.t()]) :: map()
2526
def mix_deps_to_map([%Mix.Dep{} | _rest] = modules) do
2627
Enum.reduce(modules, %{}, fn x, acc ->
2728
case x.status do

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defmodule Sentry.Mixfile do
2828
{:uuid, "~> 1.0"},
2929
{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0"},
3030
{:plug, "~> 1.0", optional: true},
31-
{:dialyxir, "> 0.0.0", only: :dev},
31+
{:dialyxir, "> 0.0.0", only: [:dev], runtime: false},
3232
{:ex_doc, "~> 0.18.0", only: :dev},
3333
{:credo, "~> 0.8", only: [:dev, :test], runtime: false},
3434
{:bypass, "~> 0.8.0", only: [:test]}

mix.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
22
"bypass": {:hex, :bypass, "0.8.1", "16d409e05530ece4a72fabcf021a3e5c7e15dcc77f911423196a0c551f2a15ca", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
3-
"certifi": {:hex, :certifi, "1.1.0", "c9b71a547016c2528a590ccfc28de786c7edb74aafa17446b84f54e04efc00ee", [:rebar3], [], "hexpm"},
3+
"certifi": {:hex, :certifi, "1.2.1", "c3904f192bd5284e5b13f20db3ceac9626e14eeacfbb492e19583cf0e37b22be", [:rebar3], [], "hexpm"},
44
"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
55
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
66
"credo": {:hex, :credo, "0.8.10", "261862bb7363247762e1063713bb85df2bbd84af8d8610d1272cd9c1943bba63", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"},
77
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"},
88
"earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [:mix], [], "hexpm"},
99
"ex_doc": {:hex, :ex_doc, "0.18.1", "37c69d2ef62f24928c1f4fdc7c724ea04aecfdf500c4329185f8e3649c915baf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
10-
"hackney": {:hex, :hackney, "1.8.0", "8388a22f4e7eb04d171f2cf0285b217410f266d6c13a4c397a6c22ab823a486c", [:rebar3], [{:certifi, "1.1.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
11-
"idna": {:hex, :idna, "4.0.0", "10aaa9f79d0b12cf0def53038547855b91144f1bfcc0ec73494f38bb7b9c4961", [:rebar3], [], "hexpm"},
10+
"hackney": {:hex, :hackney, "1.8.6", "21a725db3569b3fb11a6af17d5c5f654052ce9624219f1317e8639183de4a423", [:rebar3], [{:certifi, "1.2.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.0.2", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
11+
"idna": {:hex, :idna, "5.0.2", "ac203208ada855d95dc591a764b6e87259cb0e2a364218f215ad662daa8cd6b4", [:rebar3], [{:unicode_util_compat, "0.2.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
1212
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
1313
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], [], "hexpm"},
1414
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
@@ -17,4 +17,5 @@
1717
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"},
1818
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
1919
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5", "2e73e068cd6393526f9fa6d399353d7c9477d6886ba005f323b592d389fb47be", [:make], []},
20+
"unicode_util_compat": {:hex, :unicode_util_compat, "0.2.0", "dbbccf6781821b1c0701845eaf966c9b6d83d7c3bfc65ca2b78b88b8678bfa35", [:rebar3], [], "hexpm"},
2021
"uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"}}

test/event_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,19 +450,20 @@ defmodule Sentry.EventTest do
450450
assert event.modules == %{
451451
bunt: "0.2.0",
452452
bypass: "0.8.1",
453-
certifi: "1.1.0",
453+
certifi: "1.2.1",
454454
cowboy: "1.1.2",
455455
cowlib: "1.0.2",
456456
credo: "0.8.10",
457-
hackney: "1.8.0",
458-
idna: "4.0.0",
457+
hackney: "1.8.6",
458+
idna: "5.0.2",
459459
metrics: "1.0.1",
460460
mime: "1.1.0",
461461
mimerl: "1.0.2",
462462
plug: "1.4.3",
463463
poison: "3.1.0",
464464
ranch: "1.3.2",
465465
ssl_verify_fun: "1.1.1",
466+
unicode_util_compat: "0.2.0",
466467
uuid: "1.1.8"
467468
}
468469
end

0 commit comments

Comments
 (0)