Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make appsec work without tracing #3645

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/datadog/appsec/contrib/devise/tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,32 @@ module Tracking
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)

Comment on lines 15 to 44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cool to add type signatures for this module -- I think they would've caught this bug :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is very true @ivoanjo!

Expand Down
4 changes: 2 additions & 2 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
pkgs ? import <nixpkgs> {},

# use a pinned package state
pinned ? import(fetchTarball("https://github.com/NixOS/nixpkgs/archive/31b322916ae1.tar.gz")) {},
pinned ? import(fetchTarball("https://github.com/NixOS/nixpkgs/archive/25865a40d14b.tar.gz")) {},
}:
let
# specify ruby version to use
ruby = pinned.ruby_3_2;
ruby = pinned.ruby_3_3;

# control llvm/clang version (e.g for packages built from source)
llvm = pinned.llvmPackages_16;
Expand Down
Loading