Current section
22 Versions
Jump to
Current section
22 Versions
Compare versions
14
files changed
+514
additions
-49
deletions
| @@ -1,26 +1,30 @@ | |
| 1 1 | {<<"links">>,[{<<"Github">>,<<"https://github.com/mrdotb/disco-log">>}]}. |
| 2 2 | {<<"name">>,<<"disco_log">>}. |
| 3 | - {<<"version">>,<<"0.7.0">>}. |
| 3 | + {<<"version">>,<<"0.8.0-rc.0">>}. |
| 4 4 | {<<"description">>, |
| 5 5 | <<"Use Discord as a logging service and error tracking solution">>}. |
| 6 6 | {<<"elixir">>,<<"~> 1.17">>}. |
| 7 7 | {<<"app">>,<<"disco_log">>}. |
| 8 8 | {<<"licenses">>,[<<"MIT">>]}. |
| 9 9 | {<<"files">>, |
| 10 | - [<<"lib">>,<<"lib/disco_log">>,<<"lib/disco_log/application.ex">>, |
| 11 | - <<"lib/disco_log/supervisor.ex">>,<<"lib/disco_log/registry.ex">>, |
| 12 | - <<"lib/disco_log/context.ex">>,<<"lib/disco_log/client.ex">>, |
| 13 | - <<"lib/disco_log/config.ex">>,<<"lib/disco_log/discord.ex">>, |
| 14 | - <<"lib/disco_log/encoder.ex">>,<<"lib/disco_log/stacktrace.ex">>, |
| 15 | - <<"lib/disco_log/discord">>,<<"lib/disco_log/discord/context.ex">>, |
| 10 | + [<<"lib">>,<<"lib/disco_log">>,<<"lib/disco_log/presence.ex">>, |
| 11 | + <<"lib/disco_log/application.ex">>,<<"lib/disco_log/supervisor.ex">>, |
| 12 | + <<"lib/disco_log/registry.ex">>,<<"lib/disco_log/context.ex">>, |
| 13 | + <<"lib/disco_log/client.ex">>,<<"lib/disco_log/config.ex">>, |
| 14 | + <<"lib/disco_log/discord.ex">>,<<"lib/disco_log/encoder.ex">>, |
| 15 | + <<"lib/disco_log/stacktrace.ex">>,<<"lib/disco_log/discord">>, |
| 16 | + <<"lib/disco_log/discord/context.ex">>, |
| 16 17 | <<"lib/disco_log/discord/client.ex">>,<<"lib/disco_log/discord/config.ex">>, |
| 17 18 | <<"lib/disco_log/error.ex">>,<<"lib/disco_log/dedupe.ex">>, |
| 18 19 | <<"lib/disco_log/logger_handler.ex">>,<<"lib/disco_log/storage.ex">>, |
| 20 | + <<"lib/disco_log/websocket_client">>, |
| 21 | + <<"lib/disco_log/websocket_client/impl.ex">>, |
| 19 22 | <<"lib/disco_log/integrations">>,<<"lib/disco_log/integrations/oban.ex">>, |
| 20 23 | <<"lib/disco_log/integrations/plug.ex">>, |
| 21 24 | <<"lib/disco_log/integrations/tesla.ex">>, |
| 22 | - <<"lib/disco_log/integrations/phoenix.ex">>,<<"lib/mix">>, |
| 23 | - <<"lib/mix/tasks">>,<<"lib/mix/tasks/disco_log.drop.ex">>, |
| 25 | + <<"lib/disco_log/integrations/phoenix.ex">>, |
| 26 | + <<"lib/disco_log/websocket_client.ex">>,<<"lib/mix">>,<<"lib/mix/tasks">>, |
| 27 | + <<"lib/mix/tasks/disco_log.drop.ex">>, |
| 24 28 | <<"lib/mix/tasks/disco_log.cleanup.ex">>, |
| 25 29 | <<"lib/mix/tasks/disco_log.create.ex">>, |
| 26 30 | <<"lib/mix/tasks/disco_log.sample.ex">>,<<"lib/disco_log.ex">>, |
| @@ -45,5 +49,10 @@ | |
| 45 49 | {<<"app">>,<<"nimble_options">>}, |
| 46 50 | {<<"optional">>,false}, |
| 47 51 | {<<"requirement">>,<<"~> 1.1">>}, |
| 52 | + {<<"repository">>,<<"hexpm">>}], |
| 53 | + [{<<"name">>,<<"mint_web_socket">>}, |
| 54 | + {<<"app">>,<<"mint_web_socket">>}, |
| 55 | + {<<"optional">>,true}, |
| 56 | + {<<"requirement">>,<<"~> 1.0">>}, |
| 48 57 | {<<"repository">>,<<"hexpm">>}]]}. |
| 49 58 | {<<"build_tools">>,[<<"mix">>]}. |
| @@ -6,7 +6,7 @@ defmodule DiscoLog do | |
| 6 6 | config = config || DiscoLog.Config.read!() |
| 7 7 | context = Map.merge(DiscoLog.Context.get(), given_context) |
| 8 8 | |
| 9 | - error = DiscoLog.Error.new(exception, stacktrace, context, config.otp_app) |
| 9 | + error = DiscoLog.Error.new(exception, stacktrace, context, config) |
| 10 10 | DiscoLog.Client.send_error(error, config) |
| 11 11 | end |
| 12 12 | end |
| @@ -57,6 +57,11 @@ defmodule DiscoLog.Config do | |
| 57 57 | default: false, |
| 58 58 | doc: "Logs requests to Discord API?" |
| 59 59 | ], |
| 60 | + enable_presence: [ |
| 61 | + type: :boolean, |
| 62 | + default: false, |
| 63 | + doc: "Show DiscoLog bot status as Online?" |
| 64 | + ], |
| 60 65 | instrument_oban: [ |
| 61 66 | type: :boolean, |
| 62 67 | default: true, |
| @@ -97,6 +102,32 @@ defmodule DiscoLog.Config do | |
| 97 102 | type: :atom, |
| 98 103 | default: DiscoLog, |
| 99 104 | doc: "Name of the supervisor process running DiscoLog" |
| 105 | + ], |
| 106 | + presence_status: [ |
| 107 | + type: :string, |
| 108 | + default: "🪩 Disco Logging", |
| 109 | + doc: "A message to display as the bot's status when presence is enabled" |
| 110 | + ], |
| 111 | + enable_go_to_repo: [ |
| 112 | + type: :boolean, |
| 113 | + default: false, |
| 114 | + doc: "Enable go_to_repo feature?" |
| 115 | + ], |
| 116 | + go_to_repo_top_modules: [ |
| 117 | + type: {:list, :string}, |
| 118 | + default: [], |
| 119 | + doc: |
| 120 | + "List of top-level modules that are not part of the application spec but code belongs to the app" |
| 121 | + ], |
| 122 | + repo_url: [ |
| 123 | + type: :string, |
| 124 | + default: "", |
| 125 | + doc: "URL to the git repository viewer" |
| 126 | + ], |
| 127 | + git_sha: [ |
| 128 | + type: :string, |
| 129 | + default: "", |
| 130 | + doc: "The git SHA of the running app" |
| 100 131 | ] |
| 101 132 | ] |
| 102 133 | |
| @@ -147,7 +178,8 @@ defmodule DiscoLog.Config do | |
| 147 178 | end |
| 148 179 | |
| 149 180 | def validate(raw_options) do |
| 150 | - with {:ok, validated} <- NimbleOptions.validate(raw_options, @compiled_schema) do |
| 181 | + with {:ok, validated} <- NimbleOptions.validate(raw_options, @compiled_schema), |
| 182 | + {:ok, validated} <- validate_optional_dependencies(validated) do |
| 151 183 | config = |
| 152 184 | validated |
| 153 185 | |> Map.new() |
| @@ -158,4 +190,21 @@ defmodule DiscoLog.Config do | |
| 158 190 | {:ok, config} |
| 159 191 | end |
| 160 192 | end |
| 193 | + |
| 194 | + if Code.ensure_loaded?(Mint.WebSocket) do |
| 195 | + defp validate_optional_dependencies(validated), do: {:ok, validated} |
| 196 | + else |
| 197 | + defp validate_optional_dependencies(validated) do |
| 198 | + if value = validated[:enable_presence] do |
| 199 | + {:error, |
| 200 | + %NimbleOptions.ValidationError{ |
| 201 | + message: "optional mint_web_socket dependency is missing", |
| 202 | + key: :enable_presence, |
| 203 | + value: value |
| 204 | + }} |
| 205 | + else |
| 206 | + {:ok, validated} |
| 207 | + end |
| 208 | + end |
| 209 | + end |
| 161 210 | end |
| @@ -34,6 +34,8 @@ defmodule DiscoLog.DiscordBehaviour do | |
| 34 34 | {:ok, map()} | {:error, String.t()} |
| 35 35 | |
| 36 36 | @callback delete_threads(config(), channel_id :: String.t()) :: list(any) |
| 37 | + |
| 38 | + @callback get_gateway(config()) :: {:ok, String.t()} | {:error, String.t()} |
| 37 39 | end |
| 38 40 | |
| 39 41 | defmodule DiscoLog.Discord do |
| @@ -71,4 +73,7 @@ defmodule DiscoLog.Discord do | |
| 71 73 | |
| 72 74 | @impl true |
| 73 75 | defdelegate delete_threads(config, channel_id), to: Discord.Context |
| 76 | + |
| 77 | + @impl true |
| 78 | + defdelegate get_gateway(config), to: Discord.Context |
| 74 79 | end |
| @@ -121,6 +121,16 @@ defmodule DiscoLog.Discord.Client do | |
| 121 121 | end |
| 122 122 | end |
| 123 123 | |
| 124 | + def get_gateway(config) do |
| 125 | + case Req.get!(client(config), url: "/gateway/bot") do |
| 126 | + %Req.Response{status: 200, body: body} -> |
| 127 | + {:ok, body} |
| 128 | + |
| 129 | + _ -> |
| 130 | + {:error, "Failed to get gateway"} |
| 131 | + end |
| 132 | + end |
| 133 | + |
| 124 134 | def client(config) do |
| 125 135 | Req.new( |
| 126 136 | base_url: @base_url, |
Loading more files…