opentelemetry-instrumentation-mysql2 0.19.0 → 0.20.1

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: c4c336dee4ea731b92e4546a72fc047e1daaccbfdc45b2771844a71b937283b6
4
- data.tar.gz: ce856296ab136a054567fdd5c180af35ea1538f71eeac10255e47adc6f8e9046
3
+ metadata.gz: 2d7192d94f430fbbbe5892958eb5fd21f247fb6637ed8b22ccb4f167f72bfa7e
4
+ data.tar.gz: d9c54284fcead9d2a8fc5c33ce97a47b5548108b1eab92750288d3af87712817
5
5
  SHA512:
6
- metadata.gz: 6a0c027bb105697ba6c564a32ca3fa1db695ad374302e98b89d59d030fdc2ba63a8c2beb794033687c0a88f9ac00e65b6b6dcd152bbac379ddcdb07b2b7e5f79
7
- data.tar.gz: 8b31ee410ba0364068f3dde580728618cd9db21c09daaae7827d9a023b01ce1ad079c603e976d100c4c2ba0b4e2f93ac1952fe3d4c439a8fa607980eba586ba9
6
+ metadata.gz: af35833d59163dc130bb325d23347171a09af2e03d10b9d4b6012bc6284296bc942bfd07e01393ca39d9c905785d15b10cc198fdb136d030542e8f489a339cac
7
+ data.tar.gz: 17bfa240040ac4f21830031f5dff5a654177d771e37582afe3379581d965312d4447e7168b517384133bff33720b9403f5449c0eb9d1f47fe7506fe0ed345791
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Release History: opentelemetry-instrumentation-mysql2
2
2
 
3
+ ### v0.20.1 / 2022-05-03
4
+
5
+ * ADDED: `with_attributes` method for context propagation
6
+
7
+ ### v0.20.0 / 2021-12-01
8
+
9
+ * ADDED: Add default options config helper + env var config option support
10
+
11
+ ### v0.19.1 / 2021-09-29
12
+
13
+ * (No significant changes)
14
+
3
15
  ### v0.19.0 / 2021-08-12
4
16
 
5
17
  * BREAKING CHANGE: Add option for db.statement
data/README.md CHANGED
@@ -30,6 +30,17 @@ OpenTelemetry::SDK.configure do |c|
30
30
  end
31
31
  ```
32
32
 
33
+ The `mysql2` instrumentation allows the user to supply additional attributes via the `with_attributes` method. This makes it possible to supply additional attributes on mysql2 spans. Attributes supplied in `with_attributes` supersede those automatically generated within `mysql2`'s automatic instrumentation. If you supply a `db.statement` attribute in `with_attributes`, this library's `:db_statement` configuration will not be applied.
34
+
35
+ ```ruby
36
+ require 'opentelemetry/instrumentation/mysql2'
37
+
38
+ client = Mysql2::Client.new(:host => "localhost", :username => "root")
39
+ OpenTelemetry::Instrumentation::Mysql2.with_attributes('pizzatoppings' => 'mushrooms') do
40
+ client.query("SELECT 1")
41
+ end
42
+ ```
43
+
33
44
  ### Configuration options
34
45
 
35
46
  ```ruby
@@ -29,7 +29,7 @@ module OpenTelemetry
29
29
 
30
30
  option :peer_service, default: nil, validate: :string
31
31
  option :enable_sql_obfuscation, default: false, validate: :boolean
32
- option :db_statement, default: :include, validate: ->(opt) { %I[omit include obfuscate].include?(opt) }
32
+ option :db_statement, default: :include, validate: %I[omit include obfuscate]
33
33
 
34
34
  private
35
35
 
@@ -60,7 +60,7 @@ module OpenTelemetry
60
60
  end
61
61
  tracer.in_span(
62
62
  database_span_name(sql),
63
- attributes: attributes,
63
+ attributes: attributes.merge!(OpenTelemetry::Instrumentation::Mysql2.attributes),
64
64
  kind: :client
65
65
  ) do
66
66
  super(sql, options)
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module Mysql2
10
- VERSION = '0.19.0'
10
+ VERSION = '0.20.1'
11
11
  end
12
12
  end
13
13
  end
@@ -11,6 +11,45 @@ module OpenTelemetry
11
11
  module Instrumentation
12
12
  # Contains the OpenTelemetry instrumentation for the Mysql2 gem
13
13
  module Mysql2
14
+ extend self
15
+
16
+ CURRENT_ATTRIBUTES_KEY = Context.create_key('mysql-attributes-hash')
17
+
18
+ private_constant :CURRENT_ATTRIBUTES_KEY
19
+
20
+ # Returns the attributes hash representing the Mysql2 context found
21
+ # in the optional context or the current context if none is provided.
22
+ #
23
+ # @param [optional Context] context The context to lookup the current
24
+ # attributes hash. Defaults to Context.current
25
+ def attributes(context = nil)
26
+ context ||= Context.current
27
+ context.value(CURRENT_ATTRIBUTES_KEY) || {}
28
+ end
29
+
30
+ # Returns a context containing the merged attributes hash, derived from the
31
+ # optional parent context, or the current context if one was not provided.
32
+ #
33
+ # @param [optional Context] context The context to use as the parent for
34
+ # the returned context
35
+ def context_with_attributes(attributes_hash, parent_context: Context.current)
36
+ attributes_hash = attributes(parent_context).merge(attributes_hash)
37
+ parent_context.set_value(CURRENT_ATTRIBUTES_KEY, attributes_hash)
38
+ end
39
+
40
+ # Activates/deactivates the merged attributes hash within the current Context,
41
+ # which makes the "current attributes hash" available implicitly.
42
+ #
43
+ # On exit, the attributes hash that was active before calling this method
44
+ # will be reactivated.
45
+ #
46
+ # @param [Span] span the span to activate
47
+ # @yield [Hash, Context] yields attributes hash and a context containing the
48
+ # attributes hash to the block.
49
+ def with_attributes(attributes_hash)
50
+ attributes_hash = attributes.merge(attributes_hash)
51
+ Context.with_value(CURRENT_ATTRIBUTES_KEY, attributes_hash) { |c, h| yield h, c }
52
+ end
14
53
  end
15
54
  end
16
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-mysql2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.20.1
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-08-16 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0.rc3
19
+ version: '1.0'
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: 1.0.0.rc3
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opentelemetry-instrumentation-base
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.18.2
33
+ version: 0.20.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.18.2
40
+ version: 0.20.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.0.0.rc1
103
+ version: '1.0'
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: 1.0.0.rc1
110
+ version: '1.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: opentelemetry-test-helpers
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: pry
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -213,10 +227,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
213
227
  licenses:
214
228
  - Apache-2.0
215
229
  metadata:
216
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-mysql2/v0.19.0/file.CHANGELOG.html
230
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-mysql2/v0.20.1/file.CHANGELOG.html
217
231
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/mysql2
218
232
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
219
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-mysql2/v0.19.0
233
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-mysql2/v0.20.1
220
234
  post_install_message:
221
235
  rdoc_options: []
222
236
  require_paths: