Sha256: 5fa8a11e6f3906a56b22c66fa50a98a86e83546b2d5ae263aa9e02881de4cfc9

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

# typed: true
require 'ddtrace/ext/manual_tracing'
require 'ddtrace/ext/priority'

module Datadog
  # Defines analytics behavior
  module ForcedTracing
    class << self
      def keep(span)
        return if span.nil? || span.context.nil?

        span.context.sampling_priority = Datadog::Ext::Priority::USER_KEEP
      end

      def drop(span)
        return if span.nil? || span.context.nil?

        span.context.sampling_priority = Datadog::Ext::Priority::USER_REJECT
      end
    end

    # Extension for Datadog::Span
    module Span
      def set_tag(key, value)
        # Configure sampling priority if they give us a forced tracing tag
        # DEV: Do not set if the value they give us is explicitly "false"
        case key
        when Ext::ManualTracing::TAG_KEEP
          ForcedTracing.keep(self) unless value == false
        when Ext::ManualTracing::TAG_DROP
          ForcedTracing.drop(self) unless value == false
        else
          # Otherwise, set the tag normally.
          super if defined?(super)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-0.54.2 lib/ddtrace/forced_tracing.rb
ddtrace-0.54.1 lib/ddtrace/forced_tracing.rb
ddtrace-0.54.0 lib/ddtrace/forced_tracing.rb
ddtrace-0.53.0 lib/ddtrace/forced_tracing.rb
ddtrace-0.52.0 lib/ddtrace/forced_tracing.rb