tracer.appsec. It provides methods for user tracking, blocking, and custom security event tracking.
AppSec must be enabled (
DD_APPSEC_ENABLED=true or appsec: { enabled: true } in TracerOptions) for these methods to have effect. All methods are safe to call when AppSec is disabled — they become no-ops.Methods
setUser(user)
Links an authenticated user to the current trace.
User properties. The
id field is required.isUserBlocked(user)
Checks whether the given user should be blocked according to AppSec rules (e.g., a blocklist). If no user is currently linked to the trace, this method also links the given user.
The user to check. The
id field is required.true if the user should be blocked, false otherwise.blockRequest(req?, res?)
Sends a “blocked” response based on the request Accept header and ends the response. After calling this method, you must stop processing the request.
The request object. If omitted, the current request is used.
The response object. If omitted, the current response is used.
true if the blocking response was sent successfully, false otherwise.trackUserLoginSuccessEvent(user, metadata?) (deprecated)
Links a successful login event to the current trace.
Properties of the authenticated user.
Custom string key-value pairs to attach to the event.
trackUserLoginFailureEvent(userId, exists, metadata?) (deprecated)
Links a failed login event to the current trace.
The user ID of the attempted login.
Whether the user ID exists in the system.
Custom string key-value pairs to attach to the event.
trackCustomEvent(eventName, metadata?)
Links a custom security event to the current trace.
The name of the custom event.
Custom string key-value pairs to attach to the event.
eventTrackingV2
The eventTrackingV2 sub-object provides the current generation of user event tracking methods.
trackUserLoginSuccess(login, user?, metadata?)
Links a successful login event to the current trace. Also calls setUser() internally to link the user.
The login key (username, email) used to authenticate.
User properties object, a user ID string, or
null.Custom fields to attach to the event.
trackUserLoginFailure(login, exists?, metadata?)
Links a failed login event to the current trace.
The login key used in the failed attempt.
Whether the login exists in the system.
Custom fields to attach to the event.
