Skip to content

Conversation

@kirs
Copy link
Contributor

@kirs kirs commented Oct 27, 2025

It's surprising that we don't do this for PG while we do this for Trilogy. Without this, it's impossible to attribute any time spent establishing the connection.

@kirs kirs force-pushed the instrument-pg-connect branch from d2fc214 to 6d32bf7 Compare October 27, 2025 17:07
@kirs kirs marked this pull request as ready for review October 27, 2025 17:07
kirs added a commit to kirs/opentelemetry-ruby-contrib that referenced this pull request Oct 28, 2025
* feat: add instrumentation for connecting to PG
@kirs kirs force-pushed the instrument-pg-connect branch 2 times, most recently from 37a50d7 to 950b70a Compare October 28, 2025 00:59
@kirs kirs changed the title Instrument PG connect feat: Instrument PG connect Oct 28, 2025
Copy link
Contributor

@arielvalentin arielvalentin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. I have left some comments for you to review.

@kirs kirs force-pushed the instrument-pg-connect branch 2 times, most recently from 93e6b17 to ff5c0f4 Compare October 28, 2025 22:55
@kirs kirs requested a review from arielvalentin October 28, 2025 22:55
@kirs kirs force-pushed the instrument-pg-connect branch from ff5c0f4 to 1608d41 Compare October 28, 2025 22:58
Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution, @kirs! There's one Rubocop failure on the PG suite to address:

lib/opentelemetry/instrumentation/pg/patches/connection.rb:15:9: 
  C: Style/Documentation: Missing top-level documentation comment for module 
    OpenTelemetry::Instrumentation::PG::Patches::ConnectionHelper.
        module ConnectionHelper
        ^^^^^^^^^^^^^^^^^^^^^^^ 

@kirs kirs force-pushed the instrument-pg-connect branch from 1608d41 to 4542f03 Compare October 30, 2025 05:06
@kirs
Copy link
Contributor Author

kirs commented Oct 30, 2025

fixed, thank you!

config = OpenTelemetry::Instrumentation::PG::Instrumentation.instance.config

tracer.in_span('connect', kind: :client) do |span|
if block_given?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to confirm that there wasn't a way to simply this.

Does the block not get forwarded when calling super?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does get forwarded, but we want a special path for block_given? to be able to set span attributes.

                conn = super
                ConnectionHelper.set_connection_attributes(span, conn, config)
                conn

^ the above only returns conn when there's no block given. When the block is given, it doesn't "leak" the connection object outside of the block.

@kirs kirs force-pushed the instrument-pg-connect branch from 4542f03 to ef9bf74 Compare November 2, 2025 02:28
@arielvalentin arielvalentin merged commit b31ed7a into open-telemetry:main Nov 3, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants