Sha256: 58f305c32c72c5a52419ebc6bf7c67e61d99098ab5450d7a517cb1b4eb3e3917

Contents?: true

Size: 1.82 KB

Versions: 11

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require_relative '../../../kit/identity'

module Datadog
  module AppSec
    module Contrib
      module Devise
        # Internal module to track user events
        module Tracking
          LOGIN_SUCCESS_EVENT = 'users.login.success'
          LOGIN_FAILURE_EVENT = 'users.login.failure'
          SIGNUP_EVENT = 'users.signup'

          def self.track_login_success(trace, span, user_id:, **others)
            return if trace.nil? || span.nil?

            track(LOGIN_SUCCESS_EVENT, trace, span, **others)

            Kit::Identity.set_user(trace, span, id: user_id.to_s, **others) if user_id
          end

          def self.track_login_failure(trace, span, user_id:, user_exists:, **others)
            return if trace.nil? || span.nil?

            track(LOGIN_FAILURE_EVENT, trace, span, **others)

            span.set_tag('appsec.events.users.login.failure.usr.id', user_id) if user_id
            span.set_tag('appsec.events.users.login.failure.usr.exists', user_exists)
          end

          def self.track_signup(trace, span, user_id:, **others)
            return if trace.nil? || span.nil?

            track(SIGNUP_EVENT, trace, span, **others)
            Kit::Identity.set_user(trace, id: user_id.to_s, **others) if user_id
          end

          def self.track(event, trace, span, **others)
            return if trace.nil? || span.nil?

            span.set_tag("appsec.events.#{event}.track", 'true')
            span.set_tag("_dd.appsec.events.#{event}.auto.mode", Datadog.configuration.appsec.track_user_events.mode)

            others.each do |k, v|
              raise ArgumentError, 'key cannot be :track' if k.to_sym == :track

              span.set_tag("appsec.events.#{event}.#{k}", v) unless v.nil?
            end

            trace.keep!
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
datadog-2.7.0 lib/datadog/appsec/contrib/devise/tracking.rb
datadog-2.6.0 lib/datadog/appsec/contrib/devise/tracking.rb
datadog-2.5.0 lib/datadog/appsec/contrib/devise/tracking.rb
datadog-2.4.0 lib/datadog/appsec/contrib/devise/tracking.rb
datadog-2.3.0 lib/datadog/appsec/contrib/devise/tracking.rb
datadog-2.2.0 lib/datadog/appsec/contrib/devise/tracking.rb
ddtrace-1.23.3 lib/datadog/appsec/contrib/devise/tracking.rb
ddtrace-1.23.2 lib/datadog/appsec/contrib/devise/tracking.rb
datadog-2.1.0 lib/datadog/appsec/contrib/devise/tracking.rb
datadog-2.0.0 lib/datadog/appsec/contrib/devise/tracking.rb
ddtrace-1.23.1 lib/datadog/appsec/contrib/devise/tracking.rb