DeepTracer
SDK Reference

User Context

Attach user identity, tags, and structured context to all events.

Identifying users

Call setUser() to attach a user to all subsequent logs, errors, spans, and LLM reports:

logger.setUser({
  id: "u_123",
  email: "alice@example.com",
  username: "alice",
})

Only id is required. You can add any custom fields:

logger.setUser({
  id: "u_123",
  email: "alice@example.com",
  plan: "pro",
  company: "Acme Corp",
})

Clear the user on sign-out:

logger.clearUser()

Tags

Tags are flat key-value strings. They're indexed and searchable on the dashboard:

logger.setTags({
  release: "1.2.3",
  region: "us-east-1",
  feature_flag: "new-checkout",
})

Tags are merged into every event's metadata as _tags. Call setTags() again to add more -- existing tags are preserved:

logger.setTags({ release: "1.2.3" })
logger.setTags({ region: "us-east-1" })
// Both tags are now active

Clear all tags:

logger.clearTags()

Contexts

Contexts are named blocks of structured data. Use them for rich, non-indexed reference data:

logger.setContext("server", {
  hostname: "web-3",
  memory: "4gb",
  nodeVersion: process.version,
})

logger.setContext("request", {
  url: "/api/checkout",
  method: "POST",
  ip: "203.0.113.42",
})

Contexts are merged into metadata as _contexts.{name}. Clear a specific context or all of them:

logger.clearContext("request") // clear one
logger.clearContext()          // clear all

Scope and isolation

User, tags, and contexts are per-logger instance. Child loggers created with withContext() or forRequest() get an independent copy of the state:

const logger = init({ /* ... */ })
logger.setUser({ id: "u_123" })

const authLogger = logger.withContext("auth")
authLogger.setUser({ id: "u_456" }) // only affects authLogger

logger.info("still u_123")     // user.id = "u_123"
authLogger.info("now u_456")   // user.id = "u_456"

This makes it safe to use request-scoped loggers in concurrent servers without user data leaking between requests.

Putting it all together

import { init } from "@deeptracer/node"

const logger = init()

// After authentication
logger.setUser({ id: user.id, email: user.email, plan: user.plan })
logger.setTags({ tenant: user.orgSlug })
logger.setContext("session", { loginMethod: "google-oauth" })

// All events now carry this context
logger.info("Dashboard loaded", { page: "overview" })

try {
  await riskyOperation()
} catch (error) {
  // Error report includes user, tags, contexts, and breadcrumbs
  logger.captureError(error, { severity: "high" })
}

On the dashboard, you can filter errors by user ID, search logs by tag values, and see the full context block when investigating issues.

On this page