Skip to content

Commit f754c80

Browse files
committed
Set hostname for logs using config
The default value of 'process_host.display_name' is the same as NewRelic::Agent::Hostname.get, so this change will only impact users who have set a unique value on the config. Resolves #1696
1 parent efc9b6a commit f754c80

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010

1111
Sidekiq delay extensions were removed from Sidekiq in 7.x and are now avaliable through the [sidekiq-delay_extensions](https://rubygems.org/gems/sidekiq-delay_extensions) gem. Thanks to [@sobrinho](https://github.com/sobrinho), the agent now has continued support for delay extensions.[PR#3056](https://github.com/newrelic/newrelic-ruby-agent/pull/3056)
1212

13+
- **Feature: Use process_host.display_name configuration to set Hostname attribute on logs and other linking metadata**
14+
15+
Previously, the hostname was assigned by the `NewRelic::Agent::Hostname.get` API. This API is the default value of `process_host.display_name`. Now, user-configured values for the host name will be applied. Thank you [@flivni](https://github.com/flivni) for bringing this to our attention! [Issue#1696](https://github.com/newrelic/newrelic-ruby-agent/issues/1696) [PR#](https://github.com/newrelic/newrelic-ruby-agent/pulls)
16+
1317
- **Bugfix: Prevent a nil segment from causing errors in Net::HTTP instrumentation**
1418

1519
When using JRuby, a race condition can happen that causes the segment creation to fail and return `nil`. This would cause an error to occur when methods were later called on the `nil` segment. These methods will no longer be called if the segment is `nil`, preventing that error from occurring. [PR#3046](https://github.com/newrelic/newrelic-ruby-agent/pull/3046)
1620

1721
- **Bugfix: JRuby multithreading improvements**
18-
22+
1923
Added some additional nil checks and mutexes to prevent issues when using the agent on JRuby with multiple threads. Thanks to @NC-piercej for bringing this to our attention [Issue#3021](https://github.com/newrelic/newrelic-ruby-agent/issues/3021) [PR#3053](https://github.com/newrelic/newrelic-ruby-agent/pull/3053)
2024

2125
- **Bugfix: Stop reporting rescued Sidekiq::OverLimit exceptions**

lib/new_relic/agent/linking_metadata.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def append_service_linking_metadata(metadata)
1717

1818
metadata[ENTITY_NAME_KEY] = config[:app_name][0]
1919
metadata[ENTITY_TYPE_KEY] = ENTITY_TYPE
20-
metadata[HOSTNAME_KEY] = Hostname.get
20+
metadata[HOSTNAME_KEY] = NewRelic::Agent.config[:'process_host.display_name']
2121

2222
if entity_guid = config[:entity_guid]
2323
metadata[ENTITY_GUID_KEY] = entity_guid

lib/new_relic/agent/logging.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def add_entity_type(message)
8181
end
8282

8383
def add_hostname(message)
84-
add_key_value(message, HOSTNAME_KEY, Hostname.get)
84+
add_key_value(message, HOSTNAME_KEY, NewRelic::Agent.config[:'process_host.display_name'])
8585
end
8686

8787
def add_entity_guid(message)

test/new_relic/agent/linking_metadata_test.rb

+10
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ def test_trace_metadata_with_ids
9090
assert_equal(expected, result)
9191
end
9292

93+
def test_uses_process_host_display_name_as_hostname
94+
with_config(:'process_host.display_name' => 'crossword-oreo-panda') do
95+
result = Hash.new
96+
LinkingMetadata.append_service_linking_metadata(result)
97+
98+
refute_equal(('crossword-oreo-panda'), Hostname.get)
99+
assert_equal('crossword-oreo-panda', result['hostname'])
100+
end
101+
end
102+
93103
def apply_config(config)
94104
@config = config
95105
NewRelic::Agent.config.add_config_for_testing(@config)

test/new_relic/agent/logging_test.rb

+11
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ def test_constructor_arguments_formatter
142142

143143
refute_equal formatter, logger.formatter
144144
end
145+
146+
def test_hostname_is_same_as_process_host_display_name_config
147+
logger = DecoratingLogger.new(@output)
148+
149+
with_config(:'process_host.display_name' => 'soothing-caramel-bedtime') do
150+
logger.info('one')
151+
152+
refute_equal 'soothing-caramel-bedtime', Hostname.get
153+
assert_equal 'soothing-caramel-bedtime', last_message['hostname']
154+
end
155+
end
145156
end
146157
end
147158
end

0 commit comments

Comments
 (0)