Skip to content

Commit

Permalink
Also trace proc_lib:start_link (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryseed authored Apr 28, 2021
1 parent 4f8be41 commit e2eeac8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/new_relic/transaction/erlang_trace.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ defmodule NewRelic.Transaction.ErlangTrace do
{:noreply, state}
end

def handle_info(
{:trace_ts, source, :return_from, {:proc_lib, :start_link, _}, {:ok, pid}, timestamp},
state
) do
Transaction.Reporter.track_spawn(source, pid, NewRelic.Util.time_to_ms(timestamp))
overload_protection(state.overload)
{:noreply, state}
end

def handle_info(_msg, state) do
{:noreply, state}
end
Expand Down Expand Up @@ -82,6 +91,7 @@ defmodule NewRelic.Transaction.ErlangTrace do

defp trace_proc_lib_spawn_link do
:erlang.trace_pattern({:proc_lib, :spawn_link, :_}, [{:_, [], [{:return_trace}]}], [])
:erlang.trace_pattern({:proc_lib, :start_link, :_}, [{:_, [], [{:return_trace}]}], [])
end

defp overload_protection(%{backoff: backoff} = overload) do
Expand Down
11 changes: 11 additions & 0 deletions test/sidecar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ defmodule SidecarTest do
:ok
end

defmodule SimpleServer do
use GenServer

def init(:ok) do
NewRelic.add_attributes(gen_server: "init")
{:ok, nil}
end
end

test "Transaction.Sidecar" do
TestHelper.restart_harvest_cycle(Collector.Metric.HarvestCycle)

Expand All @@ -33,6 +42,7 @@ defmodule SidecarTest do

Task.async(fn ->
NewRelic.add_attributes(baz: "QUX")
GenServer.start_link(SimpleServer, :ok)

Task.async(fn ->
NewRelic.add_attributes(blah: "BLAH")
Expand All @@ -59,6 +69,7 @@ defmodule SidecarTest do
assert attributes[:baz] == "QUX"
assert attributes[:blah] == "BLAH"
assert attributes[:deep] == "DEEP"
assert attributes[:gen_server] == "init"

assert :ets.member(Sidecar.ContextStore, {:context, sidecar})

Expand Down

0 comments on commit e2eeac8

Please sign in to comment.