opentelemetry-instrumentation-redis 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/lib/opentelemetry/instrumentation/redis/instrumentation.rb +5 -3
- data/lib/opentelemetry/instrumentation/redis/middlewares/redis_client.rb +80 -0
- data/lib/opentelemetry/instrumentation/redis/patches/{client.rb → redis_v4_client.rb} +10 -10
- data/lib/opentelemetry/instrumentation/redis/version.rb +1 -1
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a27919563509bb9c0d19f5bc59e1d8ead18713a166791473b8bbd6ff5f3ca78a
|
4
|
+
data.tar.gz: 2649f5632d81c557b9a0cd8ad6431650c11d9b91ff705cb1eb3419407384e422
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a7aa1b2145bd567b87fa1cc6d51ac12d2accc52d05e58dc17a8cfe9f6225cd28c80ba4d1e8facc3f2991fe78f0b6835f26d152437e0d02db86e3e96f39750b7
|
7
|
+
data.tar.gz: 96c048eaa579ca59c1010950a36119e80695401218721ca95179d2dca7ba399a9c1bec16e68b4e22a152f433c12d053082fd601ff57c48702b0d4941fb7089b9
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -57,7 +57,7 @@ end
|
|
57
57
|
|
58
58
|
## Example
|
59
59
|
|
60
|
-
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).
|
60
|
+
An example of usage can be seen in [`example/redis.rb`](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/redis/example/redis.rb).
|
61
61
|
|
62
62
|
## Development
|
63
63
|
|
@@ -77,7 +77,7 @@ Apache 2.0 license. See [LICENSE][license-github] for more information.
|
|
77
77
|
[redis-home]: https://redis.io
|
78
78
|
[bundler-home]: https://bundler.io
|
79
79
|
[repo-github]: https://github.com/open-telemetry/opentelemetry-ruby
|
80
|
-
[license-github]: https://github.com/open-telemetry/opentelemetry-ruby/blob/main/LICENSE
|
80
|
+
[license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
|
81
81
|
[ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
|
82
82
|
[community-meetings]: https://github.com/open-telemetry/community#community-meetings
|
83
83
|
[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
|
@@ -16,7 +16,7 @@ module OpenTelemetry
|
|
16
16
|
end
|
17
17
|
|
18
18
|
present do
|
19
|
-
defined?(::Redis)
|
19
|
+
defined?(::Redis) || defined?(::RedisClient)
|
20
20
|
end
|
21
21
|
|
22
22
|
option :peer_service, default: nil, validate: :string
|
@@ -26,11 +26,13 @@ module OpenTelemetry
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def require_dependencies
|
29
|
-
require_relative 'patches/
|
29
|
+
require_relative 'patches/redis_v4_client' if defined?(::Redis) && ::Redis::VERSION < '5'
|
30
|
+
require_relative 'middlewares/redis_client' if defined?(::RedisClient)
|
30
31
|
end
|
31
32
|
|
32
33
|
def patch_client
|
33
|
-
::
|
34
|
+
::RedisClient.register(Middlewares::RedisClientInstrumentation) if defined?(::RedisClient)
|
35
|
+
::Redis::Client.prepend(Patches::RedisV4Client) if defined?(::Redis) && ::Redis::VERSION < '5'
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -0,0 +1,80 @@
|
|
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
|
+
module Middlewares
|
11
|
+
# Adapter for redis-client instrumentation interface
|
12
|
+
module RedisClientInstrumentation
|
13
|
+
MAX_STATEMENT_LENGTH = 500
|
14
|
+
private_constant :MAX_STATEMENT_LENGTH
|
15
|
+
|
16
|
+
def call(command, redis_config)
|
17
|
+
return super unless instrumentation.config[:trace_root_spans] || OpenTelemetry::Trace.current_span.context.valid?
|
18
|
+
|
19
|
+
attributes = span_attributes(redis_config)
|
20
|
+
|
21
|
+
attributes['db.statement'] = serialize_commands([command]) unless instrumentation.config[:db_statement] == :omit
|
22
|
+
|
23
|
+
span_name = command[0].to_s.upcase
|
24
|
+
instrumentation.tracer.in_span(span_name, attributes: attributes, kind: :client) do
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def call_pipelined(commands, redis_config)
|
30
|
+
return super unless instrumentation.config[:trace_root_spans] || OpenTelemetry::Trace.current_span.context.valid?
|
31
|
+
|
32
|
+
attributes = span_attributes(redis_config)
|
33
|
+
|
34
|
+
attributes['db.statement'] = serialize_commands(commands) unless instrumentation.config[:db_statement] == :omit
|
35
|
+
|
36
|
+
instrumentation.tracer.in_span('PIPELINED', attributes: attributes, kind: :client) do
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def span_attributes(redis_config)
|
44
|
+
attributes = {
|
45
|
+
'db.system' => 'redis',
|
46
|
+
'net.peer.name' => redis_config.host,
|
47
|
+
'net.peer.port' => redis_config.port
|
48
|
+
}
|
49
|
+
|
50
|
+
attributes['db.redis.database_index'] = redis_config.db unless redis_config.db.zero?
|
51
|
+
attributes['peer.service'] = instrumentation.config[:peer_service] if instrumentation.config[:peer_service]
|
52
|
+
attributes.merge!(OpenTelemetry::Instrumentation::Redis.attributes)
|
53
|
+
attributes
|
54
|
+
end
|
55
|
+
|
56
|
+
def serialize_commands(commands)
|
57
|
+
obfuscate = instrumentation.config[:db_statement] == :obfuscate
|
58
|
+
|
59
|
+
serialized_commands = commands.map do |command|
|
60
|
+
# If we receive an authentication request command we want to obfuscate it
|
61
|
+
if obfuscate || command[0].match?(/\A(AUTH|HELLO)\z/)
|
62
|
+
command[0].to_s.upcase + ' ?' * (command.size - 1)
|
63
|
+
else
|
64
|
+
command_copy = command.dup
|
65
|
+
command_copy[0] = command_copy[0].to_s.upcase
|
66
|
+
command_copy.join(' ')
|
67
|
+
end
|
68
|
+
end.join("\n")
|
69
|
+
serialized_commands = OpenTelemetry::Common::Utilities.truncate(serialized_commands, MAX_STATEMENT_LENGTH)
|
70
|
+
OpenTelemetry::Common::Utilities.utf8_encode(serialized_commands, binary: true)
|
71
|
+
end
|
72
|
+
|
73
|
+
def instrumentation
|
74
|
+
Redis::Instrumentation.instance
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -9,12 +9,12 @@ module OpenTelemetry
|
|
9
9
|
module Redis
|
10
10
|
module Patches
|
11
11
|
# Module to prepend to Redis::Client for instrumentation
|
12
|
-
module
|
12
|
+
module RedisV4Client
|
13
13
|
MAX_STATEMENT_LENGTH = 500
|
14
14
|
private_constant :MAX_STATEMENT_LENGTH
|
15
15
|
|
16
|
-
def process(commands) # rubocop:disable Metrics/
|
17
|
-
return super unless
|
16
|
+
def process(commands) # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
17
|
+
return super unless instrumentation_config[:trace_root_spans] || OpenTelemetry::Trace.current_span.context.valid?
|
18
18
|
|
19
19
|
host = options[:host]
|
20
20
|
port = options[:port]
|
@@ -26,10 +26,10 @@ module OpenTelemetry
|
|
26
26
|
}
|
27
27
|
|
28
28
|
attributes['db.redis.database_index'] = options[:db] unless options[:db].zero?
|
29
|
-
attributes['peer.service'] =
|
29
|
+
attributes['peer.service'] = instrumentation_config[:peer_service] if instrumentation_config[:peer_service]
|
30
30
|
attributes.merge!(OpenTelemetry::Instrumentation::Redis.attributes)
|
31
31
|
|
32
|
-
unless
|
32
|
+
unless instrumentation_config[:db_statement] == :omit
|
33
33
|
parsed_commands = parse_commands(commands)
|
34
34
|
parsed_commands = OpenTelemetry::Common::Utilities.truncate(parsed_commands, MAX_STATEMENT_LENGTH)
|
35
35
|
parsed_commands = OpenTelemetry::Common::Utilities.utf8_encode(parsed_commands, binary: true)
|
@@ -42,7 +42,7 @@ module OpenTelemetry
|
|
42
42
|
'PIPELINED'
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
instrumentation_tracer.in_span(span_name, attributes: attributes, kind: :client) do |s|
|
46
46
|
super(commands).tap do |reply|
|
47
47
|
if reply.is_a?(::Redis::CommandError)
|
48
48
|
s.record_exception(reply)
|
@@ -59,7 +59,7 @@ module OpenTelemetry
|
|
59
59
|
# Redis#pipeline: [[:set, "v1", "0"], [:incr, "v1"], [:get, "v1"]]
|
60
60
|
# Redis#hmset [[:hmset, "hash", "f1", 1234567890.0987654]]
|
61
61
|
# Redis#set [[:set, "K", "x"]]
|
62
|
-
def parse_commands(commands)
|
62
|
+
def parse_commands(commands)
|
63
63
|
commands.map do |command|
|
64
64
|
# We are checking for the use of Redis#queue command, if we detect the
|
65
65
|
# extra level of array nesting we return the first element so it
|
@@ -71,7 +71,7 @@ module OpenTelemetry
|
|
71
71
|
# and return the obfuscated command
|
72
72
|
return 'AUTH ?' if command[0] == :auth
|
73
73
|
|
74
|
-
if
|
74
|
+
if instrumentation_config[:db_statement] == :obfuscate
|
75
75
|
command[0].to_s.upcase + ' ?' * (command.size - 1)
|
76
76
|
else
|
77
77
|
command_copy = command.dup
|
@@ -81,11 +81,11 @@ module OpenTelemetry
|
|
81
81
|
end.join("\n")
|
82
82
|
end
|
83
83
|
|
84
|
-
def
|
84
|
+
def instrumentation_tracer
|
85
85
|
Redis::Instrumentation.instance.tracer
|
86
86
|
end
|
87
87
|
|
88
|
-
def
|
88
|
+
def instrumentation_config
|
89
89
|
Redis::Instrumentation.instance.config
|
90
90
|
end
|
91
91
|
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.
|
4
|
+
version: 0.24.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: 2022-
|
11
|
+
date: 2022-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -136,20 +136,34 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 4.1.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: redis-client
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.7'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.7'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: rubocop
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
157
|
- - "~>"
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
159
|
+
version: 1.3.0
|
146
160
|
type: :development
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
164
|
- - "~>"
|
151
165
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
166
|
+
version: 1.3.0
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: simplecov
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -207,16 +221,17 @@ files:
|
|
207
221
|
- lib/opentelemetry/instrumentation.rb
|
208
222
|
- lib/opentelemetry/instrumentation/redis.rb
|
209
223
|
- lib/opentelemetry/instrumentation/redis/instrumentation.rb
|
210
|
-
- lib/opentelemetry/instrumentation/redis/
|
224
|
+
- lib/opentelemetry/instrumentation/redis/middlewares/redis_client.rb
|
225
|
+
- lib/opentelemetry/instrumentation/redis/patches/redis_v4_client.rb
|
211
226
|
- lib/opentelemetry/instrumentation/redis/version.rb
|
212
|
-
homepage: https://github.com/open-telemetry/opentelemetry-
|
227
|
+
homepage: https://github.com/open-telemetry/opentelemetry-contrib
|
213
228
|
licenses:
|
214
229
|
- Apache-2.0
|
215
230
|
metadata:
|
216
|
-
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-redis/v0.
|
217
|
-
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/redis
|
218
|
-
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
219
|
-
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-redis/v0.
|
231
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby-contrib/opentelemetry-instrumentation-redis/v0.24.0/file.CHANGELOG.html
|
232
|
+
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/redis
|
233
|
+
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
234
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby-contrib/opentelemetry-instrumentation-redis/v0.24.0
|
220
235
|
post_install_message:
|
221
236
|
rdoc_options: []
|
222
237
|
require_paths:
|