opentelemetry-helpers-sql-processor 0.3.0 → 0.4.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 93190bba5f90cc331db3cb1bf1ca6f881aa84c2ca372fe36fef411406536e91f
|
|
4
|
+
data.tar.gz: 6d9223214f3c3d2976a98ac38728f09a877beba95ab1e048fead10c41747eb67
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 11ba72f0edb34309d4d7302b57f18461857e140b8a8060e76cdfceaf3a002864f801747728f7e7207ec4362a94a17d58bf45db70bec604bc4f20a9f6c00994a2
|
|
7
|
+
data.tar.gz: 2f82c82e9a1eed0e4aa3be7a7d3d9d34ea53fe048a87c66d6d315c093788012f3d0f26e3fe84d22f14711df4e4367657c088e32a66c8f4d38b7213c80d4af249
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Release History: opentelemetry-helpers-sql-processor
|
|
2
2
|
|
|
3
|
+
### v0.4.0 / 2026-01-13
|
|
4
|
+
|
|
5
|
+
* ADDED: Add SQL Comment Propagator
|
|
6
|
+
|
|
7
|
+
### v0.3.1 / 2025-11-11
|
|
8
|
+
|
|
9
|
+
* DOCS: Update example to match new gem namespace (sql-processor)
|
|
10
|
+
|
|
3
11
|
### v0.3.0 / 2025-11-04
|
|
4
12
|
|
|
5
13
|
* ADDED: Refactor SQL processor file structure for clarity
|
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:
|
|
@@ -43,7 +44,7 @@ Check [New Relic's SQL Obfuscation Helpers module][new-relic-obfuscation-helpers
|
|
|
43
44
|
To obfuscate sql in your library:
|
|
44
45
|
|
|
45
46
|
```ruby
|
|
46
|
-
OpenTelemetry::Helpers::
|
|
47
|
+
OpenTelemetry::Helpers::SqlProcessor.obfuscate_sql(sql, obfuscation_limit: config[:obfuscation_limit], adapter: :postgres)
|
|
47
48
|
```
|
|
48
49
|
|
|
49
50
|
## How can I get involved?
|
|
@@ -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
|
|
@@ -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,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opentelemetry-helpers-sql-processor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.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:
|
|
11
|
+
date: 2026-01-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: opentelemetry-api
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.0'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: opentelemetry-common
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -38,16 +52,17 @@ files:
|
|
|
38
52
|
- lib/opentelemetry-helpers-sql-processor.rb
|
|
39
53
|
- lib/opentelemetry/helpers.rb
|
|
40
54
|
- lib/opentelemetry/helpers/sql_processor.rb
|
|
55
|
+
- lib/opentelemetry/helpers/sql_processor/commenter.rb
|
|
41
56
|
- lib/opentelemetry/helpers/sql_processor/obfuscator.rb
|
|
42
57
|
- lib/opentelemetry/helpers/sql_processor/version.rb
|
|
43
58
|
homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
|
44
59
|
licenses:
|
|
45
60
|
- Apache-2.0
|
|
46
61
|
metadata:
|
|
47
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-processor/0.
|
|
62
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-processor/0.4.0/file/CHANGELOG.md
|
|
48
63
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/helpers/sql-processor
|
|
49
64
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
|
50
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-processor/0.
|
|
65
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-helpers-sql-processor/0.4.0
|
|
51
66
|
post_install_message: ''
|
|
52
67
|
rdoc_options: []
|
|
53
68
|
require_paths:
|