opentelemetry-helpers-sql-processor 0.3.1 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0380c8c77d57d2b262a891b3884c062ba915a6f07d9d0ff92aeb1c861e8936d
4
- data.tar.gz: 944100d9a3992b01bd2e094f53d385c25ebbd1d7965a42e23debc7439c8a5ffe
3
+ metadata.gz: 25af87a0d0abf1c7ceb6331a6366bd423cb7125eb78218e19f4e20950c4312d7
4
+ data.tar.gz: 10772b8265474e6fefa0f2cfe18db768933c417d6c01656cd0026860a616e334
5
5
  SHA512:
6
- metadata.gz: 8a386117eca07e983310afcb18c79e1d3779b63cf52b4f6eff780ab33a50c13a85b813227bd247a75121a07071f54ede0bacb4e4678dfe77300872f173915fcd
7
- data.tar.gz: e05f541df0080331651b87304dc60ef715c7ae6ce4b2348270640199ea0528d75ee0c2435284ed11ce2cb1ccfa8a20a59d4287a297ff9283cd1617804636d436
6
+ metadata.gz: 3eb81ec23557397fbbd190be415c6bf090548623e10643d22adbcac4dde9e54d88a7b1c62e97fd229d96e648d20cfed34681ad4331ace3bca39c1bb09487c677
7
+ data.tar.gz: 6a4101499693d326f9ae521e77c3681e1df466605219c11097535a2d93d8db63423b2a8b3b5f0c0ff5bbc28fe38f0ebb70dcb7e0bee9ccf1dd9d1c0491abe554
data/CHANGELOG.md CHANGED
@@ -1,19 +1,28 @@
1
1
  # Release History: opentelemetry-helpers-sql-processor
2
2
 
3
- ### v0.3.1 / 2025-11-11
3
+ ## v0.5.0 / 2026-04-14
4
4
 
