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

Use Map functionality for into and reduce #499

Merged
merged 2 commits into from
Feb 12, 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
4 changes: 1 addition & 3 deletions lib/new_relic/aggregate/aggregate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ defmodule NewRelic.Aggregate do
defp averages(%{call_count: call_count} = values) do
values
|> Stream.reject(fn {key, _value} -> key == :call_count end)
|> Enum.reduce(%{}, fn {key, value}, acc ->
Map.put(acc, :"avg_#{key}", value / call_count)
end)
|> Map.new(fn {key, value} -> {:"avg_#{key}", value / call_count} end)
end

defp averages(_values), do: %{}
Expand Down
7 changes: 2 additions & 5 deletions lib/new_relic/distributed_trace.ex
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ defmodule NewRelic.DistributedTrace do
end

def set_span(:generic, attrs) do
add_span_attributes(Enum.into(attrs, %{}))
add_span_attributes(Map.new(attrs))
end

def set_span(:http, url: url, method: method, component: component) do
Expand Down Expand Up @@ -237,10 +237,7 @@ defmodule NewRelic.DistributedTrace do
def add_span_attributes(attrs) do
Process.put(
:nr_current_span_attrs,
Map.merge(
get_span_attrs(),
Enum.into(attrs, %{})
)
Map.merge(get_span_attrs(), Map.new(attrs))
)

:ok
Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/error/trace.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule NewRelic.Error.Trace do
defp format_user_attributes(user_attributes) do
user_attributes
|> Map.drop(@intrinsics)
|> Enum.into(%{}, fn {k, v} ->
|> Map.new(fn {k, v} ->
(String.Chars.impl_for(v) && {k, v}) || {k, inspect(v)}
end)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/init.ex
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ defmodule NewRelic.Init do

def determine_automatic_attributes() do
Application.get_env(:new_relic_agent, :automatic_attributes, [])
|> Enum.into(%{}, fn
|> Map.new(fn
{name, {:system, env_var}} -> {name, System.get_env(env_var)}
{name, {m, f, a}} -> {name, apply(m, f, a)}
{name, value} -> {name, value}
Expand Down
4 changes: 2 additions & 2 deletions lib/new_relic/sampler/process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ defmodule NewRelic.Sampler.Process do
end

defp record_samples(state) do
Enum.reduce(state.pids, %{}, fn {pid, true}, acc ->
Map.new(state.pids, fn {pid, true} ->
{current_sample, stats} = collect(pid, state.previous[pid])
NewRelic.report_sample(:ProcessSample, stats)
Map.put(acc, pid, current_sample)
{pid, current_sample}
end)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/transaction/complete.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ defmodule NewRelic.Transaction.Complete do
|> Enum.map(&transform_trace_name_attrs/1)
|> Enum.map(&struct(Transaction.Trace.Segment, &1))
|> Enum.group_by(& &1.pid)
|> Enum.into(%{}, &generate_segment_tree(&1))
|> Map.new(&generate_segment_tree(&1))

root_process_segment =
tx_attrs
Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ defmodule NewRelic.Util do
def metadata() do
System.get_env()
|> Enum.filter(fn {key, _} -> String.starts_with?(key, @nr_metadata_prefix) end)
|> Enum.into(%{})
|> Map.new()
end

def utilization() do
Expand Down
2 changes: 1 addition & 1 deletion test/transaction_trace_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
end

get "/huge_args" do
Enum.into(1..10000, %{}, &{&1, &1})
Map.new(1..10000, &{&1, &1})
|> HelperModule.do_work()

HelperModule.work_hard(%{on: :something})
Expand Down Expand Up @@ -222,7 +222,7 @@
NewRelic.JSON.encode!(traces)
end

test "Transaction Trace when erlang trace disabled" do

Check failure on line 225 in test/transaction_trace_test.exs

View workflow job for this annotation

GitHub Actions / Unit Tests - Elixir 1.15 / OTP 26

test Transaction Trace when erlang trace disabled (TransactionTraceTest)
NewRelic.disable_erlang_trace()

on_exit(fn -> NewRelic.enable_erlang_trace() end)
Expand Down
2 changes: 1 addition & 1 deletion test/util_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule UtilTest do
nested: %{foo: %{bar: %{baz: "qux"}}},
nested_list: [%{one: %{two: "three"}}, %{four: "five"}, %{}, "string", ["nested string"]],
super_long_list: Enum.map(0..99, & &1),
big_map: String.graphemes("abcdefghijklmnopqrstuvwxyz") |> Enum.into(%{}, &{&1, &1})
big_map: String.graphemes("abcdefghijklmnopqrstuvwxyz") |> Map.new(&{&1, &1})
)

assert {"nested.foo.bar.baz", "qux"} in flattened
Expand Down
Loading