SeeStack

User Context

Set and manage user identity for all SDK telemetry.

Setting user context lets you associate errors, logs, and other events with a specific user. Once set, user context is automatically attached to all subsequent SDK calls until cleared.

Set User Context

Call setUser after authentication (e.g. after login or session validation):

SeeStack.setUser({
  id: 'usr_1234',
  email: 'user@example.com',
  ip: '192.168.1.100',
});
seestack.set_user(
    id="usr_1234",
    email="[email protected]",
    ip="192.168.1.100",
)
seestack.SetUser(seestack.User{
    ID:    "usr_1234",
    Email: "[email protected]",
    IP:    "192.168.1.100",
})

User Fields

Prop

Type

All fields are optional. Include whichever fields are useful for your debugging workflow.

Clear User Context

Call clearUser on logout or when the session ends:

SeeStack.clearUser();
seestack.clear_user()
seestack.ClearUser()

How Context Propagates

Once set, user context is automatically included in:

FeatureWhere It Appears
Error trackinguser field on the error payload
HTTP monitoringuserId field on captured requests
Session replayLinked to the user's session
LogsAvailable via metadata correlation

Example: Login / Logout Flow

auth.js
async function onLogin(credentials) {
  const user = await authenticate(credentials);

  // Set user context so all subsequent events are associated
  SeeStack.setUser({
    id: user.id,
    email: user.email,
  });
}

function onLogout() {
  SeeStack.clearUser();
  SeeStack.flush(); // Ensure pending events with user context are sent
}
auth.py
def on_login(credentials):
    user = authenticate(credentials)
    seestack.set_user(id=user.id, email=user.email)

def on_logout():
    seestack.clear_user()
    seestack.flush()
auth.go
func onLogin(credentials Credentials) {
    user := authenticate(credentials)
    seestack.SetUser(seestack.User{ID: user.ID, Email: user.Email})
}

func onLogout() {
    seestack.ClearUser()
    seestack.Flush()
}

User context is optional on all events. If you don't set it globally, you can still pass user information per-event in the captureError context parameter.

Per-Event Override

You can override or supplement the global user context on individual calls:

// Global context is "usr_1234", but this error is attributed to a different user
SeeStack.captureError(error, {
  user: { id: 'usr_5678', email: '[email protected]' },
});
seestack.capture_error(error, context={
    "user": {"id": "usr_5678", "email": "[email protected]"},
})
seestack.CaptureError(err, &seestack.ErrorContext{
    User: &seestack.User{ID: "usr_5678", Email: "[email protected]"},
})

Per-event user context takes precedence over the global context for that specific event.

On this page