5
- * DOCS: Update example to match new gem namespace (sql-processor)
5
+ - BREAKING CHANGE: Min Ruby Version 3.3 (#2125)
6
+ - ADDED: Min Ruby Version 3.3 (#2125)
7
+ - ADDED: Add release tag into source code url of gem metadata (#1984)
6
8
 
7
- ### v0.3.0 / 2025-11-04
9
+ ## v0.4.0 / 2026-01-13
8
10
 
9
- * ADDED: Refactor SQL processor file structure for clarity
11
+ - ADDED: Add SQL Comment Propagator
10
12
 
11
- ### v0.2.0 / 2025-10-22
13
+ ## v0.3.1 / 2025-11-11
12
14
 
13
- * BREAKING CHANGE: Min Ruby Version 3.2
15
+ - DOCS: Update example to match new gem namespace (sql-processor)
14
16
 
15
- * ADDED: Min Ruby Version 3.2
17
+ ## v0.3.0 / 2025-11-04
16
18
 
17
- ### v0.1.0 / 2025-10-08
19
+ - ADDED: Refactor SQL processor file structure for clarity
18
20
 
19
- Initial release.
21
+ ## v0.2.0 / 2025-10-22
22
+
23
+ - BREAKING CHANGE: Min Ruby Version 3.2
24
+ - ADDED: Min Ruby Version 3.2
25
+
26
+ ## v0.1.0 / 2025-10-08
27
+
28
+ - Initial release.
data/README.md CHANGED
@@ -22,6 +22,7 @@ group :test do
22
22
  gem 'opentelemetry-helpers-sql-processor', path: '../../helpers/sql-processor'
23
23
  end
24
24
  ```
25
+
25
26
  ## Obfuscation
26
27
 
27
28
  Make sure the `Instrumentation` class for your gem contains configuration options for:
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright The OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ require 'cgi'
8
+
9
+ module OpenTelemetry
10
+ module Helpers
11
+ module SqlProcessor
12
+ # SqlCommenter provides SQL comment-based trace context propagation
13
+ # according to the SQL Commenter specification.
14
+ #
15
+ # This module implements a propagator interface compatible with Vitess,
16
+ # allowing it to be used as a drop-in replacement.
17
+ #
18
+ # @api public
19
+ module SqlCommenter
20
+ extend self
21
+
22
+ # SqlQuerySetter is responsible for formatting trace context as SQL comments
23
+ # and appending them to SQL queries according to the SQL Commenter specification.
24
+ #
25
+ # Format: /*key='value',key2='value2'*/
26
+ # Values are URL-encoded per the SQL Commenter spec
27
+ module SqlQuerySetter
28
+ extend self
29
+
30
+ # Appends trace context as a SQL comment to the carrier (SQL query string)
31
+ #
32
+ # @param carrier [String] The SQL query string to modify
33
+ # @param headers [Hash] Hash of trace context headers (e.g., {'traceparent' => '00-...'})
34
+ def set(carrier, headers)
35
+ return if headers.empty?
36
+ return if carrier.frozen?
37
+
38
+ # Convert headers hash to SQL commenter format
39
+ # Format: /*key1='value1',key2='value2'*/
40
+ comment_parts = headers.map do |key, value|
41
+ # URL encode values as per SQL Commenter spec (using URI component encoding)
42
+ encoded_value = CGI.escapeURIComponent(value.to_s)
43
+ "#{key}='#{encoded_value}'"
44
+ end
45
+
46
+ # Append to end of query (spec recommendation)
47
+ carrier << " /*#{comment_parts.join(',')}*/"
48
+ end
49
+ end
50
+
51
+ # SqlQueryPropagator propagates trace context using SQL comments
52
+ # according to the SQL Commenter specification.
53
+ #
54
+ # This propagator implements the same interface as the Vitess propagator
55
+ # and can be used as a drop-in replacement.
56
+ #
57
+ # @example
58
+ # propagator = OpenTelemetry::Helpers::SqlProcessor::SqlCommenter.sql_query_propagator
59
+ # sql = "SELECT * FROM users"
60
+ # propagator.inject(sql, context: current_context)
61
+ # # => "SELECT * FROM users /*traceparent='00-...',tracestate='...'*/"
62
+ module SqlQueryPropagator
63
+ extend self
64
+
65
+ # Injects trace context into a SQL query as a comment
66
+ #
67
+ # @param carrier [String] The SQL query string to inject context into
68
+ # @param context [optional, Context] The context to inject. Defaults to current context.
69
+ # @param setter [optional, #set] The setter to use for appending the comment.
70
+ # Defaults to SqlQuerySetter.
71
+ # @return [nil]
72
+ def inject(carrier, context: OpenTelemetry::Context.current, setter: SqlQuerySetter)
73
+ # Use the global propagator to extract headers into a hash
74
+ headers = {}
75
+ OpenTelemetry.propagation.inject(headers, context: context)
76
+
77
+ # Pass the headers to our SQL comment setter
78
+ setter.set(carrier, headers)
79
+ nil
80
+ end
81
+ end
82
+
83
+ # Returns the SqlQueryPropagator module for stateless propagation
84
+ #
85
+ # @return [Module] The SqlQueryPropagator module
86
+ def sql_query_propagator
87
+ SqlQueryPropagator
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Helpers
9
9
  module SqlProcessor
10
- VERSION = '0.3.1'
10
+ VERSION = '0.5.0'
11
11
  end
12
12
  end
13
13
  end
@@ -6,13 +6,15 @@
6
6
 
7
7
  require 'opentelemetry-common'
8
8
  require_relative 'sql_processor/obfuscator'
9
+ require_relative 'sql_processor/commenter'
9
10
 
10
11
  module OpenTelemetry
11
12
  module Helpers
12
13
  # SQL processing utilities for OpenTelemetry instrumentation.
13
14
  #
14
15
  # This module provides a unified interface for SQL processing operations
15
- # commonly needed in database adapter instrumentation, including SQL obfuscation.
16
+ # commonly needed in database adapter instrumentation, including SQL obfuscation
17
+ # and SQL comment-based trace context propagation.
16
18
  #
17
19
  # @api public
18
20
  module SqlProcessor
metadata CHANGED
@@ -1,15 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-helpers-sql-processor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-11-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: opentelemetry-api
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.0'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: opentelemetry-common
15
28
  requirement: !ruby/object:Gem::Requirement
@@ -38,16 +51,17 @@ files:
38
51
  - lib/opentelemetry-helpers-sql-processor.rb
39
52
  - lib/opentelemetry/helpers.rb
40
53
  - lib/opentelemetry/helpers/sql_processor.rb
54
+ - lib/opentelemetry/helpers/sql_processor/commenter.rb
41
55
  - lib/opentelemetry/helpers/sql_processor/obfuscator.rb
42
56
  - lib/opentelemetry/helpers/sql_processor/version.rb
43
57
  homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
44
58
  licenses:
45
59
  - Apache-2.0
46
60
  metadata:
47
- changelog_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-processor/0.3.1/file/CHANGELOG.md
48
- source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/helpers/sql-processor
61
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-processor/0.5.0/file/CHANGELOG.md
62
+ source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/opentelemetry-helpers-sql-processor/v0.5.0/helpers/sql-processor
49
63
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
50
- documentation_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-processor/0.3.1
64
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-processor/0.5.0
51
65
  post_install_message: ''
52
66
  rdoc_options: []
53
67
  require_paths:
@@ -56,15 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
70
  requirements:
57
71
  - - ">="
58
72
  - !ruby/object:Gem::Version
59
- version: '3.2'
73
+ version: '3.3'
60
74
  required_rubygems_version: !ruby/object:Gem::Requirement
61
75
  requirements:
62
76
  - - ">="
63
77
  - !ruby/object:Gem::Version
64
78
  version: '0'
65
79
  requirements: []
66
- rubygems_version: 3.4.19
67
- signing_key:
80
+ rubygems_version: 4.0.6
68
81
  specification_version: 4
69
82
  summary: SQL Processing Instrumentation Helpers for the OpenTelemetry framework
70
83
  test_files: []