|
6 | 6 |
|
7 | 7 | module OpenTelemetry |
8 | 8 | module Instrumentation |
9 | | - # Utility functions |
10 | | - module Utils |
11 | | - extend self |
| 9 | + module Dalli |
| 10 | + # Utility functions |
| 11 | + module Utils |
| 12 | + extend self |
12 | 13 |
|
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 |
15 | 16 |
|
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 |
49 | 50 |
|
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 |
54 | 55 |
|
55 | | - def format_command(operation, args) |
56 | | - placeholder = "#{operation} BLOB (OMITTED)" |
| 56 | + def format_command(operation, args) |
| 57 | + placeholder = "#{operation} BLOB (OMITTED)" |
57 | 58 |
|
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 |
65 | 67 | end |
66 | | - end |
67 | 68 |
|
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 |
73 | 75 | end |
74 | 76 | end |
75 | 77 | end |
|
0 commit comments