browser-sdk
AGENTS.md400 starsChanged 9 months agoApache-2.0View on GitHub
Browser SDK for collecting Real User Monitoring (RUM) and logging data from web applications. This project uses Yarn workspaces (latest version). Never use npm or npx. Before running E2E or performance tests, or when a test passes locally but fails in CI, read the running-tests skill (.claude/skills/running-tests/SKILL.md). It also covers compatibility checks, BrowserStack, and pinned browsers. For deeper context, see:
We split this AGENTS.md into the rules it gives an agent
12 rules. About 0 are common, 5 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 49
Before running E2E or performance tests, or when a test passes locally but fails in CI, read the running-tests skill …
- Very specific: line 102
Test framework: Jasmine + Karma.
- Very specific: line 104
Use registerCleanupTask() for cleanup, NOT afterEach()
- Very specific: line 105
Prefer collectAsyncCalls(spy, n) over waitFor(() => spy.calls.count() > 0) for waiting on spy calls
- Very specific: line 106
Don't destructure methods from spy.calls (e.g., argsFor, mostRecent) - use calls.argsFor() to avoid @typescript-eslint/unbound-method errors
- Distinctive: line 111
Use camelCase for all internal variables and object properties
- Distinctive: line 113
Never use snake_case in internal code, even if the final event format requires it
- Very specific: line 117
Prefer TypeScript type narrowing over runtime type assertions (e.g., don't use typeof x === 'object' when proper return types can express …
- Distinctive: line 118
Use discriminated unions and return types to make invalid states unrepresentable at compile time
- Distinctive: line 123
Do NOT include runtime state analysis (e.g., whether a view was active, whether a value was overwritten) in telemetry usage — that belongs …
- Distinctive: line 141
Always branch from main unless explicitly decided otherwise
- Very specific: line 142
Commit messages and PR titles start with a gitmoji (CI checks PR titles).
≈ “Common” is an estimate: at least 1 in 5 of the 36,368 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Datadog Browser SDK
Browser SDK for collecting Real User Monitoring (RUM) and logging data from web applications.
Package Manager
This project uses Yarn workspaces (latest version). Never use npm or npx.
Key Commands
# Development server
yarn dev
# Build all packages
yarn build
# build test apps (for E2E and performance testing)
yarn build:apps
# Run unit tests
yarn test:unit
# Run specific test file
yarn test:unit --spec packages/browser-core/src/path/to/feature.spec.ts
# Run tests on a specific seed
yarn test:unit --seed 123
# setup E2E tests (installs Playwright and builds test apps)
yarn test:e2e:setup
# Run E2E tests
yarn test:e2e
# Run specific E2E test which names match “unhandled rejections”
yarn test:e2e -g "unhandled rejections"
# Type checking
yarn typecheck
# Linting
yarn lint
# Format code
yarn formatBefore running E2E or performance tests, or when a test passes locally but fails in CI, read the running-tests skill (.claude/skills/running-tests/SKILL.md). It also covers compatibility checks, BrowserStack, and pinned browsers.
Monorepo Structure
packages/
├── browser-core/ # Shared utilities (Observable, configuration, transport)
├── browser-rum-core/ # Core RUM functionality
├── browser-rum/ # Full RUM package
├── browser-rum-slim/ # Lightweight RUM
├── browser-rum-react/ # React integration
├── browser-rum-angular/ # Angular integration
├── browser-rum-vue/ # Vue integration
├── browser-rum-nextjs/ # Next.js integration
├── browser-rum-nuxt/ # Nuxt integration
├── browser-logs/ # Browser logging
├── browser-worker/ # Web Worker support
├── browser-debugger/ # Live Debugger (capture function snapshots without code changes)
└── js-core/ # Runtime-agnostic core utilities shared across Datadog JS SDKs
developer-extension/ # Chrome DevTools extension
remote-configuration/ # Remote configuration schema (mirrors internal repo)
sandbox/ # Local dev sandbox (served by `yarn dev` at localhost:8080)
docs/ # Repository documentation
test/
├── apps/ # Test apps for E2E and performance testing
├── e2e/ # Playwright E2E test scenarios
├── performance/ # Performance benchmarking tests
└── unit/ # Karma/Jasmine unit test configuration
scripts/ # Build, deploy, release automationDocumentation
For deeper context, see:
docs/REVIEW.md— what to look for (and what to skip) when reviewing a PRdocs/DEVELOPMENT.md— commit conventions, dependency management, schema generation, TS compatibilitydocs/CONVENTIONS.md— coding style, file organization, size controldocs/ARCHITECTURE.md— package dependencies, data pipelinedocs/TESTING.md— local testing strategies, debugging flaky testsscripts/AGENTS.md— writing and organizing scripts in this codebasetest/e2e/AGENTS.md— E2E test writing guide (createTest builder, IntakeRegistry, patterns)
Critical Patterns
Unit Tests
- Test framework: Jasmine + Karma. Spec files co-located with implementation:
feature.ts→feature.spec.ts - Focus tests with
fit()/fdescribe(), skip withxit()/xdescribe() - Use
registerCleanupTask()for cleanup, NOTafterEach() - Prefer
collectAsyncCalls(spy, n)overwaitFor(() => spy.calls.count() > 0)for waiting on spy calls - Don't destructure methods from
spy.calls(e.g.,argsFor,mostRecent) - usecalls.argsFor()to avoid@typescript-eslint/unbound-methoderrors - Mock values/functions: wrap with
mockable()in source, usereplaceMockable()orreplaceMockableWithSpy()in tests (auto-cleanup)
Naming Conventions
- Use camelCase for all internal variables and object properties
- Conversion to snake_case/pascal_case happens at the serialization boundary (just before sending events)
- Never use snake_case in internal code, even if the final event format requires it
TypeScript Patterns
- Prefer TypeScript type narrowing over runtime type assertions (e.g., don't use
typeof x === 'object'when proper return types can express the shape) - Use discriminated unions and return types to make invalid states unrepresentable at compile time
Telemetry Usage
addTelemetryUsagetracks which public API the customer calls and which options they pass (static call-site information)- Do NOT include runtime state analysis (e.g., whether a view was active, whether a value was overwritten) in telemetry usage — that belongs elsewhere
- In serialized telemetry configuration, the
use_prefix is reserved for boolean fields that track the usage of a configuration option that might contain customer data (e.g.use_allowed_tracing_urls)
Auto-Generated Files
- NEVER manually edit auto-generated files. They have a
DO NOT MODIFY IT BY HANDcomment at the top — respect it - Example:
telemetryEvent.types.tsis generated from therum-events-formatschema repository - Any changes to these files require a corresponding PR in the upstream source repo first, then regeneration
Manual Testing with Chrome MCP
yarn dev serves the sandbox at http://localhost:8080 (increments port if busy). The sandbox page (sandbox/index.html) loads the SDK bundles and calls DD_LOGS.init() / DD_RUM.init().
To test with specific config options (e.g. forwardErrorsToLogs: true), just edit sandbox/index.html temporarily. The dev server reloads on change, so navigate to http://localhost:8080 after saving and use evaluate_script to run test code.
Git Workflow
- Branch naming:
<username>/<feature>(e.g.,john.doe/fix-session-bug) - Always branch from
mainunless explicitly decided otherwise - Commit messages and PR titles start with a gitmoji (CI checks PR titles). Before committing or opening a PR, read the
writing-commits-and-prsskill (.claude/skills/writing-commits-and-prs/SKILL.md): gitmoji choice, signing, PR template.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 28,693 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository8 other files it gives its agents.
- scripts/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- scripts/CLAUDE.mdCLAUDE.md
- .cursor/rules/test-driven-development.mdcCursor rule
- .cursor/rules/unit-test-best-practices.mdcCursor rule
- manual-testingSkill
- running-testsSkill
- writing-commits-and-prsSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

