Skip to content

Commit

Permalink
Add telemetry events for diagnostics and indexing (erlang-ls#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoaloi committed May 19, 2022
1 parent b5359d5 commit 97721de
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
14 changes: 13 additions & 1 deletion apps/els_lsp/src/els_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ run_diagnostic(Uri, Id) ->
Source = CbModule:source(),
Module = atom_to_binary(els_uri:module(Uri), utf8),
Title = <<Source/binary, " (", Module/binary, ")">>,
Start = erlang:monotonic_time(millisecond),
Config = #{
task => fun(U, _) -> CbModule:run(U) end,
entries => [Uri],
Expand All @@ -137,7 +138,18 @@ run_diagnostic(Uri, Id) ->
false ->
ok
end,
els_diagnostics_provider:notify(Diagnostics, self())
els_diagnostics_provider:notify(Diagnostics, self()),
End = erlang:monotonic_time(millisecond),
Duration = End - Start,
Event = #{
uri => Uri,
source => Source,
duration_ms => Duration,
number_of_diagnostics => length(Diagnostics),
type => <<"diagnostics">>
},
?LOG_DEBUG("Diagnostics completed. [event=~p]", [Event]),
els_telemetry:send_notification(Event)
end
},
{ok, Pid} = els_background_job:new(Config),
Expand Down
14 changes: 13 additions & 1 deletion apps/els_lsp/src/els_indexing.erl
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,30 @@ start(Group, Skip, SkipTag, Entries, Source) ->
{Su, Sk, Fa} = index_dir(Dir, Skip, SkipTag, Source),
{Succeeded0 + Su, Skipped0 + Sk, Failed0 + Fa}
end,
Start = erlang:monotonic_time(millisecond),
Config = #{
task => Task,
entries => Entries,
title => <<"Indexing ", Group/binary>>,
initial_state => {0, 0, 0},
on_complete =>
fun({Succeeded, Skipped, Failed}) ->
End = erlang:monotonic_time(millisecond),
Duration = End - Start,
Event = #{
group => Group,
duration_ms => Duration,
succeeded => Succeeded,
skipped => Skipped,
failed => Failed,
type => <<"indexing">>
},
?LOG_INFO(
"Completed indexing for ~s "
"(succeeded: ~p, skipped: ~p, failed: ~p)",
[Group, Succeeded, Skipped, Failed]
)
),
els_telemetry:send_notification(Event)
end
},
{ok, _Pid} = els_background_job:new(Config),
Expand Down
10 changes: 10 additions & 0 deletions apps/els_lsp/src/els_telemetry.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-module(els_telemetry).

-export([send_notification/1]).

-type event() :: map().

-spec send_notification(event()) -> ok.
send_notification(Event) ->
Method = <<"telemetry/event">>,
els_server:send_notification(Method, Event).
2 changes: 1 addition & 1 deletion apps/els_lsp/test/els_diagnostics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ mock_compiler_telemetry_enabled() ->
-spec wait_for_compiler_telemetry() -> {uri(), [els_diagnostics:diagnostic()]}.
wait_for_compiler_telemetry() ->
receive
{on_complete_telemetry, Params} ->
{on_complete_telemetry, #{type := <<"erlang-diagnostic-codes">>} = Params} ->
Params
end.

Expand Down

0 comments on commit 97721de

Please sign in to comment.