instrumentation-facades

instrumentation-facades is a cursor rule for Cursor from duckduckgo/apple-browsers. It costs 14 tokens per session (1,448 once invoked), scanned A, original, Apache-2.0.

A design pattern that puts event and usage tracking behind a small, domain-specific interface instead of placing tracking calls throughout feature code.

In plain words
What is it for?
Use it to organize analytics events, timing data, success or failure states, and test doubles for instrumentation.
Why use it?
It keeps the main feature logic easier to read, test, and change while keeping tracking behavior in one place.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it to organize analytics events, timing data, success or failure states, and test doubles for instrumentation.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/duckduckgo/apple-browsers/instrumentation-facades
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/duckduckgo/apple-browsers

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for instrumentation-facades

README.md
[![agentmods](https://agentmods.dev/badge/rules/duckduckgo/apple-browsers/instrumentation-facades.svg)](https://agentmods.dev/rules/duckduckgo/apple-browsers/instrumentation-facades)
Your own site
<a href="https://agentmods.dev/rules/duckduckgo/apple-browsers/instrumentation-facades"><img src="https://agentmods.dev/badge/rules/duckduckgo/apple-browsers/instrumentation-facades.svg" alt="Measured on agentmods" height="20"></a>
Per session 14 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,448 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00014 $0.01448
Opus 5 $0.00007 $0.00724
Sonnet 5 $0.00003 $0.00290
Haiku 4.5 $0.00001 $0.00145

Measured 6d ago against content hash ead3d8c53570, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

instrumentation-facades scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/instrumentation-facades.mdc · 203 lines

How it starts

The opening of the file, as written. The whole thing — 203 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Instrumentation Facades

Feature code often becomes verbose when sending many pixels, or mixing pixel calls and wide event lifecycle management.

Consider a subscription purchase flow that needs to:

  • Fire a daily pixel when purchase starts
  • Start a wide event flow
  • Update the wide event with timing data
  • Fire unique pixels on success
  • Complete the wide event with success/failure/cancelled status
  • Handle multiple error cases with different failing steps

This leads to instrumentation code scattered throughout the feature, making it hard to:

  • Understand the feature's core logic
  • Test the feature in isolation
  • Modify instrumentation without touching feature code
  • Ensure all instrumentation points are covered

We can improve this using the facade pattern, abstracting our instrumentation behind a protocol. This is done by defining a protocol with domain-specific hooks that the feature calls, then implementing the protocol in a dedicated object that handles all instrumentation.

Benefits

  1. Feature code emits domain events only - Cleaner, more readable feature logic
  2. Instrumentation logic is centralized - Easy to audit and modify
  3. Easy to inject mocks for unit testing - Test feature behavior without pixel dependencies

File Organization

Instrumentation facades should be placed in the same module as the feature they instrument:

Component Location
Protocol Feature module (e.g., Subscription/SubscriptionPurchaseInstrumentation.swift)
Default Implementation Same module as protocol
Mock for Testing Test target or same module

For features that span iOS and macOS, place the protocol and implementation in a shared package (e.g., BrowserServicesKit).

Pattern Structure

Step 1: Define the Protocol

Create a protocol with methods for each instrumentation hook your feature needs. Name methods after domain events, not pixels:

public protocol SubscriptionPurchaseInstrumentation: AnyObject {
    func purchaseAttemptStarted(selectionID: String, freeTrialEligible: Bool, ...)
    func purchaseCancelled()
    func purchaseFailed(step: FailingStep, error: Error)
    func activationSucceeded()
    // ... other domain events
}

Read the full file on GitHub · 203 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 203 lines · 14 tokens per session scan A ead3d8c53570

Subscribe to this mod's changes

instrumentation-facades is a cursor rule published in the GitHub repository duckduckgo/apple-browsers (251 stars, last pushed yesterday), licensed Apache-2.0. It adds 14 tokens to every session and 1,448 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-01.