Module: Datadog::Contrib::Mysql2::Instrumentation::InstanceMethods

Defined in:
lib/ddtrace/contrib/mysql2/instrumentation.rb

Overview

Mysql2::Client patch instance methods

Instance Method Summary collapse

Instance Method Details

#datadog_pinObject



34
35
36
37
38
39
40
41
# File 'lib/ddtrace/contrib/mysql2/instrumentation.rb', line 34

def datadog_pin
  @datadog_pin ||= Datadog::Pin.new(
    Datadog.configuration[:mysql2][:service_name],
    app: Ext::APP,
    app_type: Datadog::Ext::AppTypes::DB,
    tracer: Datadog.configuration[:mysql2][:tracer]
  )
end

#query(sql, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ddtrace/contrib/mysql2/instrumentation.rb', line 18

def query(sql, options = {})
  datadog_pin.tracer.trace(Ext::SPAN_QUERY) do |span|
    span.resource = sql
    span.service = datadog_pin.service
    span.span_type = Datadog::Ext::SQL::TYPE

    # Set analytics sample rate
    Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?

    span.set_tag(Ext::TAG_DB_NAME, query_options[:database])
    span.set_tag(Datadog::Ext::NET::TARGET_HOST, query_options[:host])
    span.set_tag(Datadog::Ext::NET::TARGET_PORT, query_options[:port])
    super(sql, options)
  end
end