Skip to content

Commit fcdf688

Browse files
authored
Merge pull request #515 from newrelic/vince/internal-span-attributes
Enable adding span attrs inside span macro
2 parents 1a20891 + 2e7f0aa commit fcdf688

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/new_relic/tracer/direct.ex

+6-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ defmodule NewRelic.Tracer.Direct do
5050
end
5151

5252
name = Keyword.get(options, :name, name)
53-
stop_attributes = Keyword.get(options, :attributes, []) |> Map.new()
54-
attributes = Map.merge(start_attributes, stop_attributes)
5553
timestamp_ms = System.convert_time_unit(system_time, :native, :millisecond)
54+
stop_attributes = Keyword.get(options, :attributes, []) |> Map.new()
55+
56+
attributes =
57+
start_attributes
58+
|> Map.merge(NewRelic.DistributedTrace.get_span_attrs())
59+
|> Map.merge(stop_attributes)
5660

5761
{primary_name, secondary_name} =
5862
case name do

test/span_event_test.exs

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ defmodule SpanEventTest do
117117
end
118118

119119
NewRelic.span "another.span", with: "an attribute" do
120+
NewRelic.add_span_attributes(inside: "attribute!")
120121
Process.sleep(5)
121122
end
122123

@@ -205,6 +206,7 @@ defmodule SpanEventTest do
205206

206207
assert another_span[:category] == "generic"
207208
assert another_span[:with] == "an attribute"
209+
assert another_span[:inside] == "attribute!"
208210

209211
[single_span, _, _] =
210212
Enum.find(span_events, fn [ev, _, _] ->

0 commit comments

Comments
 (0)