diff --git a/test/new_relic/agent/span_event_primitive_test.rb b/test/new_relic/agent/span_event_primitive_test.rb index 0379f463b1..edbdf61eb7 100644 --- a/test/new_relic/agent/span_event_primitive_test.rb +++ b/test/new_relic/agent/span_event_primitive_test.rb @@ -2,6 +2,7 @@ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. # frozen_string_literal: true +require 'uri' require_relative '../../test_helper' module NewRelic @@ -325,18 +326,24 @@ def test_agent_attributes_are_not_included_for_external_segments_by_default segment = MiniTest::Mock.new segment.expect(:library, :library) segment.expect(:procedure, :procedure) + segment.expect(:procedure, :procedure) # 2 calls segment.expect(:http_status_code, :http_status_code) segment.expect(:http_status_code, :http_status_code) # 2 calls - segment.expect(:uri, :uri) + segment.expect(:uri, uri_for_testing) + segment.expect(:uri, uri_for_testing) + segment.expect(:uri, uri_for_testing) # 3 calls segment.expect(:record_agent_attributes?, false) result = SpanEventPrimitive.for_external_request_segment(segment) expected_intrinsics = {'component' => :library, 'http.method' => :procedure, + 'http.request.method' => :procedure, 'http.statusCode' => :http_status_code, 'category' => 'http', - 'span.kind' => 'client'} + 'span.kind' => 'client', + 'server.address' => 'newrelic.com', + 'server.port' => 443} expected_custom_attrs = {} - expected_agent_attrs = {'http.url' => 'uri'} + expected_agent_attrs = {'http.url' => uri_for_testing.to_s} assert_equal [expected_intrinsics, expected_custom_attrs, expected_agent_attrs], result end @@ -353,18 +360,24 @@ def test_agent_attributes_are_included_for_external_segments_when_enabled_on_a_p segment = MiniTest::Mock.new segment.expect(:library, :library) segment.expect(:procedure, :procedure) + segment.expect(:procedure, :procedure) # 2 calls segment.expect(:http_status_code, :http_status_code) segment.expect(:http_status_code, :http_status_code) # 2 calls - segment.expect(:uri, :uri) + segment.expect(:uri, uri_for_testing) + segment.expect(:uri, uri_for_testing) + segment.expect(:uri, uri_for_testing) # 3 calls segment.expect(:record_agent_attributes?, true) result = SpanEventPrimitive.for_external_request_segment(segment) expected_intrinsics = {'component' => :library, 'http.method' => :procedure, + 'http.request.method' => :procedure, 'http.statusCode' => :http_status_code, 'category' => 'http', - 'span.kind' => 'client'} + 'span.kind' => 'client', + 'server.address' => 'newrelic.com', + 'server.port' => 443} expected_custom_attrs = {} - expected_agent_attrs = {'http.url' => 'uri'}.merge(existing_agent_attributes) + expected_agent_attrs = {'http.url' => uri_for_testing.to_s}.merge(existing_agent_attributes) assert_equal [expected_intrinsics, expected_custom_attrs, expected_agent_attrs], result end @@ -372,6 +385,12 @@ def test_agent_attributes_are_included_for_external_segments_when_enabled_on_a_p end end end + + private + + def uri_for_testing + URI.parse('https://newrelic.com') + end end end end