Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extended attrs for functions, make extended attrs configurable #479

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/new_relic/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ defmodule NewRelic.Config do
* Controls all Redix instrumentation
* `:oban_instrumentation_enabled` (default `true`)
* Controls all Oban instrumentation
* `:request_queuing_metrics_enabled`
* `:request_queuing_metrics_enabled` (default `true`)
* Controls collection of request queuing metrics
* `:extended_attributes` (default `true`)
* Controls reporting extended per-source attributes for datastore, external and function traces


### Configuration
Expand Down Expand Up @@ -209,6 +211,10 @@ defmodule NewRelic.Config do
get(:features, :request_queuing_metrics)
end

def feature?(:extended_attributes) do
get(:features, :extended_attributes)
end

@doc """
Some Agent features can be controlled via configuration.

Expand Down
5 changes: 5 additions & 0 deletions lib/new_relic/init.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ defmodule NewRelic.Init do
determine_feature(
"NEW_RELIC_REQUEST_QUEUING_METRICS_ENABLED",
:request_queuing_metrics_enabled
),
extended_attributes:
determine_feature(
"NEW_RELIC_EXTENDED_ATTRIBUTES_ENABLED",
:extended_attributes_enabled
)
})
end
Expand Down
11 changes: 8 additions & 3 deletions lib/new_relic/telemetry/ecto/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ defmodule NewRelic.Telemetry.Ecto.Handler do
databaseCallCount: 1,
databaseDuration: duration_s,
datastore_call_count: 1,
datastore_duration_ms: duration_ms,
"datastore.#{table}.call_count": 1,
"datastore.#{table}.duration_ms": duration_ms
datastore_duration_ms: duration_ms
)

if NewRelic.Config.feature?(:extended_attributes) do
NewRelic.incr_attributes(
"datastore.#{table}.call_count": 1,
"datastore.#{table}.duration_ms": duration_ms
)
end
end
end

Expand Down
27 changes: 19 additions & 8 deletions lib/new_relic/tracer/report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ defmodule NewRelic.Tracer.Report do
})
)

NewRelic.incr_attributes(
"external.#{host}.call_count": 1,
"external.#{host}.duration_ms": duration_ms
)
if NewRelic.Config.feature?(:extended_attributes) do
NewRelic.incr_attributes(
"external.#{host}.call_count": 1,
"external.#{host}.duration_ms": duration_ms
)
end

NewRelic.report_metric({:external, url, component, method}, duration_s: duration_s)

Expand Down Expand Up @@ -126,10 +128,12 @@ defmodule NewRelic.Tracer.Report do
})
)

NewRelic.incr_attributes(
"external.#{function_name}.call_count": 1,
"external.#{function_name}.duration_ms": duration_ms
)
if NewRelic.Config.feature?(:extended_attributes) do
NewRelic.incr_attributes(
"external.#{function_name}.call_count": 1,
"external.#{function_name}.duration_ms": duration_ms
)
end

NewRelic.report_metric({:external, function_name}, duration_s: duration_s)

Expand Down Expand Up @@ -193,6 +197,13 @@ defmodule NewRelic.Tracer.Report do
})
)

if NewRelic.Config.feature?(:extended_attributes) do
NewRelic.incr_attributes(
"function.#{function_name}.call_count": 1,
"function.#{function_name}.duration_ms": duration_ms
)
end

NewRelic.report_metric(
{:function, function_name},
duration_s: duration_s,
Expand Down
33 changes: 33 additions & 0 deletions test/transaction_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
send_resp(conn, 200, "bar")
end

get "/fn_trace" do
HelperModule.function(10)
send_resp(conn, 200, "fn_trace")
end

get "/incr" do
NewRelic.set_transaction_name("/incr")
NewRelic.incr_attributes(one: 1, two: 1, four: 2)
Expand Down Expand Up @@ -199,7 +204,7 @@
end
end

test "Basic transaction" do

Check failure on line 207 in test/transaction_test.exs

View workflow job for this annotation

GitHub Actions / Unit Tests - Elixir 1.18 / OTP 27

test Basic transaction (TransactionTest)
TestHelper.restart_harvest_cycle(Collector.TransactionEvent.HarvestCycle)

TestHelper.request(TestPlugApp, conn(:get, "/foo/1"))
Expand Down Expand Up @@ -540,4 +545,32 @@

assert event[:"cowboy.connection_error"] == "timeout"
end

describe "Extended attributes" do
test "can be turned on" do
reset_features = TestHelper.update(:nr_features, extended_attributes: true)
TestHelper.restart_harvest_cycle(Collector.TransactionEvent.HarvestCycle)

TestHelper.request(TestPlugApp, conn(:get, "/fn_trace"))

[[_, event]] = TestHelper.gather_harvest(Collector.TransactionEvent.Harvester)

assert event[:"function.TransactionTest.HelperModule.function/1.call_count"] == 1

reset_features.()
end

test "can be turned off" do
reset_features = TestHelper.update(:nr_features, extended_attributes: false)
TestHelper.restart_harvest_cycle(Collector.TransactionEvent.HarvestCycle)

TestHelper.request(TestPlugApp, conn(:get, "/fn_trace"))

[[_, event]] = TestHelper.gather_harvest(Collector.TransactionEvent.Harvester)

refute event[:"function.TransactionTest.HelperModule.function/1.call_count"]

reset_features.()
end
end
end
Loading