Skip to content

Commit

Permalink
Experiment with AppSignal for monitoring (#888)
Browse files Browse the repository at this point in the history
* Test out appsignal for monitoring

* Try adding appsignal config to runtime.exs

* Try setting active: true for appsignal

* Test removing all but runtime config
  • Loading branch information
reichert621 committed Jun 21, 2021
1 parent 537c2b0 commit 4dcaa5d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ config :ex_aws,
region: region
]

config :appsignal, :config,
otp_app: :chat_api,
name: "chat_api",
push_api_key: System.get_env("APPSIGNAL_API_KEY"),
env: Mix.env(),
active: true

case System.get_env("PAPERCUPS_STRIPE_SECRET") do
"sk_" <> _rest = api_key ->
config :stripity_stripe, api_key: api_key
Expand Down
3 changes: 3 additions & 0 deletions lib/chat_api_web/channels/conversation_channel.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule ChatApiWeb.ConversationChannel do
use ChatApiWeb, :channel
use Appsignal.Instrumentation.Decorators

alias ChatApiWeb.Presence
alias ChatApi.{Messages, Conversations}
Expand Down Expand Up @@ -75,6 +76,7 @@ defmodule ChatApiWeb.ConversationChannel do
{:reply, {:ok, payload}, socket}
end

@decorate channel_action()
def handle_in("shout", payload, socket) do
with %{conversation: conversation} <- socket.assigns,
%{id: conversation_id, account_id: account_id} <- conversation,
Expand All @@ -98,6 +100,7 @@ defmodule ChatApiWeb.ConversationChannel do
{:noreply, socket}
end

@decorate channel_action()
def handle_in("messages:seen", _payload, socket) do
with %{conversation: conversation} <- socket.assigns,
%{id: conversation_id} <- conversation do
Expand Down
4 changes: 4 additions & 0 deletions lib/chat_api_web/channels/event_channel.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule ChatApiWeb.EventChannel do
use ChatApiWeb, :channel
use Appsignal.Instrumentation.Decorators

alias ChatApiWeb.Presence

Expand Down Expand Up @@ -99,13 +100,15 @@ defmodule ChatApiWeb.EventChannel do
{:reply, {:ok, payload}, socket}
end

@decorate channel_action()
def handle_in("replay:event:emitted", payload, socket) do
enqueue_process_browser_replay_event(payload, socket)
broadcast_to_admin(socket, "replay:event:emitted", payload)

{:noreply, socket}
end

@decorate channel_action()
def handle_in("session:active", _payload, socket) do
topic = get_admin_all_topic(socket)
key = "session:" <> socket.assigns.browser_session_id
Expand All @@ -120,6 +123,7 @@ defmodule ChatApiWeb.EventChannel do
{:noreply, socket}
end

@decorate channel_action()
def handle_in("session:inactive", _payload, socket) do
topic = get_admin_all_topic(socket)
key = "session:" <> socket.assigns.browser_session_id
Expand Down
3 changes: 3 additions & 0 deletions lib/chat_api_web/channels/notification_channel.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule ChatApiWeb.NotificationChannel do
use ChatApiWeb, :channel
use Appsignal.Instrumentation.Decorators

alias ChatApiWeb.Presence
alias Phoenix.Socket.Broadcast
Expand All @@ -26,13 +27,15 @@ defmodule ChatApiWeb.NotificationChannel do
{:reply, {:ok, payload}, socket}
end

@decorate channel_action()
def handle_in("read", %{"conversation_id" => id}, socket) do
{:ok, conversation} = Conversations.mark_conversation_read(id)
Conversations.Notification.notify(conversation, :webhooks, event: "conversation:updated")

{:reply, :ok, socket}
end

@decorate channel_action()
def handle_in("shout", payload, socket) do
with %{current_user: current_user} <- socket.assigns,
%{id: user_id, account_id: account_id} <- current_user do
Expand Down
1 change: 1 addition & 0 deletions lib/chat_api_web/endpoint.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule ChatApiWeb.Endpoint do
use Sentry.PlugCapture
use Phoenix.Endpoint, otp_app: :chat_api
use Appsignal.Phoenix

# The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with.
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ defmodule ChatApi.MixProject do
{:floki, "~> 0.30.0"},
{:paginator, "~> 1.0.3"},
{:phoenix_pubsub_redis, "~> 3.0.0"},
{:appsignal_phoenix, "~> 2.0.0"},
{:mix_test_watch, "~> 1.0", only: :dev, runtime: false}
]
end
Expand Down
4 changes: 4 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
%{
"appsignal": {:hex, :appsignal, "2.1.7", "b7d976ea3183ccf4cffde1763b38ed21ad7483084e516f1dc22e83b6f55f1ee9", [:make, :mix], [{:decorator, "~> 1.2.3 or ~> 1.3", [hex: :decorator, repo: "hexpm", optional: false]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, ">= 1.3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "83533fd5adb8df13c231089968fcdb10c53c686e62aee7c9c69fc5656ae816aa"},
"appsignal_phoenix": {:hex, :appsignal_phoenix, "2.0.7", "4806a6ad75619a930bf218789e3f9d6df5c5341b20dee422c015ca3ebb5c33ee", [:mix], [{:appsignal_plug, ">= 2.0.8 and < 3.0.0", [hex: :appsignal_plug, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.11", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.9", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "623ceea265b94bdb958c54b39fcb5d59f2d05eeda30f9a67c9e24d0f4d803520"},
"appsignal_plug": {:hex, :appsignal_plug, "2.0.8", "1021f4f4039a360a2dd01163e035f1cb49ce52fc7d7edf144bfe9743e508f40c", [:mix], [{:appsignal, ">= 2.1.5 and < 3.0.0", [hex: :appsignal, repo: "hexpm", optional: false]}, {:plug, ">= 1.1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "fa7dbf18c5998e60b465fc4aa5de5608b2fee47b1a0ef4fa88c6659f19429074"},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"},
Expand All @@ -10,6 +13,7 @@
"customerio": {:hex, :customerio, "0.2.2", "0a7848cbeb5ea7fd7b481dfcf58ace5f760a73f366847af2d429b2412f9066e6", [:mix], [{:hackney, "~> 1.15", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "76028accaec18de17ad2fabf6553d5752d574f2aa520eca49a8986a2f9c0eabe"},
"db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"},
"decimal": {:hex, :decimal, "1.9.0", "83e8daf59631d632b171faabafb4a9f4242c514b0a06ba3df493951c08f64d07", [:mix], [], "hexpm", "b1f2343568eed6928f3e751cf2dffde95bfaa19dd95d09e8a9ea92ccfd6f7d85"},
"decorator": {:hex, :decorator, "1.4.0", "a57ac32c823ea7e4e67f5af56412d12b33274661bb7640ec7fc882f8d23ac419", [:mix], [], "hexpm", "0a07cedd9083da875c7418dea95b78361197cf2bf3211d743f6f7ce39656597f"},
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"ecto": {:hex, :ecto, "3.4.6", "08f7afad3257d6eb8613309af31037e16c36808dfda5a3cd0cb4e9738db030e4", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6f13a9e2a62e75c2dcfc7207bfc65645ab387af8360db4c89fee8b5a4bf3f70b"},
"ecto_sql": {:hex, :ecto_sql, "3.4.5", "30161f81b167d561a9a2df4329c10ae05ff36eca7ccc84628f2c8b9fa1e43323", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "31990c6a3579b36a3c0841d34a94c275e727de8b84f58509da5f1b2032c98ac2"},
Expand Down

0 comments on commit 4dcaa5d

Please sign in to comment.