Module: OpenTelemetry::Instrumentation::PG::Patches::Connect
- Defined in:
- lib/opentelemetry/instrumentation/pg/patches/connection.rb
Overview
Module to prepend to PG::Connection singleton class for connection initialization
We override new instead of initialize because PG::Connection.new is implemented
as a Ruby method that calls the C-level connect_start, bypassing initialize.
We also need to override the aliases (open, connect, async_connect) because they
were aliased before our prepend, so they point to the original method.
See: https://github.com/ged/ruby-pg/blob/master/lib/pg/connection.rb#L870
Instance Method Summary collapse
Instance Method Details
#new ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/opentelemetry/instrumentation/pg/patches/connection.rb', line 51 def new(...) tracer = OpenTelemetry::Instrumentation::PG::Instrumentation.instance.tracer config = OpenTelemetry::Instrumentation::PG::Instrumentation.instance.config tracer.in_span('connect', kind: :client) do |span| if block_given? super do |conn| ConnectionHelper.set_connection_attributes(span, conn, config) yield conn end else conn = super ConnectionHelper.set_connection_attributes(span, conn, config) conn end end end |