Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove stdlib2 #7

Open
wants to merge 104 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
794acac
Replace jiffy with jsx
bipthelin Jan 14, 2016
657248c
Update lager backend to work with newer lager
bipthelin Jan 14, 2016
d2fd413
Cleanup raven_lager_backend
bipthelin Jan 14, 2016
63bea5a
Report release to sentry
plux-kivra Apr 6, 2016
59183cf
Only include extra if metadata is available
plux-kivra Apr 6, 2016
e8bae60
Merge pull request #1 from kivra/hn-release
plux Apr 8, 2016
eed6d03
Fix lager backend init/1 signature
Jul 5, 2016
10d9b8e
Merge pull request #2 from zyegfryed/master
bipthelin Jul 25, 2016
d008660
Adds special handling of terminated cowboy_handlers (v1.x)
zigge-zagge Apr 10, 2017
a92a1df
Use kivra_io:format/2
zigge-zagge Apr 6, 2017
bc45d02
Adds special handling of 'Unhandled error:'
zigge-zagge Apr 6, 2017
f55848d
Fixes Http interface according to Sentry version 2
zigge-zagge Apr 7, 2017
78e50bd
Adds special handling of 'Error: {failed, Reason}...' and possibility…
zigge-zagge Apr 7, 2017
ea29fd4
Don't limit custom issues to error level
zigge-zagge Apr 7, 2017
31986a8
Adds special handling of failed operations like those in kivra_core_p…
zigge-zagge Apr 7, 2017
f047ae0
Adds kivra_lib to applications
zigge-zagge Apr 11, 2017
470f1a0
Adds special handling of mechanus_modron error logs
zigge-zagge Apr 11, 2017
dc2c941
Cleaner error messages for failed actions in mechanus_modron
zigge-zagge Apr 11, 2017
6ccc059
Special handling of krc warnings
zigge-zagge Jun 22, 2017
3dbdcb6
Properly send exceptions that are not two element tuples
zigge-zagge Jun 22, 2017
d85f143
Adds special handling of pacioli error logs
zigge-zagge Jul 10, 2017
3c620d4
json encode exception type (since we're not always exactly sending th…
zigge-zagge Jul 10, 2017
33a1866
Small improvement
zigge-zagge Jul 10, 2017
fa33633
Mask warnings for failed tasks in KKng
zigge-zagge Jul 11, 2017
bc4ef1d
crypto:rand_uniform is deprecated, use rand:uniform instead
plux-kivra Oct 3, 2017
7a32e1f
Merge remote-tracking branch 'origin/hn-erl-20' into kivra
plux-kivra Oct 5, 2017
1126daa
Adds special handling for 'unable to fetch payments from pacioli for …
zigge-zagge Nov 13, 2017
ad8b875
Adds special handling for KRC exits
zigge-zagge Nov 13, 2017
f7127e9
Adds special handling for 'unable to pay using pacioli for user'
zigge-zagge Nov 13, 2017
5989147
Moar special handling for pacioli errors
zigge-zagge Nov 13, 2017
d9b41cf
Adds special handling for 'Brod - Error in produce response'
zigge-zagge Nov 14, 2017
1493f81
Adds special handling for 'ULog error'
zigge-zagge Nov 14, 2017
7dd4175
Adds special handling for 'ULog error' in ulogc
zigge-zagge Nov 14, 2017
257c145
Bugfix
zigge-zagge Nov 28, 2017
ceebb52
Adds special handling for 'ULog error' in ulog_kafka_client
zigge-zagge Dec 14, 2017
9e0f854
Adds another handling for stacktraces in 'ULog error' in ulog_kafka_c…
zigge-zagge Dec 15, 2017
866b0e4
Adds special handling for terminating brod_client
zigge-zagge Dec 15, 2017
9dfaff7
Merge pull request #5 from kivra/jz-improved-ulog-kafka-client
JYZR Dec 20, 2017
cd4c0c6
Lower 'Error in produce response' to warning
zigge-zagge Dec 28, 2017
663612b
Adds helping description to 'Error in produce response'
zigge-zagge Dec 28, 2017
7e09e16
Adds 'Catched this: ~p' log
zigge-zagge May 3, 2018
2601fe5
Adds special handling for too_many_requests in rest_prelude
zigge-zagge Oct 23, 2018
034714e
Adds support for user interface
zigge-zagge Oct 26, 2018
845de03
Adds user data to too_many_requests event
zigge-zagge Oct 26, 2018
d566ee6
Merge pull request #6 from kivra/jz-users
JYZR Oct 29, 2018
997202c
Adds special handling for 'cybertron_email failed for 5 minutes'
zigge-zagge Nov 21, 2018
2a0422e
General handling of exceptions from macro in prelude.hrl (#7)
JYZR Nov 26, 2018
b46e740
More special handling for Pacioli exceptions
zigge-zagge Feb 13, 2019
0e4afad
Adds handling for OTP 20+ gen_server reports
zigge-zagge Feb 14, 2019
421459e
Merge remote-tracking branch 'origin/master' into kivra
zigge-zagge Feb 14, 2019
ddcdc49
Adds handling for gen_statem reports
zigge-zagge Feb 26, 2019
6b97b46
Adds special handling for terminating brod_consumer
zigge-zagge Apr 11, 2019
d8ba1b5
Unintentional match of Pids in 'Krc Exit' message :(
zigge-zagge Apr 11, 2019
067f20f
Adds special handling for failed asserts in Pacioli
zigge-zagge May 14, 2019
dd2ad2e
chore: 'kivra_io' has moved to 'stdlib2' and is now called 's2_io'
zigge-zagge May 23, 2019
24c4fd8
Group brod produce errors
plux-kivra Jun 18, 2019
637955f
Handle brod produce error (take 2)
plux-kivra Jun 19, 2019
6c480c3
Remove beehive special case
maxnordlund Sep 30, 2019
3cd0275
Merge pull request #8 from kivra/mn-remove-beehive-special-case
maxno-kivra Jan 31, 2020
10b7d7c
Ignore build and lock file
maxno-kivra Dec 16, 2019
a8a1ab2
Support Sentry users for general error macros
maxno-kivra Dec 16, 2019
0e39934
Merge pull request #9 from kivra:mn-raven-user-from-extras
maxno-kivra Feb 4, 2020
58fd5b7
feat: Support for structured warning messages to Sentry (#10)
zigge-zagge Dec 10, 2020
bd9ea54
fix: Bug in parse_message
moritzploss-k Aug 12, 2021
61bbd8e
fix: Bug in parse_message (#11)
moritzploss-k Aug 12, 2021
2b3aa62
Add basic logger handler that sends logs to sentry
RSBRK Oct 12, 2021
4fe754f
Drop logs from httpc to prevent a log loop
RSBRK Oct 13, 2021
3447f63
Handle more types of log messages
RSBRK Oct 15, 2021
be5773f
Fix level mismatch with sentry and handle reports better
RSBRK Oct 18, 2021
a596916
Add all meta values to the additional data part of the log
RSBRK Oct 19, 2021
de97c91
feat:add skeleton for save sending to sentry
rolkar-kivra Oct 19, 2021
1881b84
chore: change from gen_event to gen_server for sending sfe to sentry
rolkar-kivra Oct 20, 2021
910db04
chore: starte sending safe from supervisor
rolkar-kivra Oct 20, 2021
0b3df53
chore: send via safe sentry
rolkar-kivra Oct 20, 2021
6863cd2
Respect backoff from Sentry, allow disk logging from Raven
RSBRK Oct 25, 2021
55915fc
Use a separate config variable to enable otp_logger
RSBRK Oct 26, 2021
7a97dac
Remove dev logging
RSBRK Oct 26, 2021
c7e8201
feat: Handle stacktrace and exception from the meta map
RSBRK Oct 27, 2021
9bbd29d
feat: Support all raven props from logged map
RSBRK Oct 27, 2021
3a6ca56
Changed suggested during review
RSBRK Oct 28, 2021
4f075ed
feat: Handle legacy error_logger formating of log messages
RSBRK Oct 29, 2021
ee1224f
Handle reports that store the log message in reason and error keys
RSBRK Oct 29, 2021
b697fef
Catch format exception in logs
RSBRK Nov 3, 2021
6210abb
Merge pull request #12 from kivra/feat-otp-logger-sentry-backend
RSBRK Nov 8, 2021
37b601a
chore: improve logging, applying report_cb to one more case
rolkar-kivra Nov 24, 2021
1375e6c
Merge pull request #13 from kivra/improve-logging-applying-report_cb-…
rolkar-kivra Nov 24, 2021
3dd78dd
chore: more general reason in sentry
rolkar-kivra Nov 29, 2021
4410934
Merge pull request #14 from kivra/sentry-more-general-reason
rolkar-kivra Nov 29, 2021
72a8b85
chore: Add report to sentry log
rolkar-kivra Nov 29, 2021
13fc7f4
eunit: Add report to sentry log
rolkar-kivra Nov 30, 2021
4f0488d
chore: Add the tag correlation_id to sentry report
rolkar-kivra Dec 1, 2021
675ac9d
eunit: one more test case
rolkar-kivra Dec 1, 2021
2b522ad
chore: better logging of unexpected log format
rolkar-kivra Dec 1, 2021
6728eab
Merge pull request #15 from kivra/sentry-add-report
rolkar-kivra Dec 1, 2021
3058233
chore: proplists:from_map is not available in otp 23 (#18)
chsukivra Jan 24, 2022
56dd24d
feat: Catch crashing otp logger plugin (#16)
rolkar-kivra Jan 24, 2022
6ee694a
feat: add possibility to configure ssl options (#19)
chsukivra Feb 3, 2022
8f61531
fix: Don't send extra data as attributes
moritzploss-k Feb 28, 2022
4f9bd67
fix: Don't send extra data as attributes
moritzploss-k Feb 28, 2022
285ff14
Use 'reason' field when provided (defaults to message) (#21)
ssepml Apr 19, 2022
dccf360
Also get message from 'message' field (#22)
ssepml Apr 22, 2022
6d8659b
Removed stdlib2
kivra-thohut Aug 29, 2023
dc48a2c
Removed stdlib2
kivra-thohut Aug 29, 2023
c58e4c8
Removed stdlib2
kivra-thohut Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*~
.*
/deps/
/ebin/
/_build
rebar.lock
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROJECT = raven

DIALYZER = dialyzer
REBAR = rebar
REBAR = rebar3

all: app

Expand Down
23 changes: 15 additions & 8 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 noet syntax=erlang
{erl_opts, [
warnings_as_errors,
warn_export_all,
{platform_define, "^R14", no_callbacks}
]}.
{deps, [
{jiffy, ".*", {git, "git://github.com/davisp/jiffy.git", {tag, "0.13.1"}}}
]}.
{erl_opts, [ warnings_as_errors,
warn_export_all,
{platform_define, "^R14", no_callbacks}
]
}.

{deps, [ {jsx, ".*", {git, "[email protected]:kivra/jsx.git", {tag, "2.9.0"}}} ]
}.

{profiles, [ {test, [ {deps, [ {meck, {git, "[email protected]:kivra/meck.git", {tag, "0.8.13"}}}]},
{extra_src_dirs, [{"test", [{recursive, true}]}]}
]
}
]
}.
3 changes: 1 addition & 2 deletions src/raven.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
crypto,
public_key,
ssl,
inets,
jiffy
inets
]},
{mod, {raven_app, []}},
{env, [
Expand Down
106 changes: 80 additions & 26 deletions src/raven.erl
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
-module(raven).
-export([
capture/2,
capture_prepare/2,
capture_with_backoff_send/2,
user_agent/0
]).

-include("raven.hrl").

-define(SENTRY_VERSION, "2.0").

-record(cfg, {
uri :: string(),
public_key :: string(),
private_key :: string(),
project :: string(),
ipfamily :: atom()
ipfamily :: atom(),
release :: binary() | undefined
}).

-type cfg_rec() :: #cfg{}.
Expand All @@ -27,34 +32,61 @@
capture(Message, Params) when is_list(Message) ->
capture(unicode:characters_to_binary(Message), Params);
capture(Message, Params) ->
{ok, Body} = capture_prepare(Message, Params),
capture_with_backoff_send(Body, false).

capture_prepare(Message, Params) ->
Cfg = get_config(),
Document = {[
Document = [
{event_id, event_id_i()},
{project, unicode:characters_to_binary(Cfg#cfg.project)},
{platform, erlang},
{server_name, node()},
{timestamp, timestamp_i()},
{release, Cfg#cfg.release},
{message, term_to_json_i(Message)} |
lists:map(fun
({stacktrace, Value}) ->
{'sentry.interfaces.Stacktrace', {[
{'sentry.interfaces.Stacktrace', [
{frames,lists:reverse([frame_to_json_i(Frame) || Frame <- Value])}
]}};
]};
({exception, {Type, Value}}) ->
{'sentry.interfaces.Exception', {[
{type, Type},
{'sentry.interfaces.Exception', [
{type, term_to_json_i(Type)},
{value, term_to_json_i(Value)}
]};
({exception, Value}) ->
{'sentry.interfaces.Exception', [
{type, error},
{value, term_to_json_i(Value)}
]}};
]};
({http_request, {Method, Url, Headers}}) ->
{'sentry.interfaces.Http', [
{method, Method},
{url, Url},
{headers, Headers}
]};
% Reserved keys are 'id', 'username', 'email' and 'ip_address' out
% of which ONE needs to be supplied. Additional arbitrary keys may
% also be sent.
({user, KVs}) when is_list(KVs) ->
{'sentry.interfaces.User', KVs};
({tags, Tags}) ->
{tags, {[{Key, term_to_json_i(Value)} || {Key, Value} <- Tags]}};
{tags, [{Key, term_to_json_i(Value)} || {Key, Value} <- Tags]};
({extra, Tags}) ->
{extra, {[{Key, term_to_json_i(Value)} || {Key, Value} <- Tags]}};
{extra, [{Key, term_to_json_i(Value)} || {Key, Value} <- Tags]};
({Key, Value}) ->
{Key, term_to_json_i(Value)}
end, Params)
]},
],
Body = base64:encode(zlib:compress(jsx:encode(Document))),
{ok, Body}.

%Synchronized set to true returns backoff
%otherwise, it is not returned
capture_with_backoff_send(Body, Synchronized) ->
Cfg = get_config(),
Timestamp = integer_to_list(unix_timestamp_i()),
Body = base64:encode(zlib:compress(jiffy:encode(Document, [force_utf8]))),
UA = user_agent(),
Headers = [
{"X-Sentry-Auth",
Expand All @@ -65,18 +97,39 @@ capture(Message, Params) ->
{"User-Agent", UA}
],
ok = httpc:set_options([{ipfamily, Cfg#cfg.ipfamily}]),
httpc:request(post,
{ok, Result} = httpc:request(post,
{Cfg#cfg.uri ++ "/api/store/", Headers, "application/octet-stream", Body},
[],
[{body_format, binary}, {sync, false}]
[ssl_options()],
[{body_format, binary}, {sync, Synchronized}],
?RAVEN_HTTPC_PROFILE
),
ok.
case Synchronized of
false -> ok;
true -> {ok, extract_backoff(Result)}
end.

extract_backoff(Result) when is_reference(Result) ->
io:format("~nHTTP return was reference ~p~n", [Result]),
0;
extract_backoff({StatusLine, Headers, _Body}) ->
{_,ResponseCode, _} = StatusLine,
case ResponseCode of
429 ->
Backoff = list_to_integer(proplists:get_value("retry-after", Headers)),
io:format(" retry: ~p~n", [Backoff]),
Backoff;
_ ->
0
end.

-spec user_agent() -> iolist().
user_agent() ->
{ok, Vsn} = application:get_key(raven, vsn),
["raven-erlang/", Vsn].

ssl_options() ->
persistent_term:get(?RAVEN_SSL_PERSIST_KEY).

%% @private
-spec get_config() -> cfg_rec().
get_config() ->
Expand All @@ -85,6 +138,7 @@ get_config() ->
-spec get_config(App :: atom()) -> cfg_rec().
get_config(App) ->
{ok, IpFamily} = application:get_env(App, ipfamily),
Release = application:get_env(App, release, undefined),
case application:get_env(App, dsn) of
{ok, Dsn} ->
{match, [_, Protocol, PublicKey, SecretKey, Uri, Project]} =
Expand All @@ -93,7 +147,8 @@ get_config(App) ->
public_key = PublicKey,
private_key = SecretKey,
project = Project,
ipfamily = IpFamily};
ipfamily = IpFamily,
release = Release};
undefined ->
{ok, Uri} = application:get_env(App, uri),
{ok, PublicKey} = application:get_env(App, public_key),
Expand All @@ -103,16 +158,17 @@ get_config(App) ->
public_key = PublicKey,
private_key = PrivateKey,
project = Project,
ipfamily = IpFamily}
ipfamily = IpFamily,
release = Release}
end.


event_id_i() ->
U0 = crypto:rand_uniform(0, (2 bsl 32) - 1),
U1 = crypto:rand_uniform(0, (2 bsl 16) - 1),
U2 = crypto:rand_uniform(0, (2 bsl 12) - 1),
U3 = crypto:rand_uniform(0, (2 bsl 32) - 1),
U4 = crypto:rand_uniform(0, (2 bsl 30) - 1),
U0 = rand:uniform((2 bsl 32) - 1) - 1,
U1 = rand:uniform((2 bsl 16) - 1) - 1,
U2 = rand:uniform((2 bsl 12) - 1) - 1,
U3 = rand:uniform((2 bsl 32) - 1) - 1,
U4 = rand:uniform((2 bsl 30) - 1) - 1,
<<UUID:128>> = <<U0:32, U1:16, 4:4, U2:12, 2#10:2, U3:32, U4:30>>,
iolist_to_binary(io_lib:format("~32.16.0b", [UUID])).

Expand All @@ -136,7 +192,6 @@ frame_to_json_i({Module, Function, Arguments, Location}) ->
false -> -1;
{line, L} -> L
end,
{
case is_list(Arguments) of
true -> [{vars, [iolist_to_binary(io_lib:format("~w", [Argument])) || Argument <- Arguments]}];
false -> []
Expand All @@ -148,10 +203,9 @@ frame_to_json_i({Module, Function, Arguments, Location}) ->
false -> <<(atom_to_binary(Module, utf8))/binary, ".erl">>;
{file, File} -> list_to_binary(File)
end}
]
}.
].

term_to_json_i(Term) when is_binary(Term); is_atom(Term) ->
Term;
term_to_json_i(Term) ->
iolist_to_binary(io_lib:format("~120p", [Term])).
iolist_to_binary(raven_io:format("~120p", [Term])).
7 changes: 7 additions & 0 deletions src/raven.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

%% The httpc profile used by raven
-define(RAVEN_HTTPC_PROFILE, raven).

%% Key of persistent term for httpc ssl options
-define(RAVEN_SSL_PERSIST_KEY, {raven, ssl}).

36 changes: 33 additions & 3 deletions src/raven_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
stop/1
]).

-include("raven.hrl").

-spec start() -> ok | {error, term()}.
start() ->
ensure_started(raven).
Expand All @@ -21,13 +23,39 @@ stop() ->

%% @hidden
start(_StartType, _StartArgs) ->
case application:get_env(ssl) of
{ok, Options} ->
persistent_term:put(?RAVEN_SSL_PERSIST_KEY, {ssl, Options});
_ ->
logger:notice("Raven not configured with httpc ssl options"),
persistent_term:put(?RAVEN_SSL_PERSIST_KEY, {ssl, []})
end,
{ok, _ProfilePid} = inets:start(httpc, [{profile, ?RAVEN_HTTPC_PROFILE}]),
case application:get_env(uri) of
{ok, _} ->
case application:get_env(error_logger) of
{ok, true} -> error_logger:add_report_handler(raven_error_logger);
{ok, true} ->
error_logger:add_report_handler(raven_error_logger);
_ -> ok
end,
raven_sup:start_link();
case application:get_env(otp_logger) of
{ok, true} ->
logger:add_handler(raven_otp_logger, raven_logger_backend, #{level => warning
, filter_default => log
, filters => [{ssl, {fun logger_filters:domain/2, {stop, sub, [ssl]}}}
,{progress, {fun logger_filters:domain/2, {stop, equal, [progress]}}}
,{raven, {fun logger_filters:domain/2, {stop, sub, [raven]}}}
,{sasl, {fun logger_filters:domain/2, {stop, sub, [otp, sasl]}}}
]});
_ ->
ok
end,
case raven_sup:start_link() of
{ok, Pid} ->
{ok, Pid};
Error ->
Error
end;
_ ->
{error, missing_configuration}
end.
Expand All @@ -40,7 +68,9 @@ stop(_State) ->
ok;
_ ->
ok
end.
end,
inets:stop(httpc, ?RAVEN_HTTPC_PROFILE),
ok.

%% @private
ensure_started(App) ->
Expand Down
Loading