opentelemetry-instrumentation-redis 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f308b21893c76a482cbed3e42ce6f72b6a5c435aedabdee8a3d5f886f289273
4
- data.tar.gz: 79fc2ad085205197ca11e452bf2f7c240fa939a6bb77287eb076e1b66c7b084f
3
+ metadata.gz: b97d1d7565c42c6b2a1c5a3d351c1b289c958de50295fdc5b75bcb04dd08e90f
4
+ data.tar.gz: '0901c065c1a7cb6bd7412ea275a836b6575e2ae52096047822cc980963c187e0'
5
5
  SHA512:
6
- metadata.gz: 3b90442147ac86fa19c49c2bb7a60f3c3a6b67fce95abd2d31ac5a29e729d51d0eb43c583066be34b0eff5c1878f8af69fef2309a487c7a34cb0f107a93566de
7
- data.tar.gz: d9389b133663fae2be0460663a7dac48dc69ed5d4162409524aa8e74d7a645bd4263623e8e879250ce8ba72792e186324250f41e2903612581660bf6c991ebe2
6
+ metadata.gz: d068fef46b939f32433777e0d2a361f8108eae305c9c019817efc67ecb86b4d147591200b6fe6699e801b1c2d3884a34c3c07f2c1816f1948e7008b60d79bbac
7
+ data.tar.gz: e15af756ab9191474be4ba2b5783158288553ca34a6563a518159825f165663bbc13260901b2bdf58abac84712db8b922bb739f6bd2712d4dc740c2634dc964f
data/CHANGELOG.md CHANGED
@@ -1,18 +1,27 @@
1
1
  # Release History: opentelemetry-instrumentation-redis
2
2
 
