@trafficwar/node 2.2.2 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -89,21 +89,39 @@ const trafficwar = new TrafficWar({
89
89
  });
90
90
  ```
91
91
 
92
+ Set `verbose: true` to print, once at startup, every `event` and `label` the
93
+ SDK can see statically in `capture()` calls under the working directory (or
94
+ `catalogRoot`). String literals are printed as written. A present value that
95
+ is not a static string is printed as `<dynamic>`, and a missing one as
96
+ `<missing>`. The scan skips `node_modules` and does not print payloads, API
97
+ keys, or other properties. A scan failure is logged and does not stop the
98
+ client.
99
+
100
+ ```ts
101
+ const trafficwar = new TrafficWar({
102
+ apiKey: process.env.TRAFFICWAR_API_KEY!,
103
+ verbose: true,
104
+ });
105
+ ```
106
+
92
107
  The SDK generates a process-monotonic RFC 9562 UUIDv7 `event_id` for each event
93
108
  that omits one. A caller may override it with any valid UUID. Caller-owned
94
109
  objects are never modified.
95
110
 
96
- Canonical `event` categories are `http`, `database`, `redis`, and `s3`. Use
111
+ Canonical `event` categories are `http`, `database`, `redis`, `s3`, and
112
+ `external`. Use `external` for an outbound HTTP service that belongs on the
113
+ infrastructure tier. Use
97
114
  `source` for the emitting host or dependency (`backend-a`, `db-primary`,
98
- `redis-1`, `ovh-s3`, `https://app.example.com`), `label` for the human route
99
- name (`Checkout`), `path` for the route URL (`/v1/checkout`), and
100
- `operation_type` for the concrete work (`route.handler`, `postgres.select`,
101
- `redis.get`, `s3.get_object`). For HTTP events, `http_method` is trimmed and
102
- normalized to uppercase and must be a 1–64-character RFC HTTP token. Spans of
103
- one request share `trace_id`. `span_kind` is one of `server`, `client`,
104
- `producer`, `consumer`, or `internal`, lowercase; any other value is discarded.
105
- It does not replace `source`, and it is not decorative: `event`, `source`, and
106
- `span_kind` are the three fields that place a span on a tier.
115
+ `redis-1`, `ovh-s3`, `google-routes`, `https://app.example.com`), `label` for
116
+ the human route name (`Checkout`), `path` for the route URL
117
+ (`/v1/checkout`), and `operation_type` for the concrete work
118
+ (`route.handler`, `postgres.select`, `redis.get`, `s3.get_object`,
119
+ `google.routes.compute`). For HTTP events, `http_method` is trimmed and
120
+ normalized to uppercase and must be a 1–64-character RFC HTTP token. Spans
121
+ of one request share `trace_id`. `span_kind` is one of `server`, `client`,
122
+ `producer`, `consumer`, or `internal`, lowercase; any other value is
123
+ discarded. It does not replace `source`, and it is not decorative: `event`,
124
+ `source`, and `span_kind` are the three fields that place a span on a tier.
107
125
 
108
126
  ## Traces and tiers
109
127
 
@@ -111,7 +129,8 @@ Spans of one request share `trace_id` and `label`. There is no `span_id` or
111
129
  `parent_span_id` on the wire, so TrafficWar places each span on a tier from its
112
130
  own fields, in this order:
113
131
 
114
- 1. `event` is `database`, `redis`, or `s3` — **infrastructure**.
132
+ 1. `event` is `database`, `redis`, `s3`, or `external` —
133
+ **infrastructure**.
115
134
  2. `event` is `http` and `source` is an absolute `http(s)://` URL, or starts
116
135
  with `web`, `browser`, `client`, `edge`, or `frontend` followed by a
117
136
  separator or nothing (`web`, `web-eu`, `frontend.eu`, but not `webhooks`)
@@ -127,14 +146,14 @@ own fields, in this order:
127
146
  tier regardless of its `span_kind`. Sending your own API hostname as the
128
147
  `source` of a browser-facing span is the most common way to get a span on the
129
148
  wrong tier. `operation_type` never affects tier placement; it names the
