Module: Datadog::Tracing::Contrib::Propagation::SqlComment

Defined in:
lib/datadog/tracing/contrib/propagation/sql_comment.rb,
lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb,
lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb,
lib/datadog/tracing/contrib/propagation/sql_comment/comment.rb

Overview

Implements sql comment propagation related contracts.

Defined Under Namespace

Modules: Ext Classes: Comment, Mode

Class Method Summary collapse

Class Method Details

.annotate!(span_op, mode) ⇒ Object



12
13
14
15
16
# File 'lib/datadog/tracing/contrib/propagation/sql_comment.rb', line 12

def self.annotate!(span_op, mode)
  return unless mode.enabled?

  span_op.set_tag(Ext::TAG_DBM_TRACE_INJECTED, true) if mode.full?
end

.datadog_configurationObject



46
47
48
# File 'lib/datadog/tracing/contrib/propagation/sql_comment.rb', line 46

def self.datadog_configuration
  Datadog.configuration
end

.prepend_comment(sql, span_op, trace_op, mode) ⇒ Object

Inject span_op and trace_op instead of TraceDigest to improve memory usage for ‘disabled` and `service` mode



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/datadog/tracing/contrib/propagation/sql_comment.rb', line 20

def self.prepend_comment(sql, span_op, trace_op, mode)
  return sql unless mode.enabled?

  tags = {
    Ext::KEY_DATABASE_SERVICE => span_op.get_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE) || span_op.service,
    Ext::KEY_ENVIRONMENT => datadog_configuration.env,
    Ext::KEY_PARENT_SERVICE => datadog_configuration.service,
    Ext::KEY_VERSION => datadog_configuration.version
  }

  if mode.full?
    # When tracing is disabled, trace_operation is a dummy object that does not contain data to build traceparent
    if datadog_configuration.tracing.enabled
      tags[Ext::KEY_TRACEPARENT] =
        Tracing::Distributed::TraceContext.new(fetcher: nil).send(:build_traceparent, trace_op.to_digest)
    else
      Datadog.logger.warn(
        'Sql comment propagation with `full` mode is aborted, because tracing is disabled. '\
        'Please set `Datadog.configuration.tracing.enabled = true` to continue.'
      )
    end
  end

  "#{Comment.new(tags)} #{sql}"
end