Module: Datadog::Tracing::Contrib::Trilogy::Instrumentation::InstanceMethods

Defined in:
lib/datadog/tracing/contrib/trilogy/instrumentation.rb

Overview

Trilogy patch instance methods

Instance Method Summary collapse

Instance Method Details

#query(sql) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/datadog/tracing/contrib/trilogy/instrumentation.rb', line 22

def query(sql)
  service = Datadog.configuration_for(self, :service_name) || datadog_configuration[:service_name]

  Tracing.trace(Ext::SPAN_QUERY, service: service) do |span, trace_op|
    span.resource = sql
    span.span_type = Tracing::Metadata::Ext::SQL::TYPE

    if datadog_configuration[:peer_service]
      span.set_tag(
        Tracing::Metadata::Ext::TAG_PEER_SERVICE,
        datadog_configuration[:peer_service]
      )
    end

    # Tag original global service name if not used
    if span.service != Datadog.configuration.service
      span.set_tag(Tracing::Contrib::Ext::Metadata::TAG_BASE_SERVICE, Datadog.configuration.service)
    end

    span.set_tag(Contrib::Ext::DB::TAG_SYSTEM, Ext::TAG_SYSTEM)
    span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)

    span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
    span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_QUERY)

    span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, connection_options[:host])

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

    span.set_tag(Ext::TAG_DB_NAME, connection_options[:database])
    span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, connection_options[:host])
    span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_PORT, connection_options[:port])

    Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)

    propagation_mode = Contrib::Propagation::SqlComment::Mode.new(comment_propagation)

    Contrib::Propagation::SqlComment.annotate!(span, propagation_mode)
    sql = Contrib::Propagation::SqlComment.prepend_comment(
      sql,
      span,
      trace_op,
      propagation_mode
    )

    super(sql)
  end
end