3
+ ### v0.18.0 / 2021-05-21
4
+
5
+ * ADDED: Updated API depedency for 1.0.0.rc1
6
+ refactor: redis attribute utils [#760](https://github.com/open-telemetry/opentelemetry-ruby/pull/760)
7
+ refactor: simplify redis attribute assignment [#758](https://github.com/open-telemetry/opentelemetry-ruby/pull/758)
8
+ test: split redis instrumentation test [#754](https://github.com/open-telemetry/opentelemetry-ruby/pull/754)
9
+ * ADDED: Option to obfuscate redis arguments
10
+ * FIXED: Instrument Redis more thoroughly by patching Client#process.
11
+
3
12
  ### v0.17.0 / 2021-04-22
4
13
 
5
14
  * (No significant changes)
6
15
 
7
16
  ### v0.16.0 / 2021-03-17
8
17
 
9
- * FIXED: Update DB semantic conventions
10
- * FIXED: Example scripts now reference local common lib
11
- * DOCS: Replace Gitter with GitHub Discussions
18
+ * FIXED: Update DB semantic conventions
19
+ * FIXED: Example scripts now reference local common lib
20
+ * DOCS: Replace Gitter with GitHub Discussions
12
21
 
13
22
  ### v0.15.0 / 2021-02-18
14
23
 
15
- * ADDED: Add instrumentation config validation
24
+ * ADDED: Add instrumentation config validation
16
25
 
17
26
  ### v0.14.0 / 2021-02-03
18
27
 
@@ -28,13 +37,13 @@
28
37
 
29
38
  ### v0.11.0 / 2020-12-11
30
39
 
31
- * ADDED: Accept config for redis peer service attribute
32
- * ADDED: Move utf8 encoding to common utils
33
- * FIXED: Copyright comments to not reference year
40
+ * ADDED: Accept config for redis peer service attribute
41
+ * ADDED: Move utf8 encoding to common utils
42
+ * FIXED: Copyright comments to not reference year
34
43
 
35
44
  ### v0.10.1 / 2020-12-09
36
45
 
37
- * FIXED: Semantic conventions db.type -> db.system
46
+ * FIXED: Semantic conventions db.type -> db.system
38
47
 
39
48
  ### v0.10.0 / 2020-12-03
40
49
 
@@ -42,21 +51,21 @@
42
51
 
43
52
  ### v0.9.0 / 2020-11-27
44
53
 
45
- * BREAKING CHANGE: Add timeout for force_flush and shutdown
54
+ * BREAKING CHANGE: Add timeout for force_flush and shutdown
46
55
 
47
- * ADDED: Redis attribute propagation
48
- * ADDED: Add timeout for force_flush and shutdown
56
+ * ADDED: Redis attribute propagation
57
+ * ADDED: Add timeout for force_flush and shutdown
49
58
 
50
59
  ### v0.8.0 / 2020-10-27
51
60
 
52
- * BREAKING CHANGE: Remove 'canonical' from status codes
61
+ * BREAKING CHANGE: Remove 'canonical' from status codes
53
62
 
54
- * FIXED: Remove 'canonical' from status codes
63
+ * FIXED: Remove 'canonical' from status codes
55
64
 
56
65
  ### v0.7.0 / 2020-10-07
57
66
 
58
- * DOCS: Added redis documentation
59
- * DOCS: Standardize toplevel docs structure and readme
67
+ * DOCS: Added redis documentation
68
+ * DOCS: Standardize toplevel docs structure and readme
60
69
 
61
70
  ### v0.6.0 / 2020-09-10
62
71
 
data/README.md CHANGED
@@ -41,6 +41,18 @@ OpenTelemetry::Instrumentation::Redis.with_attributes('peer.service' => 'cache')
41
41
  end
42
42
  ```
43
43
 
44
+ ### Configuration options
45
+
46
+ ```ruby
47
+ OpenTelemetry::SDK.configure do |c|
48
+ c.use 'OpenTelemetry::Instrumentation::Redis', {
49
+ # The obfuscation of arguments in the db.statement attribute is enabled by default.
50
+ # To disable, set enable_statement_obfuscation to false.
51
+ enable_statement_obfuscation: true,
52
+ }
53
+ end
54
+ ```
55
+
44
56
  ## Example
45
57
 
46
58
  An example of usage can be seen in [`example/redis.rb`](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/instrumentation/redis/example/redis.rb).
@@ -48,11 +60,7 @@ An example of usage can be seen in [`example/redis.rb`](https://github.com/open-
48
60
  ## Development
49
61
 
50
62
  You'll need Redis installed locally to run the test suite. Once you've
51
- installed it, start it with the included configuration:
52
-
53
- ```
54
- redis-server test/redis.conf
55
- ```
63
+ installed it, it will start and stop automatically when you run `rake`.
56
64
 
57
65
  ## How can I get involved?
58
66
 
@@ -20,11 +20,11 @@ module OpenTelemetry
20
20
  end
21
21
 
22
22
  option :peer_service, default: nil, validate: :string
23
+ option :enable_statement_obfuscation, default: true, validate: :boolean
23
24
 
24
25
  private
25
26
 
26
27
  def require_dependencies
27
- require_relative 'utils'
28
28
  require_relative 'patches/client'
29
29
  end
30
30
 
@@ -10,41 +10,10 @@ module OpenTelemetry
10
10
  module Patches
11
11
  # Module to prepend to Redis::Client for instrumentation
12
12
  module Client
13
- def call(*args, &block)
14
- response = nil
13
+ MAX_STATEMENT_LENGTH = 500
14
+ private_constant :MAX_STATEMENT_LENGTH
15
15
 
16
- attributes = client_attributes
17
- attributes['db.statement'] = Utils.format_statement(args)
18
- tracer.in_span(
19
- Utils.format_command(args),
20
- attributes: attributes,
21
- kind: :client
22
- ) do
23
- response = super(*args, &block)
24
- end
25
-
26
- response
27
- end
28
-
29
- def call_pipeline(*args, &block)
30
- response = nil
31
-
32
- attributes = client_attributes
33
- attributes['db.statement'] = Utils.format_pipeline_statement(args)
34
- tracer.in_span(
35
- 'pipeline',
36
- attributes: attributes,
37
- kind: :client
38
- ) do
39
- response = super(*args, &block)
40
- end
41
-
42
- response
43
- end
44
-
45
- private
46
-
47
- def client_attributes
16
+ def process(commands) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
48
17
  host = options[:host]
49
18
  port = options[:port]
50
19
 
@@ -53,9 +22,61 @@ module OpenTelemetry
53
22
  'net.peer.name' => host,
54
23
  'net.peer.port' => port
55
24
  }
25
+
56
26
  attributes['db.redis.database_index'] = options[:db] unless options[:db].zero?
57
27
  attributes['peer.service'] = config[:peer_service] if config[:peer_service]
58
- attributes.merge(OpenTelemetry::Instrumentation::Redis.attributes)
28
+ attributes.merge!(OpenTelemetry::Instrumentation::Redis.attributes)
29
+
30
+ parsed_commands = parse_commands(commands)
31
+ parsed_commands = OpenTelemetry::Common::Utilities.truncate(parsed_commands, MAX_STATEMENT_LENGTH)
32
+ parsed_commands = OpenTelemetry::Common::Utilities.utf8_encode(parsed_commands, binary: true)
33
+ attributes['db.statement'] = parsed_commands
34
+
35
+ span_name = if commands.length == 1
36
+ commands[0][0].to_s.upcase
37
+ else
38
+ 'PIPELINED'
39
+ end
40
+
41
+ tracer.in_span(span_name, attributes: attributes, kind: :client) do |s|
42
+ super(commands).tap do |reply|
43
+ if reply.is_a?(::Redis::CommandError)
44
+ s.record_exception(reply)
45
+ s.status = Trace::Status.new(
46
+ Trace::Status::ERROR,
47
+ description: reply.message
48
+ )
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ # Examples of commands received for parsing
57
+ # Redis#queue [[[:set, "v1", "0"]], [[:incr, "v1"]], [[:get, "v1"]]]
58
+ # Redis#pipeline: [[:set, "v1", "0"], [:incr, "v1"], [:get, "v1"]]
59
+ # Redis#hmset [[:hmset, "hash", "f1", 1234567890.0987654]]
60
+ # Redis#set [[:set, "K", "x"]]
61
+ def parse_commands(commands) # rubocop:disable Metrics/AbcSize
62
+ commands.map do |command|
63
+ # We are checking for the use of Redis#queue command, if we detect the
64
+ # extra level of array nesting we return the first element so it
65
+ # can be parsed.
66
+ command = command[0] if command.is_a?(Array) && command[0].is_a?(Array)
67
+
68
+ # If we receive an authentication request command
69
+ # we want to short circuit parsing the commands
70
+ # and return the obfuscated command
71
+ return 'AUTH ?' if command[0] == :auth
72
+
73
+ command[0] = command[0].to_s.upcase
74
+ if config[:enable_statement_obfuscation]
75
+ command[0] + ' ?' * (command.size - 1)
76
+ else
77
+ command.join(' ')
78
+ end
79
+ end.join("\n")
59
80
  end
60
81
 
61
82
  def tracer
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module Redis
10
- VERSION = '0.17.0'
10
+ VERSION = '0.18.0'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-23 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.17.0
19
+ version: 1.0.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.17.0
26
+ version: 1.0.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opentelemetry-common
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.17.0
33
+ version: 0.18.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.17.0
40
+ version: 0.18.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: opentelemetry-instrumentation-base
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.17.0
47
+ version: 0.18.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.17.0
54
+ version: 0.18.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: appraisal
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.0'
103
+ version: 1.0.0.rc1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.0'
110
+ version: 1.0.0.rc1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: redis
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -194,16 +194,15 @@ files:
194
194
  - lib/opentelemetry/instrumentation/redis.rb
195
195
  - lib/opentelemetry/instrumentation/redis/instrumentation.rb
196
196
  - lib/opentelemetry/instrumentation/redis/patches/client.rb
197
- - lib/opentelemetry/instrumentation/redis/utils.rb
198
197
  - lib/opentelemetry/instrumentation/redis/version.rb
199
198
  homepage: https://github.com/open-telemetry/opentelemetry-ruby
200
199
  licenses:
201
200
  - Apache-2.0
202
201
  metadata:
203
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-redis/v0.17.0/file.CHANGELOG.html
202
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-redis/v0.18.0/file.CHANGELOG.html
204
203
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/redis
205
204
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
206
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-redis/v0.17.0
205
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-redis/v0.18.0
207
206
  post_install_message:
208
207
  rdoc_options: []
209
208
  require_paths:
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- module OpenTelemetry
8
- module Instrumentation
9
- module Redis
10
- # Utility functions
11
- module Utils
12
- extend self
13
-
14
- PLACEHOLDER = '?'
15
- VALUE_MAX_LEN = 50
16
- CMD_MAX_LEN = 500
17
-
18
- def format_command(command_args)
19
- format_arg(resolve_command_args(command_args).first)
20
- end
21
-
22
- def format_pipeline_statement(command_args)
23
- command_args[0].commands.map do |args|
24
- format_statement(args)
25
- end.join("\n")
26
- end
27
-
28
- def format_statement(command_args)
29
- command_args = resolve_command_args(command_args)
30
- return 'AUTH ?' if auth_command?(command_args)
31
-
32
- cmd = command_args.map { |x| format_arg(x) }.join(' ')
33
- OpenTelemetry::Common::Utilities.truncate(cmd, CMD_MAX_LEN)
34
- end
35
-
36
- def format_arg(arg)
37
- str = arg.is_a?(Symbol) ? arg.to_s.upcase : arg.to_s
38
- str = OpenTelemetry::Common::Utilities.utf8_encode(str, binary: true)
39
- OpenTelemetry::Common::Utilities.truncate(str, VALUE_MAX_LEN)
40
- rescue StandardError => e
41
- OpenTelemetry.logger.debug("non formattable Redis arg #{str}: #{e}")
42
- PLACEHOLDER
43
- end
44
-
45
- def auth_command?(command_args)
46
- return false unless command_args.is_a?(Array) && !command_args.empty?
47
-
48
- command_args.first.to_sym == :auth
49
- end
50
-
51
- # Unwraps command array when Redis is called with the following syntax:
52
- # redis.call([:cmd, 'arg1', ...])
53
- def resolve_command_args(command_args)
54
- return command_args.first if command_args.is_a?(Array) && command_args.first.is_a?(Array)
55
-
56
- command_args
57
- end
58
- end
59
- end
60
- end
61
- end