@ancha-labs/record 0.1.0 → 0.1.1

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
@@ -8,7 +8,7 @@ npm install @ancha-labs/record @opentelemetry/api
8
8
  node --import ./otel.js --import @ancha-labs/record your-agent.js # otel.js starts your OpenTelemetry SDK
9
9
  ```
10
10
 
11
- - **What becomes a span:** each `fetch` or `node:http(s)` call to a tool Ancha replicates (Slack, GitHub, Datadog, PagerDuty, Stripe, and the hosts in `VENDOR_API_BASES`). It is a client span on your own tracer, so it goes out through your own exporter, with `url.full`, the method, the status, `ancha.service`, and the bodies (`ancha.http.request.body`, `ancha.http.response.body`, 64 KB each at most). Other calls are left alone.
11
+ - **What becomes a span:** each `fetch` or `node:http(s)` call to a tool Ancha replicates (Slack, GitHub, Datadog, PagerDuty, Stripe, Okta on your `<org>.okta.com`, Google Drive, and the hosts in `VENDOR_API_BASES`). It is a client span on your own tracer, so it goes out through your own exporter, with `url.full`, the method, the status, `ancha.service`, and the bodies (`ancha.http.request.body`, `ancha.http.response.body`, 64 KB each at most). Other calls are left alone.
12
12
  - **Headers are never recorded,** so tokens never leave the process. Ancha removes credentials found in bodies before it stores anything.
13
13
  - **Webhooks:** call `recordInbound('slack', rawBody)` in the handler, while the request's server span is active.
14
14
  - **A proxy or private host** in front of a tool: `ANCHA_RECORD_HOSTS=api.internal.example=stripe`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancha-labs/record",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Adds the request and response bodies of your agent's API calls to your OpenTelemetry traces, so Ancha can rebuild the world your agent saw.",
5
5
  "type": "module",
6
6
  "engines": {
package/src/index.mjs CHANGED
@@ -26,7 +26,17 @@ function hostTable(extra = process.env.ANCHA_RECORD_HOSTS ?? '') {
26
26
  for (const pair of extra.split(',').map(s => s.trim()).filter(Boolean)) { const [host, service] = pair.split('='); if (host && service) table.set(host, service); }
27
27
  return table;
28
28
  }
29
- const serviceOf = (url) => { try { return hosts.get(new URL(url).host); } catch { return undefined; } };
29
+ const serviceOf = (url) => { let u; try { u = new URL(url); } catch { return undefined; } return hosts.get(u.host) ?? serviceByRule(u); };
30
+
31
+ /**
32
+ * Vendors that live on the customer's own host (Okta: <org>.okta.com) or on a host other APIs share (Google Drive on
33
+ * www.googleapis.com): a rule each. cloud/rebuild/ir.mjs keeps the same rules; a test holds the two equal.
34
+ */
35
+ export function serviceByRule(u) {
36
+ if (/^[a-z0-9-]+\.(?:okta|oktapreview|okta-emea)\.com$/i.test(u.hostname)) return 'okta';
37
+ if (u.hostname === 'www.googleapis.com' && /^\/(?:upload\/)?drive\//.test(u.pathname)) return 'google-drive';
38
+ return undefined;
39
+ }
30
40
  const clip = (text) => (text.length > MAX_BODY ? `${text.slice(0, MAX_BODY)}[truncated]` : text);
31
41
  const textOf = (body) => (typeof body === 'string' ? body : body instanceof URLSearchParams ? body.toString() : body instanceof Uint8Array ? Buffer.from(body).toString('utf8') : '');
32
42