Skip to content

Commit

Permalink
add SDK tag for login alias
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-id committed Dec 12, 2024
1 parent 134c561 commit 1df40e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/dd-trace/src/appsec/sdk/track_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ function trackUserLoginSuccessEvent (tracer, user, metadata) {

setUserTags(user, rootSpan)

const login = user.login ?? user.id

metadata = Object.assign({ 'usr.login': login }, metadata)

trackEvent('users.login.success', metadata, 'trackUserLoginSuccessEvent', rootSpan)

runWaf('users.login.success', { id: user.id, login: user.login ?? user.id })
runWaf('users.login.success', { id: user.id, login })
}

function trackUserLoginFailureEvent (tracer, userId, exists, metadata) {
Expand All @@ -37,6 +41,7 @@ function trackUserLoginFailureEvent (tracer, userId, exists, metadata) {

const fields = {
'usr.id': userId,
'usr.login': userId,
'usr.exists': exists ? 'true' : 'false',
...metadata
}
Expand Down
10 changes: 8 additions & 2 deletions packages/dd-trace/test/appsec/sdk/track_event.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('track_event', () => {
{
'appsec.events.users.login.success.track': 'true',
'_dd.appsec.events.users.login.success.sdk': 'true',
'appsec.events.users.login.success.usr.login': 'user_id',
'appsec.events.users.login.success.metakey1': 'metaValue1',
'appsec.events.users.login.success.metakey2': 'metaValue2',
'appsec.events.users.login.success.metakey3': 'metaValue3'
Expand All @@ -128,7 +129,8 @@ describe('track_event', () => {
expect(setUserTags).to.have.been.calledOnceWithExactly(user, rootSpan)
expect(rootSpan.addTags).to.have.been.calledOnceWithExactly({
'appsec.events.users.login.success.track': 'true',
'_dd.appsec.events.users.login.success.sdk': 'true'
'_dd.appsec.events.users.login.success.sdk': 'true',
'appsec.events.users.login.success.usr.login': 'user_id',

Check failure on line 133 in packages/dd-trace/test/appsec/sdk/track_event.spec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected trailing comma
})
expect(prioritySampler.setPriority)
.to.have.been.calledOnceWithExactly(rootSpan, USER_KEEP, SAMPLING_MECHANISM_APPSEC)
Expand All @@ -151,7 +153,8 @@ describe('track_event', () => {
expect(setUserTags).to.have.been.calledOnceWithExactly(user, rootSpan)
expect(rootSpan.addTags).to.have.been.calledOnceWithExactly({
'appsec.events.users.login.success.track': 'true',
'_dd.appsec.events.users.login.success.sdk': 'true'
'_dd.appsec.events.users.login.success.sdk': 'true',
'appsec.events.users.login.success.usr.login': 'user_login',

Check failure on line 157 in packages/dd-trace/test/appsec/sdk/track_event.spec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected trailing comma
})
expect(prioritySampler.setPriority)
.to.have.been.calledOnceWithExactly(rootSpan, USER_KEEP, SAMPLING_MECHANISM_APPSEC)
Expand Down Expand Up @@ -203,6 +206,7 @@ describe('track_event', () => {
'appsec.events.users.login.failure.track': 'true',
'_dd.appsec.events.users.login.failure.sdk': 'true',
'appsec.events.users.login.failure.usr.id': 'user_id',
'appsec.events.users.login.failure.usr.login': 'user_id',
'appsec.events.users.login.failure.usr.exists': 'true',
'appsec.events.users.login.failure.metakey1': 'metaValue1',
'appsec.events.users.login.failure.metakey2': 'metaValue2',
Expand Down Expand Up @@ -232,6 +236,7 @@ describe('track_event', () => {
'appsec.events.users.login.failure.track': 'true',
'_dd.appsec.events.users.login.failure.sdk': 'true',
'appsec.events.users.login.failure.usr.id': 'user_id',
'appsec.events.users.login.failure.usr.login': 'user_id',
'appsec.events.users.login.failure.usr.exists': 'false',
'appsec.events.users.login.failure.metakey1': 'metaValue1',
'appsec.events.users.login.failure.metakey2': 'metaValue2',
Expand All @@ -257,6 +262,7 @@ describe('track_event', () => {
'appsec.events.users.login.failure.track': 'true',
'_dd.appsec.events.users.login.failure.sdk': 'true',
'appsec.events.users.login.failure.usr.id': 'user_id',
'appsec.events.users.login.failure.usr.login': 'user_id',
'appsec.events.users.login.failure.usr.exists': 'true'
})
expect(prioritySampler.setPriority)
Expand Down

0 comments on commit 1df40e2

Please sign in to comment.