Skip to content

Commit de4da24

Browse files
authored
fix: Do not pollute the OpenTelemetry::Instrumentation namespace (#1511)
Do not pollute the `OpenTelemetry::Instrumentation` namespace The `dalli` instrumentation is defining a `Utils` module under the `OpenTelemetry::Instrumentation`. The `Utils` module should be an internal concern of the instrumentation library, and thus, the module should've been under the `OpenTelemetry::Instrumentation::Dalli` namespace.
1 parent f8d2551 commit de4da24

File tree

1 file changed

+59
-57
lines changed
  • instrumentation/dalli/lib/opentelemetry/instrumentation/dalli

1 file changed

+59
-57
lines changed

instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/utils.rb

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,72 @@
66

77
module OpenTelemetry
88
module Instrumentation
9-
# Utility functions
10-
module Utils
11-
extend self
9+
module Dalli
10+
# Utility functions
11+
module Utils
12+
extend self
1213

13-
STRING_PLACEHOLDER = ''.encode(::Encoding::UTF_8).freeze
14-
CMD_MAX_LEN = 500
14+
STRING_PLACEHOLDER = ''.encode(::Encoding::UTF_8).freeze
15+
CMD_MAX_LEN = 500
1516

16-
OPNAME_MAPPING = {
17-
'get' => 'get',
18-
'cas' => 'get',
19-
'set' => 'set',
20-
'add' => 'add',
21-
'replace' => 'replace',
22-
'delete' => 'delete',
23-
'incr' => 'incr',
24-
'decr' => 'decr',
25-
'flush' => 'flush',
26-
'write_noop' => 'noop',
27-
'version' => 'version',
28-
'send_multiget' => 'getkq',
29-
# TODO: add better support for PipelinedGetter
30-
# In dalli 3.1, multiget has been refactored to use a more robust PipelinedGetter class.
31-
# The `pipelined_get` method has been introduced to the Dalli::Server to support this new class.
32-
# If PipelinedGetter makes instrumentation of multi operations easier, we should then migrate
33-
# instrumentation to Dalli::Client, since it seems to be a more stable chokepoint.
34-
# For now we're just ensuring we support this new Dalli::Server method.
35-
'pipelined_get' => 'getkq',
36-
'append' => 'append',
37-
'prepend' => 'prepend',
38-
'stats' => 'stat',
39-
'reset_stats' => 'stat',
40-
'multi_set' => 'setq',
41-
'multi_add' => 'addq',
42-
'multi_replace' => 'replaceq',
43-
'multi_delete' => 'deleteq',
44-
'touch' => 'touch',
45-
'gat' => 'gat'
46-
# 'sasl_authentication' => 'auth_negotiation',
47-
# 'sasl_authentication' => 'auth_request',
48-
}.freeze
17+
OPNAME_MAPPING = {
18+
'get' => 'get',
19+
'cas' => 'get',
20+
'set' => 'set',
21+
'add' => 'add',
22+
'replace' => 'replace',
23+
'delete' => 'delete',
24+
'incr' => 'incr',
25+
'decr' => 'decr',
26+
'flush' => 'flush',
27+
'write_noop' => 'noop',
28+
'version' => 'version',
29+
'send_multiget' => 'getkq',
30+
# TODO: add better support for PipelinedGetter
31+
# In dalli 3.1, multiget has been refactored to use a more robust PipelinedGetter class.
32+
# The `pipelined_get` method has been introduced to the Dalli::Server to support this new class.
33+
# If PipelinedGetter makes instrumentation of multi operations easier, we should then migrate
34+
# instrumentation to Dalli::Client, since it seems to be a more stable chokepoint.
35+
# For now we're just ensuring we support this new Dalli::Server method.
36+
'pipelined_get' => 'getkq',
37+
'append' => 'append',
38+
'prepend' => 'prepend',
39+
'stats' => 'stat',
40+
'reset_stats' => 'stat',
41+
'multi_set' => 'setq',
42+
'multi_add' => 'addq',
43+
'multi_replace' => 'replaceq',
44+
'multi_delete' => 'deleteq',
45+
'touch' => 'touch',
46+
'gat' => 'gat'
47+
# 'sasl_authentication' => 'auth_negotiation',
48+
# 'sasl_authentication' => 'auth_request',
49+
}.freeze
4950

50-
def opname(operation, multi)
51-
lookup_name = multi ? "multi_#{operation}" : operation.to_s
52-
OPNAME_MAPPING[lookup_name] || operation.to_s
53-
end
51+
def opname(operation, multi)
52+
lookup_name = multi ? "multi_#{operation}" : operation.to_s
53+
OPNAME_MAPPING[lookup_name] || operation.to_s
54+
end
5455

55-
def format_command(operation, args)
56-
placeholder = "#{operation} BLOB (OMITTED)"
56+
def format_command(operation, args)
57+
placeholder = "#{operation} BLOB (OMITTED)"
5758

58-
command = +operation.to_s
59-
args.flatten.each do |arg|
60-
str = arg.to_s
61-
if str.bytesize >= CMD_MAX_LEN
62-
command << ' BLOB (OMITTED)'
63-
elsif !str.empty?
64-
command << ' ' << str
59+
command = +operation.to_s
60+
args.flatten.each do |arg|
61+
str = arg.to_s
62+
if str.bytesize >= CMD_MAX_LEN
63+
command << ' BLOB (OMITTED)'
64+
elsif !str.empty?
65+
command << ' ' << str
66+
end
6567
end
66-
end
6768

68-
command = OpenTelemetry::Common::Utilities.utf8_encode(command, binary: true, placeholder: placeholder)
69-
OpenTelemetry::Common::Utilities.truncate(command, CMD_MAX_LEN)
70-
rescue StandardError => e
71-
OpenTelemetry.logger.debug("Error sanitizing Dalli operation: #{e}")
72-
placeholder
69+
command = OpenTelemetry::Common::Utilities.utf8_encode(command, binary: true, placeholder: placeholder)
70+
OpenTelemetry::Common::Utilities.truncate(command, CMD_MAX_LEN)
71+
rescue StandardError => e
72+
OpenTelemetry.logger.debug("Error sanitizing Dalli operation: #{e}")
73+
placeholder
74+
end
7375
end
7476
end
7577
end

0 commit comments

Comments
 (0)