opentelemetry-instrumentation-redis 0.17.0 → 0.21.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: 623d653fb0f83f2c6587fab77efa962491d5eb034cd4e8c98dda39b572d1a613
4
+ data.tar.gz: 74e7a1a810ad625768eec316a4b16ec8ece8ae4a93b3c3cc1b16da135d3c6bc8
5
5
  SHA512:
6
- metadata.gz: 3b90442147ac86fa19c49c2bb7a60f3c3a6b67fce95abd2d31ac5a29e729d51d0eb43c583066be34b0eff5c1878f8af69fef2309a487c7a34cb0f107a93566de
7
- data.tar.gz: d9389b133663fae2be0460663a7dac48dc69ed5d4162409524aa8e74d7a645bd4263623e8e879250ce8ba72792e186324250f41e2903612581660bf6c991ebe2
6
+ metadata.gz: 601147ca939a22bf4654dfba53675f56800ddf0ca3cc995e9321843e5738200e775c3dc9ac3f49cb9d2b0c62728ddc391b3f12d80ec46a4689d8a6ba22793f20
7
+ data.tar.gz: 5bb1f8966cecfce7d81a1c8124545394df58c720b5a4730dad944cca488a9e53336be896490137151a812fbb2f555c3125d61ba21001c789ed52a18e15595d6f
data/CHANGELOG.md CHANGED
@@ -1,18 +1,41 @@
1
1
  # Release History: opentelemetry-instrumentation-redis
2
2
 
