GETTING STARTED

Instrument your backend with a TrafficWar SDK.

The SDKs validate and queue events, then batch and deliver them in the background. You choose what to measure and add the framework hooks; installing an SDK does not capture requests.

Install one server SDK

Use @trafficwar/node 5+ with Node.js 22+, or trafficwar 2+ with Python 3.9+. Create a service API key and store it in the server environment as TRAFFICWAR_API_KEY. The key selects the destination service. Never send it to the browser or commit it.

Shell
npm install @trafficwar/node
# Or for Python:
python -m pip install trafficwar

Measure one backend request

In your framework, record the start before work and capture from the hook that observes the actual completed response. This Node.js example wraps a handler that returns a Response. Use the matched route template and the real method; do not copy the example’s route into an unrelated handler.

TypeScript
import { TrafficWar } from "@trafficwar/node";

const trafficwar = new TrafficWar({
  apiKey: process.env.TRAFFICWAR_API_KEY!,
  onError: () => console.warn("TrafficWar background delivery failed"),
});

async function measureCheckout(request: Request, handle: () => Promise<Response>) {
  const timestamp = new Date();
  const start = performance.now();
  const response = await handle();
  const latency_ms = performance.now() - start;
  try {
    trafficwar.capture({
      event: "http",
      label: `${request.method} /v1/checkout`,
      path: "/v1/checkout",
      source: "backend-a",
      operation_type: "route.handler",
      span_kind: "server",
      timestamp,
      latency_ms,
      http_method: request.method,
      status_code: response.status,
    });
  } catch {
    console.warn("TrafficWar capture failed");
  }
  return response;
}

Queue during requests; drain at shutdown

Reuse one client per service key. Capture returning successfully means queued, not durably accepted. Observe background errors with onError (Node) or on_error (Python). Drain with close() or aclose() at graceful shutdown, never on every request.

Python uses TrafficWar or AsyncTrafficWar. Record a timezone-aware datetime for the start and use perf_counter() for elapsed time, converting seconds to milliseconds. Await async capture to enqueue and await aclose() to drain. Python does not register observed catalog pairs.

Integrate with a coding agent

  • Read the installed Node package’s README.md and AGENTS.md, or the Python package README’s AI-assisted integration checklist. Link the Node guide from your application’s own agent instructions; dependency guidance may not load automatically.
  • Start with one handler span per selected route. Use stable method/template labels and a separate source alias. Add only dependency and edge spans you measure. Exclude TrafficWar’s own ingest/catalog calls and long-lived live streams.
  • Use a private destination unless publishing route templates, status, timings, and dependency names is intentional. Omit raw URLs, headers, cookies, bodies, SQL text, secrets, and personal data.
  • Drive the real framework hook with fake ingest: test a success, a failure, and two concrete URLs matching one template. Check that route identity stays stable, timings and outcomes are real, sensitive data is absent, and capture failure leaves the response or original exception unchanged. For a trace, also check shared trace identity, unique event IDs, and dependency-first order.