Sha256: ecdc74cf9f500c2e41db5fa55234080a99964da0dc0888e0d20da91c13ad536f

Contents?: true

Size: 878 Bytes

Versions: 8

Compression:

Stored size: 878 Bytes

Contents

module DatadogSetTraceDetails
  extend ActiveSupport::Concern

  included do
    before_action :set_trace_tags, unless: -> { Rails.env.development? }
  end

  def set_trace_tags
    begin
      # set log context as (Datadog) APM trace tags
      tracer = Datadog.configuration[:rails][:tracer]
      span = tracer.active_span
      dotted_hash(ContextualizedLogger.config.current_context).each do |k, v|
        span.set_tag(k, v)
      end
    rescue StandardError => e
      Rails.logger.info "Error setting trace tags #{e}"
    end
  end

  private

  # {http: {uuid: 123}} => {http.uuid: 123}
  # could be added to Hash
  def dotted_hash(hash, recursive_key = "")
    hash.each_with_object({}) do |(k, v), ret|
      key = recursive_key + k.to_s
      if v.is_a? Hash
        ret.merge! dotted_hash(v, key + ".")
      else
        ret[key] = v
      end
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
contextualized_logs-0.0.8.pre.alpha app/controllers/concerns/datadog_set_trace_details.rb
contextualized_logs-0.0.7.pre.alpha app/controllers/concerns/datadog_set_trace_details.rb
contextualized_logs-0.0.6.pre.alpha app/controllers/concerns/datadog_set_trace_details.rb
contextualized_logs-0.0.5.pre.alpha app/controllers/concerns/datadog_set_trace_details.rb
contextualized_logs-0.0.4.pre.demo app/controllers/concerns/datadog_set_trace_details.rb
contextualized_logs-0.0.4.pre.alpha app/controllers/concerns/datadog_set_trace_details.rb
contextualized_logs-0.0.3.pre.alpha app/controllers/concerns/datadog_set_trace_details.rb
contextualized_logs-0.0.2.pre.alpha app/controllers/concerns/datadog_set_trace_details.rb