3
+ ### v0.21.0 / 2021-08-12
4
+
5
+ * ADDED: Add toggle for redis db.statement attribute
6
+
7
+ ### v0.20.0 / 2021-06-23
8
+
9
+ * BREAKING CHANGE: Total order constraint on span.status=
10
+
11
+ * FIXED: Total order constraint on span.status=
12
+
13
+ ### v0.19.0 / 2021-05-28
14
+
15
+ * ADDED: Configuration option to enable or disable redis root spans [#777](https://github.com/open-telemetry/opentelemetry-ruby/pull/777)
16
+
17
+ ### v0.18.0 / 2021-05-21
18
+
19
+ * ADDED: Updated API depedency for 1.0.0.rc1
20
+ refactor: redis attribute utils [#760](https://github.com/open-telemetry/opentelemetry-ruby/pull/760)
21
+ refactor: simplify redis attribute assignment [#758](https://github.com/open-telemetry/opentelemetry-ruby/pull/758)
22
+ test: split redis instrumentation test [#754](https://github.com/open-telemetry/opentelemetry-ruby/pull/754)
23
+ * ADDED: Option to obfuscate redis arguments
24
+ * FIXED: Instrument Redis more thoroughly by patching Client#process.
25
+
3
26
  ### v0.17.0 / 2021-04-22
4
27
 
5
28
  * (No significant changes)
6
29
 
7
30
  ### v0.16.0 / 2021-03-17
8
31
 
9
- * FIXED: Update DB semantic conventions
10
- * FIXED: Example scripts now reference local common lib
11
- * DOCS: Replace Gitter with GitHub Discussions
32
+ * FIXED: Update DB semantic conventions
33
+ * FIXED: Example scripts now reference local common lib
34
+ * DOCS: Replace Gitter with GitHub Discussions
12
35
 
13
36
  ### v0.15.0 / 2021-02-18
14
37
 
15
- * ADDED: Add instrumentation config validation
38
+ * ADDED: Add instrumentation config validation
16
39
 
17
40
  ### v0.14.0 / 2021-02-03
18
41
 
@@ -28,13 +51,13 @@
28
51
 
29
52
  ### v0.11.0 / 2020-12-11
30
53
 
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
54
+ * ADDED: Accept config for redis peer service attribute
55
+ * ADDED: Move utf8 encoding to common utils
56
+ * FIXED: Copyright comments to not reference year
34
57
 
35
58
  ### v0.10.1 / 2020-12-09
36
59
 
37
- * FIXED: Semantic conventions db.type -> db.system
60
+ * FIXED: Semantic conventions db.type -> db.system
38
61
 
39
62
  ### v0.10.0 / 2020-12-03
40
63
 
@@ -42,21 +65,21 @@
42
65
 
43
66
  ### v0.9.0 / 2020-11-27
44
67
 
45
- * BREAKING CHANGE: Add timeout for force_flush and shutdown
68
+ * BREAKING CHANGE: Add timeout for force_flush and shutdown
46
69
 
47
- * ADDED: Redis attribute propagation
48
- * ADDED: Add timeout for force_flush and shutdown
70
+ * ADDED: Redis attribute propagation
71
+ * ADDED: Add timeout for force_flush and shutdown
49
72
 
50
73
  ### v0.8.0 / 2020-10-27
51
74
 
52
- * BREAKING CHANGE: Remove 'canonical' from status codes
75
+ * BREAKING CHANGE: Remove 'canonical' from status codes
53
76
 
54
- * FIXED: Remove 'canonical' from status codes
77
+ * FIXED: Remove 'canonical' from status codes
55
78
 
56
79
  ### v0.7.0 / 2020-10-07
57
80
 
58
- * DOCS: Added redis documentation
59
- * DOCS: Standardize toplevel docs structure and readme
81
+ * DOCS: Added redis documentation
82
+ * DOCS: Standardize toplevel docs structure and readme
60
83
 
61
84
  ### v0.6.0 / 2020-09-10
62
85
 
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
 
@@ -19,12 +19,13 @@ module OpenTelemetry
19
19
  defined?(::Redis)
20
20
  end
21
21
 
22
- option :peer_service, default: nil, validate: :string
22
+ option :peer_service, default: nil, validate: :string
23
+ option :trace_root_spans, default: true, validate: :boolean
24
+ option :db_statement, default: :obfuscate, validate: ->(opt) { %I[omit include obfuscate].include?(opt) }
23
25
 
24
26
  private
25
27
 
26
28
  def require_dependencies
27
- require_relative 'utils'
28
29
  require_relative 'patches/client'
29
30
  end
30
31
 
@@ -10,41 +10,12 @@ 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
16
+ def process(commands) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
17
+ return super unless config[:trace_root_spans] || OpenTelemetry::Trace.current_span.context.valid?
41
18
 
42
- response
43
- end
44
-
45
- private
46
-
47
- def client_attributes
48
19
  host = options[:host]
49
20
  port = options[:port]
50
21
 
@@ -53,9 +24,60 @@ module OpenTelemetry
53
24
  'net.peer.name' => host,
54
25
  'net.peer.port' => port
55
26
  }
27
+
56
28
  attributes['db.redis.database_index'] = options[:db] unless options[:db].zero?
57
29
  attributes['peer.service'] = config[:peer_service] if config[:peer_service]
58
- attributes.merge(OpenTelemetry::Instrumentation::Redis.attributes)
30
+ attributes.merge!(OpenTelemetry::Instrumentation::Redis.attributes)
31
+
32
+ unless config[:db_statement] == :omit
33
+ parsed_commands = parse_commands(commands)
34
+ parsed_commands = OpenTelemetry::Common::Utilities.truncate(parsed_commands, MAX_STATEMENT_LENGTH)
35
+ parsed_commands = OpenTelemetry::Common::Utilities.utf8_encode(parsed_commands, binary: true)
36
+ attributes['db.statement'] = parsed_commands
37
+ end
38
+
39
+ span_name = if commands.length == 1
40
+ commands[0][0].to_s.upcase
41
+ else
42
+ 'PIPELINED'
43
+ end
44
+
45
+ tracer.in_span(span_name, attributes: attributes, kind: :client) do |s|
46
+ super(commands).tap do |reply|
47
+ if reply.is_a?(::Redis::CommandError)
48
+ s.record_exception(reply)
49
+ s.status = Trace::Status.error(reply.message)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ # Examples of commands received for parsing
58
+ # Redis#queue [[[:set, "v1", "0"]], [[:incr, "v1"]], [[:get, "v1"]]]
59
+ # Redis#pipeline: [[:set, "v1", "0"], [:incr, "v1"], [:get, "v1"]]
60
+ # Redis#hmset [[:hmset, "hash", "f1", 1234567890.0987654]]
61
+ # Redis#set [[:set, "K", "x"]]
62
+ def parse_commands(commands) # rubocop:disable Metrics/AbcSize
63
+ commands.map do |command|
64
+ # We are checking for the use of Redis#queue command, if we detect the
65
+ # extra level of array nesting we return the first element so it
66
+ # can be parsed.
67
+ command = command[0] if command.is_a?(Array) && command[0].is_a?(Array)
68
+
69
+ # If we receive an authentication request command
70
+ # we want to short circuit parsing the commands
71
+ # and return the obfuscated command
72
+ return 'AUTH ?' if command[0] == :auth
73
+
74
+ command[0] = command[0].to_s.upcase
75
+ if config[:db_statement] == :obfuscate
76
+ command[0] + ' ?' * (command.size - 1)
77
+ else
78
+ command.join(' ')
79
+ end
80
+ end.join("\n")
59
81
  end
60
82
 
61
83
  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.21.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.21.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-08-16 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.rc3
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.rc3
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.19.1
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.19.1
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.2
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.2
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.21.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.21.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