Skip to content

Commit 1624e04

Browse files
committed
feat: Add Scout APM monitoring
1 parent f75cc2d commit 1624e04

File tree

18 files changed

+59
-4
lines changed

18 files changed

+59
-4
lines changed

apps/cf/config/config.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,7 @@ config :guardian, Guardian.DB, repo: DB.Repo
5757
config :rollbax,
5858
enabled: :log
5959

60+
config :scout_apm, name: "CaptainFact"
61+
6062
# Import environment specific config
6163
import_config "#{Mix.env()}.exs"

apps/cf/mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ defmodule CF.Mixfile do
5858
{:sweet_xml, "~> 0.6"},
5959
{:burnex, "~> 1.0"},
6060
{:yaml_elixir, "~> 2.4.0"},
61+
{:scout_apm, "~> 1.0.6"},
6162

6263
# ---- Internal ----
6364
{:db, in_umbrella: true},

apps/cf_graphql/lib/endpoint.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ defmodule CF.GraphQLWeb.Endpoint do
1818
json_decoder: Poison
1919
)
2020

21+
plug(ScoutApm.Absinthe.Plug)
2122
plug(Plug.MethodOverride)
2223
plug(Plug.Head)
2324
plug(CF.GraphQLWeb.Router)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
defmodule ScoutApm.Absinthe.Plug do
2+
alias ScoutApm.Internal.Layer
3+
4+
def init(default), do: default
5+
6+
def call(conn, _default) do
7+
ScoutApm.TrackedRequest.start_layer("Controller", action_name(conn))
8+
9+
conn
10+
|> Plug.Conn.register_before_send(&before_send/1)
11+
end
12+
13+
def before_send(conn) do
14+
full_name = action_name(conn)
15+
uri = "#{conn.request_path}"
16+
17+
ScoutApm.TrackedRequest.stop_layer(fn layer ->
18+
layer
19+
|> Layer.update_name(full_name)
20+
|> Layer.update_uri(uri)
21+
end)
22+
23+
conn
24+
end
25+
26+
# Takes a connection, extracts the phoenix controller & action, then manipulates & cleans it up.
27+
# Returns a string like "PageController#index"
28+
defp action_name(conn) do
29+
action_name = conn.params["operationName"]
30+
"GraphQL##{action_name}"
31+
end
32+
end

apps/cf_graphql/mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ defmodule CF.Graphql.Mixfile do
4141
{:absinthe_plug, "~> 1.4.1"},
4242
{:kaur, "~> 1.1"},
4343
{:poison, "~> 3.1"},
44+
{:scout_apm, "~> 1.0.6"},
4445

4546
# Internal dependencies
4647
{:db, in_umbrella: true},

apps/cf_jobs/lib/job.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule CF.Jobs.Job do
66
@type t :: module
77

88
use GenServer
9+
import ScoutApm.Tracing
910

1011
def init(args) do
1112
{:ok, args}

apps/cf_jobs/lib/jobs/create_notifications.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ defmodule CF.Jobs.CreateNotifications do
6565
end
6666

6767
# --- Server callbacks ---
68-
68+
@transaction_opts [type: "background", name: "update_notifications"]
6969
def handle_call({:update, force}, _from, _state) do
7070
last_action_id = ReportManager.get_last_action_id(@analyser_id)
7171

apps/cf_jobs/lib/jobs/flags.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule CF.Jobs.Flags do
4141
end
4242

4343
# --- Server callbacks ---
44-
44+
@transaction_opts [type: "background", name: "update_flags"]
4545
def handle_call(:update_flags, _from, _state) do
4646
last_action_id = ReportManager.get_last_action_id(@analyser_id)
4747

apps/cf_jobs/lib/jobs/moderation.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ defmodule CF.Jobs.Moderation do
7878

7979
# --- Internal API ---
8080

81+
@transaction_opts [type: "background", name: "update_moderation"]
8182
def handle_call(:update, _, _) do
8283
UserAction
8384
|> join(:inner, [a], uf in ModerationUserFeedback, uf.action_id == a.id)

apps/cf_jobs/lib/jobs/reputation.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ defmodule CF.Jobs.Reputation do
9999
do: max(change, @daily_loss_limit - today_change)
100100

101101
# --- Server callbacks ---
102-
102+
@transaction_opts [type: "background", name: "update_reputation"]
103103
def handle_call(:update_reputations, _from, _state) do
104104
last_action_id = ReportManager.get_last_action_id(@analyser_id)
105105

@@ -114,6 +114,7 @@ defmodule CF.Jobs.Reputation do
114114
{:reply, :ok, :ok}
115115
end
116116

117+
@transaction_opts [type: "background", name: "reset_reputation_limits"]
117118
def handle_call(:reset_daily_limits, _from, _state) do
118119
Logger.info("[Jobs.Reputation] Reset daily limits")
119120

0 commit comments

Comments
 (0)