Skip to content

Commit 45edbb3

Browse files
Merge branch 'main' into 669-add-net_ldap-instrumentation
2 parents 93deed5 + 6963d21 commit 45edbb3

File tree

14 files changed

+340
-103
lines changed

14 files changed

+340
-103
lines changed

.github/workflows/ossf-scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ jobs:
4343
# Upload the results to GitHub's code scanning dashboard (optional).
4444
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
4545
- name: "Upload to code-scanning"
46-
uses: github/codeql-action/upload-sarif@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
46+
uses: github/codeql-action/upload-sarif@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
4747
with:
4848
sarif_file: results.sarif

helpers/sql-processor/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History: opentelemetry-helpers-sql-processor
22

3+
### v0.3.0 / 2025-11-04
4+
5+
* ADDED: Refactor SQL processor file structure for clarity
6+
37
### v0.2.0 / 2025-10-22
48

59
* BREAKING CHANGE: Min Ruby Version 3.2

helpers/sql-processor/lib/opentelemetry/helpers/sql_processor/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
module OpenTelemetry
88
module Helpers
99
module SqlProcessor
10-
VERSION = '0.2.0'
10+
VERSION = '0.3.0'
1111
end
1212
end
1313
end

instrumentation/all/opentelemetry-instrumentation-all.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Gem::Specification.new do |spec|
4949
spec.add_dependency 'opentelemetry-instrumentation-mongo', '~> 0.25.0'
5050
spec.add_dependency 'opentelemetry-instrumentation-mysql2', '~> 0.31.0'
5151
spec.add_dependency 'opentelemetry-instrumentation-net_http', '~> 0.26.0'
52-
spec.add_dependency 'opentelemetry-instrumentation-pg', '~> 0.32.0'
52+
spec.add_dependency 'opentelemetry-instrumentation-pg', '~> 0.33.0'
5353
spec.add_dependency 'opentelemetry-instrumentation-que', '~> 0.11.1'
5454
spec.add_dependency 'opentelemetry-instrumentation-racecar', '~> 0.6.0'
5555
spec.add_dependency 'opentelemetry-instrumentation-rack', '~> 0.29.0'

instrumentation/pg/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History: opentelemetry-instrumentation-pg
22

3+
### v0.33.0 / 2025-11-03
4+
5+
* ADDED: Instrument PG connect
6+
37
### v0.32.0 / 2025-10-22
48

59
* BREAKING CHANGE: Min Ruby Version 3.2

instrumentation/pg/lib/opentelemetry/instrumentation/pg/constants.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ module Constants
9494
async_exec_prepared
9595
sync_exec_prepared
9696
].freeze
97+
98+
CONNECTION_METHODS = %i[
99+
connect
100+
open
101+
async_connect
102+
].freeze
97103
end
98104
end
99105
end

instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def require_dependencies
4040

4141
def patch_client
4242
::PG::Connection.prepend(Patches::Connection)
43+
::PG::Connection.singleton_class.prepend(Patches::Connect)
4344
end
4445
end
4546
end

instrumentation/pg/lib/opentelemetry/instrumentation/pg/patches/connection.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,65 @@ module OpenTelemetry
1212
module Instrumentation
1313
module PG
1414
module Patches
15+
# Utility methods for setting connection attributes from Connect module
16+
module ConnectionHelper
17+
module_function
18+
19+
def set_connection_attributes(span, conn, config)
20+
attributes = {
21+
'db.system' => 'postgresql',
22+
'db.name' => conn.db,
23+
'db.user' => conn.user
24+
}
25+
attributes['peer.service'] = config[:peer_service] if config[:peer_service]
26+
27+
h = conn.host
28+
if h&.start_with?('/')
29+
attributes['net.sock.family'] = 'unix'
30+
attributes['net.peer.name'] = h
31+
else
32+
attributes['net.transport'] = 'ip_tcp'
33+
attributes['net.peer.name'] = h
34+
attributes['net.peer.port'] = conn.port if defined?(::PG::DEF_PGPORT)
35+
end
36+
37+
attributes.merge!(OpenTelemetry::Instrumentation::PG.attributes)
38+
attributes.compact!
39+
40+
span.add_attributes(attributes)
41+
end
42+
end
43+
44+
# Module to prepend to PG::Connection singleton class for connection initialization
45+
# We override `new` instead of `initialize` because PG::Connection.new is implemented
46+
# as a Ruby method that calls the C-level connect_start, bypassing initialize.
47+
# We also need to override the aliases (open, connect, async_connect) because they
48+
# were aliased before our prepend, so they point to the original method.
49+
# See: https://github.com/ged/ruby-pg/blob/master/lib/pg/connection.rb#L870
50+
module Connect
51+
def new(...)
52+
tracer = OpenTelemetry::Instrumentation::PG::Instrumentation.instance.tracer
53+
config = OpenTelemetry::Instrumentation::PG::Instrumentation.instance.config
54+
55+
tracer.in_span('connect', kind: :client) do |span|
56+
if block_given?
57+
super do |conn|
58+
ConnectionHelper.set_connection_attributes(span, conn, config)
59+
yield conn
60+
end
61+
else
62+
conn = super
63+
ConnectionHelper.set_connection_attributes(span, conn, config)
64+
conn
65+
end
66+
end
67+
end
68+
69+
PG::Constants::CONNECTION_METHODS.each do |method|
70+
alias_method method, :new
71+
end
72+
end
73+
1574
# Module to prepend to PG::Connection for instrumentation
1675
module Connection # rubocop:disable Metrics/ModuleLength
1776
# Capture the first word (including letters, digits, underscores, & '.', ) that follows common table commands

instrumentation/pg/lib/opentelemetry/instrumentation/pg/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
module OpenTelemetry
88
module Instrumentation
99
module PG
10-
VERSION = '0.32.0'
10+
VERSION = '0.33.0'
1111
end
1212
end
1313
end

0 commit comments

Comments
 (0)