Skip to content

Commit 4dbb668

Browse files
authored
fix: compact Dalli attributes (#1548)
1 parent 76b1c7f commit 4dbb668

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/patches/server.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ def request(op, *args) # rubocop:disable Naming/MethodParameterName
1515
attributes = {
1616
'db.system' => 'memcached',
1717
'db.operation' => operation,
18-
'net.peer.name' => hostname,
19-
'net.peer.port' => port
18+
'net.peer.name' => hostname
2019
}
20+
attributes['net.peer.port'] = port if port
21+
2122
if config[:db_statement] == :include
2223
attributes['db.statement'] = Utils.format_command(operation, args)
2324
elsif config[:db_statement] == :obfuscate

instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@
142142
_(span.name).must_equal 'gat'
143143
_(span.attributes['db.statement']).must_equal 'gat foo 0'
144144
end
145+
146+
it 'supports unix domain socket' do
147+
dalli.version
148+
exporter.reset
149+
150+
server = dalli.instance_variable_get(:@ring).servers.first
151+
server.stub(:hostname, '/tmp/memcached.sock') do
152+
server.stub(:port, nil) do
153+
dalli.set('foo', 'bar')
154+
155+
puts exporter.finished_spans
156+
_(exporter.finished_spans.size).must_equal 1
157+
_(span.name).must_equal 'set'
158+
_(span.attributes).wont_include 'net.peer.port'
159+
_(span.attributes['net.peer.name']).must_equal '/tmp/memcached.sock'
160+
end
161+
end
162+
end
145163
end
146164
end
147165

0 commit comments

Comments
 (0)