Skip to content

Commit

Permalink
update span event primitive tests for PR 2284
Browse files Browse the repository at this point in the history
PR #2284 added 3 new attributes that need to be included in the tests
  • Loading branch information
fallwith committed Oct 23, 2023
1 parent 44234cb commit 62bcaec
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions test/new_relic/agent/span_event_primitive_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -353,25 +360,37 @@ 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
end
end
end
end

private

def uri_for_testing
URI.parse('https://newrelic.com')
end
end
end
end
Expand Down

0 comments on commit 62bcaec

Please sign in to comment.