Sha256: 780d43fb72132ce2c18cb444a6273f8a8b6f02a3eb137d89edb5d45fb77dbb79

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

# typed: true
require 'ddtrace/ext/analytics'

module Datadog
  # Defines analytics behavior
  module Analytics
    class << self
      def set_sample_rate(span, sample_rate)
        return if span.nil? || !sample_rate.is_a?(Numeric)

        span.set_metric(Datadog::Ext::Analytics::TAG_SAMPLE_RATE, sample_rate)
      end

      def set_measured(span, value = true)
        return if span.nil?

        # rubocop:disable Style/MultipleComparison
        value = value == true || value == 1 ? 1 : 0
        span.set_metric(Datadog::Ext::Analytics::TAG_MEASURED, value)
      end
    end

    # Extension for Datadog::Span
    module Span
      def set_tag(key, value)
        case key
        when Ext::Analytics::TAG_ENABLED
          # If true, set rate to 1.0, otherwise set 0.0.
          value = value == true ? Ext::Analytics::DEFAULT_SAMPLE_RATE : 0.0
          Analytics.set_sample_rate(self, value)
        when Ext::Analytics::TAG_SAMPLE_RATE
          Analytics.set_sample_rate(self, value)
        else
          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/analytics.rb
ddtrace-0.54.1 lib/ddtrace/analytics.rb
ddtrace-0.54.0 lib/ddtrace/analytics.rb
ddtrace-0.53.0 lib/ddtrace/analytics.rb
ddtrace-0.52.0 lib/ddtrace/analytics.rb