130
- operation dot on S3 stations. Only `server` and `client` select a tier:
149
+ concrete activity. Only `server` and `client` select an HTTP tier:
131
150
  `producer`, `consumer`, and `internal` fall through to rule 5, so an `http`
132
151
  span with one of those kinds lands on the edge tier.
133
152
 
134
153
  On the edge and backend tiers the station is named by `label`, and `source`
135
154
  becomes an instance dot inside that station. Infrastructure stations are named
136
- from `event` and `source`, so `db-primary`, `redis-1`, and `receipts.ovh-s3`
137
- each get their own station.
155
+ from `event` and `source`, so `db-primary`, `redis-1`, `receipts.ovh-s3`, and
156
+ `google-routes` each get their own station.
138
157
 
139
158
  ### Send a complete trace
140
159
 
@@ -163,6 +182,9 @@ trafficwar.capture([
163
182
  { event: "s3", label, path, distinct_id, trace_id,
164
183
  source: "receipts.ovh-s3", operation_type: "s3.put_object",
165
184
  span_kind: "client", timestamp: at(75), latency_ms: 22.0 },
185
+ { event: "external", label, path, distinct_id, trace_id,
186
+ source: "payment-gateway", operation_type: "payment.authorize",
187
+ span_kind: "client", timestamp: at(100), latency_ms: 20.0 },
166
188
  { event: "http", label, path, distinct_id, trace_id,
167
189
  source: "backend-a", operation_type: "route.handler",
168
190
  span_kind: "server", timestamp: at(8), latency_ms: 160,
@@ -176,7 +198,7 @@ trafficwar.capture([
176
198
 
177
199
  That trace renders as one journey: an edge station for `Checkout` with
178
200
  `https://app.example.com` as its caller, a backend station for `Checkout`
179
- served by `backend-a`, and three infrastructure stations beneath it.
201
+ served by `backend-a`, and four infrastructure stations beneath it.
180
202
 
181
203
  A single-span request needs none of this. One `http` span with
182
204
  `span_kind: "server"` is a complete, valid event.
@@ -198,9 +220,24 @@ report, send the server span alone. A trace does not require an edge span.
198
220
  an allowlist of hostnames you expect and collapse the rest to a single value
199
221
  such as `web-other`, rather than forwarding arbitrary header content.
200
222
 
201
- There is no category for outbound third-party HTTP. A call your backend makes
202
- to another vendor's API is `event: "http"` with `span_kind: "client"`, which is
203
- the edge signature, so it renders on the edge tier beside your real callers.
223
+ For an outbound third-party HTTP call, send `event: "external"` with
224
+ `span_kind: "client"`. Keep the provider in `source` and the API action in
225
+ `operation_type`:
226
+
227
+ ```ts
228
+ trafficwar.capture({
229
+ event: "external",
230
+ source: "google-routes",
231
+ label: "Route planner",
232
+ span_kind: "client",
233
+ operation_type: "google.routes.compute",
234
+ latency_ms: 13,
235
+ });
236
+ ```
237
+
238
+ This creates a source-keyed infrastructure station. The incoming caller remains
239
+ an `http` client span. If a request has no trusted `Origin` or `Referer`, use a
240
+ stable value such as `web-direct`; never substitute your own API `Host` header.
204
241
 
205
242
  ## Actor identity and application errors
206
243
 
@@ -300,6 +337,10 @@ delivery still fails.
300
337
  - `baseUrl`: ingest origin. Defaults to `https://ingest.trafficwar.tech`.
301
338
  - `debug`: print safe batch lifecycle diagnostics with `console.debug`.
302
339
  Defaults to `false`.
340
+ - `verbose`: at startup, statically scan source for `capture()` calls and
341
+ print each `event` and `label`. Defaults to `false`.
342
+ - `catalogRoot`: directory scanned when `verbose` is true. Defaults to the
343
+ process working directory.
303
344
  - `timeoutMs`: timeout for each attempt. Defaults to 30,000 ms, safely above
304
345
  TrafficWar's 10-second durable acknowledgement window.
305
346
  - `maxRetries`: retries after the first attempt. Defaults to 3.