risicare 0.9.1 → 0.10.0

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.
Files changed (93) hide show
  1. package/CHANGELOG.md +1419 -0
  2. package/README.md +37 -19
  3. package/dist/frameworks/instructor.cjs +65 -5
  4. package/dist/frameworks/instructor.cjs.map +1 -1
  5. package/dist/frameworks/instructor.js +65 -5
  6. package/dist/frameworks/instructor.js.map +1 -1
  7. package/dist/frameworks/langchain.cjs +65 -5
  8. package/dist/frameworks/langchain.cjs.map +1 -1
  9. package/dist/frameworks/langchain.js +65 -5
  10. package/dist/frameworks/langchain.js.map +1 -1
  11. package/dist/frameworks/langgraph.cjs +65 -5
  12. package/dist/frameworks/langgraph.cjs.map +1 -1
  13. package/dist/frameworks/langgraph.js +65 -5
  14. package/dist/frameworks/langgraph.js.map +1 -1
  15. package/dist/frameworks/llamaindex.cjs +65 -5
  16. package/dist/frameworks/llamaindex.cjs.map +1 -1
  17. package/dist/frameworks/llamaindex.js +65 -5
  18. package/dist/frameworks/llamaindex.js.map +1 -1
  19. package/dist/index.cjs +405 -27
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +14 -5
  22. package/dist/index.d.ts +14 -5
  23. package/dist/index.js +405 -27
  24. package/dist/index.js.map +1 -1
  25. package/dist/providers/anthropic/index.cjs +141 -13
  26. package/dist/providers/anthropic/index.cjs.map +1 -1
  27. package/dist/providers/anthropic/index.d.cts +3 -0
  28. package/dist/providers/anthropic/index.d.ts +3 -0
  29. package/dist/providers/anthropic/index.js +141 -13
  30. package/dist/providers/anthropic/index.js.map +1 -1
  31. package/dist/providers/bedrock/index.cjs +88 -9
  32. package/dist/providers/bedrock/index.cjs.map +1 -1
  33. package/dist/providers/bedrock/index.d.cts +3 -0
  34. package/dist/providers/bedrock/index.d.ts +3 -0
  35. package/dist/providers/bedrock/index.js +88 -9
  36. package/dist/providers/bedrock/index.js.map +1 -1
  37. package/dist/providers/cerebras/index.cjs +88 -9
  38. package/dist/providers/cerebras/index.cjs.map +1 -1
  39. package/dist/providers/cerebras/index.d.cts +3 -0
  40. package/dist/providers/cerebras/index.d.ts +3 -0
  41. package/dist/providers/cerebras/index.js +88 -9
  42. package/dist/providers/cerebras/index.js.map +1 -1
  43. package/dist/providers/cohere/index.cjs +88 -9
  44. package/dist/providers/cohere/index.cjs.map +1 -1
  45. package/dist/providers/cohere/index.d.cts +3 -0
  46. package/dist/providers/cohere/index.d.ts +3 -0
  47. package/dist/providers/cohere/index.js +88 -9
  48. package/dist/providers/cohere/index.js.map +1 -1
  49. package/dist/providers/google/index.cjs +88 -9
  50. package/dist/providers/google/index.cjs.map +1 -1
  51. package/dist/providers/google/index.d.cts +3 -0
  52. package/dist/providers/google/index.d.ts +3 -0
  53. package/dist/providers/google/index.js +88 -9
  54. package/dist/providers/google/index.js.map +1 -1
  55. package/dist/providers/groq/index.cjs +88 -9
  56. package/dist/providers/groq/index.cjs.map +1 -1
  57. package/dist/providers/groq/index.d.cts +3 -0
  58. package/dist/providers/groq/index.d.ts +3 -0
  59. package/dist/providers/groq/index.js +88 -9
  60. package/dist/providers/groq/index.js.map +1 -1
  61. package/dist/providers/huggingface/index.cjs +86 -8
  62. package/dist/providers/huggingface/index.cjs.map +1 -1
  63. package/dist/providers/huggingface/index.js +86 -8
  64. package/dist/providers/huggingface/index.js.map +1 -1
  65. package/dist/providers/mistral/index.cjs +88 -9
  66. package/dist/providers/mistral/index.cjs.map +1 -1
  67. package/dist/providers/mistral/index.d.cts +3 -0
  68. package/dist/providers/mistral/index.d.ts +3 -0
  69. package/dist/providers/mistral/index.js +88 -9
  70. package/dist/providers/mistral/index.js.map +1 -1
  71. package/dist/providers/ollama/index.cjs +88 -9
  72. package/dist/providers/ollama/index.cjs.map +1 -1
  73. package/dist/providers/ollama/index.d.cts +3 -0
  74. package/dist/providers/ollama/index.d.ts +3 -0
  75. package/dist/providers/ollama/index.js +88 -9
  76. package/dist/providers/ollama/index.js.map +1 -1
  77. package/dist/providers/openai/index.cjs +126 -11
  78. package/dist/providers/openai/index.cjs.map +1 -1
  79. package/dist/providers/openai/index.d.cts +3 -0
  80. package/dist/providers/openai/index.d.ts +3 -0
  81. package/dist/providers/openai/index.js +126 -11
  82. package/dist/providers/openai/index.js.map +1 -1
  83. package/dist/providers/together/index.cjs +88 -9
  84. package/dist/providers/together/index.cjs.map +1 -1
  85. package/dist/providers/together/index.d.cts +3 -0
  86. package/dist/providers/together/index.d.ts +3 -0
  87. package/dist/providers/together/index.js +88 -9
  88. package/dist/providers/together/index.js.map +1 -1
  89. package/dist/providers/vercel-ai/index.cjs +67 -7
  90. package/dist/providers/vercel-ai/index.cjs.map +1 -1
  91. package/dist/providers/vercel-ai/index.js +67 -7
  92. package/dist/providers/vercel-ai/index.js.map +1 -1
  93. package/package.json +3 -2
package/dist/index.d.cts CHANGED
@@ -310,10 +310,17 @@ interface RisicareConfig {
310
310
  /**
311
311
  * Whether prompt/completion content may leave the process.
312
312
  *
313
- * **Default `false` since 0.5.1** (was `true`). When false, every
314
- * content-keyed attribute is replaced with `<risicare:content-omitted>` on
315
- * the export path — including content you set by hand, which 0.5.0 and
316
- * earlier did NOT gate.
313
+ * **Default `true`** (capture is on). Set `false`, or set
314
+ * `RISICARE_TRACE_CONTENT=false`, to stop capture. Capture was on through
315
+ * 0.5.0, off by default from 0.5.2 to 0.9.2, and is on by default again after
316
+ * 0.9.2. When false, every content-keyed attribute is replaced with
317
+ * `<risicare:content-omitted>` on the export path — including content you
318
+ * set by hand, which 0.5.0 and earlier did NOT gate. The project setting in
319
+ * the Risicare dashboard can also turn content off for a project; the
320
+ * gateway then drops it. With `traceContent: false`, the SDK still sends the
321
+ * status message, the exception message, the stack trace (which repeats the
322
+ * message), `error.message` and `exception.message`. Only the project switch
323
+ * masks them, at the gateway.
317
324
  */
318
325
  traceContent?: boolean;
319
326
  /** Sample rate 0.0–1.0 (default: 1.0 = trace all) */
@@ -400,7 +407,9 @@ interface TracerConfig {
400
407
  /** Whether tracing is enabled */
401
408
  enabled?: boolean;
402
409
  /**
403
- * Whether prompt/completion content may leave the process (default: false).
410
+ * Whether prompt/completion content may leave the process. A Tracer built
411
+ * without this value uses `false` (fail-closed); that is NOT the user default,
412
+ * which is `true` in `resolveConfig`.
404
413
  *
405
414
  * ⚠ The Tracer only CARRIES this for the provider patches to read via
406
415
  * `getTraceContent()`. It is NOT the enforcement point — the gate runs in the
package/dist/index.d.ts CHANGED
@@ -310,10 +310,17 @@ interface RisicareConfig {
310
310
  /**
311
311
  * Whether prompt/completion content may leave the process.
312
312
  *
313
- * **Default `false` since 0.5.1** (was `true`). When false, every
314
- * content-keyed attribute is replaced with `<risicare:content-omitted>` on
315
- * the export path — including content you set by hand, which 0.5.0 and
316
- * earlier did NOT gate.
313
+ * **Default `true`** (capture is on). Set `false`, or set
314
+ * `RISICARE_TRACE_CONTENT=false`, to stop capture. Capture was on through
315
+ * 0.5.0, off by default from 0.5.2 to 0.9.2, and is on by default again after
316
+ * 0.9.2. When false, every content-keyed attribute is replaced with
317
+ * `<risicare:content-omitted>` on the export path — including content you
318
+ * set by hand, which 0.5.0 and earlier did NOT gate. The project setting in
319
+ * the Risicare dashboard can also turn content off for a project; the
320
+ * gateway then drops it. With `traceContent: false`, the SDK still sends the
321
+ * status message, the exception message, the stack trace (which repeats the
322
+ * message), `error.message` and `exception.message`. Only the project switch
323
+ * masks them, at the gateway.
317
324
  */
318
325
  traceContent?: boolean;
319
326
  /** Sample rate 0.0–1.0 (default: 1.0 = trace all) */
@@ -400,7 +407,9 @@ interface TracerConfig {
400
407
  /** Whether tracing is enabled */
401
408
  enabled?: boolean;
402
409
  /**
403
- * Whether prompt/completion content may leave the process (default: false).
410
+ * Whether prompt/completion content may leave the process. A Tracer built
411
+ * without this value uses `false` (fail-closed); that is NOT the user default,
412
+ * which is `true` in `resolveConfig`.
404
413
  *
405
414
  * ⚠ The Tracer only CARRIES this for the provider patches to read via
406
415
  * `getTraceContent()`. It is NOT the enforcement point — the gate runs in the
package/dist/index.js CHANGED
@@ -281,7 +281,49 @@ var CONTENT_KEYS_EXACT = /* @__PURE__ */ new Set([
281
281
  "audio.transcript",
282
282
  "traceloop.entity.input",
283
283
  // OpenLLMetry
284
- "traceloop.entity.output"
284
+ "traceloop.entity.output",
285
+ // Gateway corpus v2 (R41): the content keys of more frameworks. The same 75
286
+ // keys as `CONTENT_KEYS_EXACT` in the gateway's `content_control.rs`.
287
+ "agent.backstory",
288
+ // OpenInference
289
+ "agent.goal",
290
+ "llm.available_functions",
291
+ "llm.tools",
292
+ "ai.prompt",
293
+ // Vercel AI SDK
294
+ "ai.prompt.messages",
295
+ "ai.prompt.tools",
296
+ "ai.response.files",
297
+ "ai.response.object",
298
+ "ai.response.reasoning",
299
+ "ai.response.text",
300
+ "ai.response.toolCalls",
301
+ "ai.result.object",
302
+ // the older Vercel names
303
+ "ai.result.text",
304
+ "ai.result.toolCalls",
305
+ "ai.toolCall.args",
306
+ "ai.toolCall.result",
307
+ "ai.value",
308
+ // the text of an embedding call
309
+ "ai.values",
310
+ "final_result",
311
+ // Pydantic AI
312
+ "model_request_parameters",
313
+ "pydantic_ai.all_messages",
314
+ "tool_arguments",
315
+ "tool_response",
316
+ "gcp.vertex.agent.data",
317
+ // Google ADK
318
+ "gcp.vertex.agent.llm_request",
319
+ "gcp.vertex.agent.llm_response",
320
+ "gcp.vertex.agent.tool_call_args",
321
+ "gcp.vertex.agent.tool_response",
322
+ "gen_ai.task.input",
323
+ // OpenLLMetry
324
+ "gen_ai.task.output",
325
+ "sk.available_functions"
326
+ // Semantic Kernel
285
327
  ]);
286
328
  var CONTENT_LAST_SEGMENT_IN_CONTEXT = /* @__PURE__ */ new Map([
287
329
  ["function_call_arguments_json", /* @__PURE__ */ new Set()],
@@ -289,7 +331,15 @@ var CONTENT_LAST_SEGMENT_IN_CONTEXT = /* @__PURE__ */ new Map([
289
331
  ["data", /* @__PURE__ */ new Set(["message_content"])],
290
332
  ["url", /* @__PURE__ */ new Set(["image"])],
291
333
  // `image.url` can hold base64 data
292
- ["metadata", /* @__PURE__ */ new Set(["document", "documents"])]
334
+ ["metadata", /* @__PURE__ */ new Set(["document", "documents"])],
335
+ // Gateway corpus v2: a list of tool definitions. The `description` of one tool
336
+ // on a tool span (`tool.description`) is not content; the descriptions in a list are.
337
+ ["description", /* @__PURE__ */ new Set(["definitions", "functions", "tools"])],
338
+ ["json_schema", /* @__PURE__ */ new Set(["tool", "tools"])],
339
+ ["parameters", /* @__PURE__ */ new Set(["definitions", "functions", "tool", "tools"])],
340
+ // Gateway corpus v2: the Mastra span I/O, `mastra.<span type>.input|output`.
341
+ ["input", /* @__PURE__ */ new Set(["mastra"])],
342
+ ["output", /* @__PURE__ */ new Set(["mastra"])]
293
343
  ]);
294
344
  var CONTENT_CONTAINER_SEGMENTS = /* @__PURE__ */ new Set([
295
345
  "message",
@@ -302,8 +352,23 @@ var CONTENT_CONTAINER_SEGMENTS = /* @__PURE__ */ new Set([
302
352
  "documents",
303
353
  "tool_call",
304
354
  "tool_calls",
305
- "function"
355
+ "function",
356
+ // Gateway corpus v2: LiteLLM `gen_ai.completion.{i}.function_call.arguments` and
357
+ // OpenInference `llm.prompts.{i}.prompt.text`.
358
+ "function_call",
359
+ "prompt",
360
+ "prompts"
361
+ ]);
362
+ var CONTENT_FIRST_SEGMENTS = /* @__PURE__ */ new Set(["crewai"]);
363
+ var CONTENT_EVENT_NAMES = /* @__PURE__ */ new Set([
364
+ "gen_ai.assistant.message",
365
+ "gen_ai.choice",
366
+ "gen_ai.system.message",
367
+ "gen_ai.tool.message",
368
+ "gen_ai.user.message"
306
369
  ]);
370
+ var CONTENT_EVENT_PREFIX = "gen_ai.content.";
371
+ var CONTENT_EVENT_KEEP_KEYS = /* @__PURE__ */ new Set(["gen_ai.provider.name", "gen_ai.system"]);
307
372
  var CONTENT_KEYS_KEEP_EXACT = /* @__PURE__ */ new Set([
308
373
  "gen_ai.response.content_type",
309
374
  "gen_ai.response.content_blocks",
@@ -321,10 +386,60 @@ var KEEP_LAST_SEGMENTS = /* @__PURE__ */ new Set([
321
386
  "index",
322
387
  "model",
323
388
  "finish_reason",
324
- "mime_type"
389
+ "mime_type",
390
+ // Gateway v2 at risicare-ingestion main (PR 94): a model name
391
+ // (`crewai.agent.llm`) and the crew process type are not content.
392
+ "llm",
393
+ "process"
325
394
  ]);
326
395
  var KEEP_LAST_SUFFIXES = ["_length", "_tokens", "_count"];
396
+ var CONTENT_IN_JSON_OBJECT = /* @__PURE__ */ new Map([
397
+ [
398
+ "llm.invocation_parameters",
399
+ /* @__PURE__ */ new Set([
400
+ "additionalinstructions",
401
+ // OpenAI assistants run
402
+ "chathistory",
403
+ // Cohere
404
+ "contents",
405
+ // Gemini
406
+ "documents",
407
+ // Cohere RAG
408
+ "functions",
409
+ "input",
410
+ "inputtext",
411
+ // Bedrock Titan
412
+ "instructions",
413
+ "message",
414
+ // Cohere
415
+ "messages",
416
+ "preamble",
417
+ // Cohere
418
+ "prediction",
419
+ // OpenAI predicted output
420
+ "prompt",
421
+ "system",
422
+ // Anthropic
423
+ "systeminstruction",
424
+ // Gemini
425
+ "texts",
426
+ // Cohere embed
427
+ "toolconfig",
428
+ // Gemini
429
+ "tools"
430
+ ])
431
+ ]
432
+ ]);
433
+ var VALUE_RULE_PREFIXES = new Set(
434
+ [...CONTENT_IN_JSON_OBJECT.keys()].flatMap((key) => {
435
+ const segments = key.split(".");
436
+ return segments.slice(1).map((_, i) => segments.slice(0, i + 1).join("."));
437
+ })
438
+ );
327
439
  var CONTENT_OMITTED_MARKER = "<risicare:content-omitted>";
440
+ function hasKeepLastSegment(last) {
441
+ return KEEP_LAST_SEGMENTS.has(last) || KEEP_LAST_SUFFIXES.some((x) => last.endsWith(x));
442
+ }
328
443
  function isContentKey(key) {
329
444
  if (CONTENT_KEYS_KEEP_EXACT.has(key)) return false;
330
445
  if (CONTENT_KEYS_EXACT.has(key) || key.endsWith("_content")) return true;
@@ -334,25 +449,220 @@ function isContentKey(key) {
334
449
  if (context && (context.size === 0 || segments.slice(0, -1).some((s) => context.has(s)))) {
335
450
  return true;
336
451
  }
337
- if (KEEP_LAST_SEGMENTS.has(last) || KEEP_LAST_SUFFIXES.some((x) => last.endsWith(x))) {
452
+ if (hasKeepLastSegment(last)) {
338
453
  return false;
339
454
  }
455
+ if (segments.length > 1 && CONTENT_FIRST_SEGMENTS.has(segments[0])) return true;
340
456
  if (last === "content") return true;
341
457
  if (last === "text" || last === "arguments") {
342
458
  return segments.slice(0, -1).some((s) => CONTENT_CONTAINER_SEGMENTS.has(s));
343
459
  }
344
460
  return false;
345
461
  }
346
- function stripAttributes(attrs) {
462
+ function isContentEvent(name) {
463
+ return CONTENT_EVENT_NAMES.has(name) || name.startsWith(CONTENT_EVENT_PREFIX);
464
+ }
465
+ function isContentEventAttribute(key) {
466
+ if (isContentKey(key)) return true;
467
+ const last = key.slice(key.lastIndexOf(".") + 1);
468
+ return !(CONTENT_KEYS_KEEP_EXACT.has(key) || CONTENT_EVENT_KEEP_KEYS.has(key) || hasKeepLastSegment(last));
469
+ }
470
+ function jsonObjectContentKeys(keyPath, key) {
471
+ for (const [ruleKey, keys] of CONTENT_IN_JSON_OBJECT) {
472
+ if (ruleKey === keyPath || ruleKey === key) return keys;
473
+ }
474
+ return void 0;
475
+ }
476
+ function isJsonObject(value) {
477
+ return typeof value === "object" && value !== null && !Array.isArray(value);
478
+ }
479
+ function flatValueRule(keyPath, key) {
480
+ for (const [ruleKey, keys] of CONTENT_IN_JSON_OBJECT) {
481
+ for (const k of [keyPath, key]) {
482
+ if (k.startsWith(`${ruleKey}.`)) return [k.slice(ruleKey.length + 1), keys];
483
+ }
484
+ }
485
+ return void 0;
486
+ }
487
+ function normalisedKey(key) {
488
+ return key.replace(/_/g, "").replace(/[A-Z]/g, (c) => c.toLowerCase());
489
+ }
490
+ function namesListedKey(key, keys) {
491
+ return key.split(".").some((part) => keys.has(normalisedKey(part)));
492
+ }
493
+ function isKeyRuleText(keyPath, key) {
494
+ return isContentKey(keyPath) || isContentKey(key);
495
+ }
496
+ function startsAsJson(text) {
497
+ return /^[ \t\n\r]*[{[]/.test(text);
498
+ }
499
+ function parseJson(text) {
500
+ return JSON.parse(text, (_key, value) => {
501
+ if (typeof value === "number" && !Number.isFinite(value)) {
502
+ throw new RangeError("not JSON: a number out of range");
503
+ }
504
+ return value;
505
+ });
506
+ }
507
+ function jsonCopy(value) {
508
+ return parseJson(
509
+ JSON.stringify(value, (_key, v) => {
510
+ if (typeof v === "number" && !Number.isFinite(v)) throw new RangeError("not JSON: a non-finite number");
511
+ return v;
512
+ })
513
+ );
514
+ }
515
+ function omitInJsonObject(value, keyPath, keys) {
516
+ try {
517
+ let parsed;
518
+ if (typeof value === "string") parsed = parseJson(value);
519
+ else if (typeof value === "object" && value !== null) parsed = jsonCopy(value);
520
+ if (!isJsonObject(parsed)) return [CONTENT_OMITTED_MARKER, 1];
521
+ let n = 0;
522
+ for (const k of Object.keys(parsed)) {
523
+ const [entry, count] = omitInParameterEntry(parsed[k], `${keyPath}.${k}`, k, keys);
524
+ parsed[k] = entry;
525
+ n += count;
526
+ }
527
+ return [typeof value === "string" ? JSON.stringify(parsed) : parsed, n];
528
+ } catch {
529
+ return [CONTENT_OMITTED_MARKER, 1];
530
+ }
531
+ }
532
+ function omitInParameterEntry(value, keyPath, key, keys) {
533
+ if (namesListedKey(key, keys) || isKeyRuleText(keyPath, key)) return [CONTENT_OMITTED_MARKER, 1];
534
+ return omitInParameter(value, keyPath, keys);
535
+ }
536
+ function omitInParameter(value, path, keys) {
347
537
  let n = 0;
348
- for (const k of Object.keys(attrs)) {
349
- if (isContentKey(k)) {
350
- attrs[k] = CONTENT_OMITTED_MARKER;
351
- n++;
538
+ if (Array.isArray(value)) {
539
+ value.forEach((item, i) => {
540
+ const [entry, count] = omitInParameter(item, `${path}.${i}`, keys);
541
+ value[i] = entry;
542
+ n += count;
543
+ });
544
+ } else if (isJsonObject(value)) {
545
+ for (const k of Object.keys(value)) {
546
+ const [entry, count] = omitInParameterEntry(value[k], `${path}.${k}`, k, keys);
547
+ value[k] = entry;
548
+ n += count;
549
+ }
550
+ } else if (typeof value === "string" && startsAsJson(value)) {
551
+ try {
552
+ const [tree, count] = omitInParameter(parseJson(value), path, keys);
553
+ return [count ? JSON.stringify(tree) : value, count];
554
+ } catch {
555
+ return [CONTENT_OMITTED_MARKER, 1];
556
+ }
557
+ }
558
+ return [value, n];
559
+ }
560
+ function omitFlat(value, keyPath, key, rest, keys) {
561
+ if (namesListedKey(rest, keys) || isKeyRuleText(keyPath, key)) return [CONTENT_OMITTED_MARKER, 1];
562
+ try {
563
+ if (typeof value === "object" && value !== null) {
564
+ const [tree, n] = omitInParameter(jsonCopy(value), keyPath, keys);
565
+ return n ? [tree, n] : [value, 0];
566
+ }
567
+ return omitInParameter(value, keyPath, keys);
568
+ } catch {
569
+ return [CONTENT_OMITTED_MARKER, 1];
570
+ }
571
+ }
572
+ function omitBelow(value, path) {
573
+ const text = typeof value === "string" ? value : value instanceof String ? value.valueOf() : void 0;
574
+ if (text !== void 0) {
575
+ let tree;
576
+ try {
577
+ tree = parseJson(text);
578
+ } catch {
579
+ return startsAsJson(text) ? [CONTENT_OMITTED_MARKER, 1] : [value, 0];
580
+ }
581
+ if (typeof tree !== "object" || tree === null) return [value, 0];
582
+ try {
583
+ const [n, found] = omitBelowParsed(tree, path);
584
+ return found ? [JSON.stringify(tree), n] : [value, 0];
585
+ } catch {
586
+ return [CONTENT_OMITTED_MARKER, 1];
352
587
  }
353
588
  }
589
+ if (typeof value !== "object" || value === null) return [value, 0];
590
+ try {
591
+ const tree = jsonCopy(value);
592
+ const [n, found] = omitBelowParsed(tree, path);
593
+ return found ? [tree, n] : [value, 0];
594
+ } catch {
595
+ return [CONTENT_OMITTED_MARKER, 1];
596
+ }
597
+ }
598
+ function omitBelowParsed(tree, path) {
599
+ let n = 0;
600
+ let found = false;
601
+ if (Array.isArray(tree)) {
602
+ tree.forEach((item, i) => {
603
+ const child = `${path}.${i}`;
604
+ if (!VALUE_RULE_PREFIXES.has(child)) return;
605
+ const [count, below] = omitBelowParsed(item, child);
606
+ n += count;
607
+ found ||= below;
608
+ });
609
+ } else if (isJsonObject(tree)) {
610
+ for (const k of Object.keys(tree)) {
611
+ const child = `${path}.${k}`;
612
+ const keys = jsonObjectContentKeys(child, k);
613
+ const flat = keys ? void 0 : flatValueRule(child, k);
614
+ if (keys) {
615
+ const [entry, count] = omitInJsonObject(tree[k], child, keys);
616
+ tree[k] = entry;
617
+ n += count;
618
+ found = true;
619
+ } else if (flat) {
620
+ const [entry, count] = omitFlat(tree[k], child, k, flat[0], flat[1]);
621
+ tree[k] = entry;
622
+ n += count;
623
+ found = true;
624
+ } else if (VALUE_RULE_PREFIXES.has(child)) {
625
+ const [count, below] = omitBelowParsed(tree[k], child);
626
+ n += count;
627
+ found ||= below;
628
+ }
629
+ }
630
+ }
631
+ return [n, found];
632
+ }
633
+ function reachesValueRule(key) {
634
+ return CONTENT_IN_JSON_OBJECT.has(key) || VALUE_RULE_PREFIXES.has(key) || flatValueRule(key, key) !== void 0;
635
+ }
636
+ function stripAttributes(attrs, rule = isContentKey) {
637
+ let n = 0;
638
+ for (const k of Object.keys(attrs)) {
639
+ const keys = rule === isContentKey ? jsonObjectContentKeys(k, k) : void 0;
640
+ const flat = rule === isContentKey && !keys ? flatValueRule(k, k) : void 0;
641
+ let result;
642
+ if (keys) result = omitInJsonObject(attrs[k], k, keys);
643
+ else if (flat) result = omitFlat(attrs[k], k, k, flat[0], flat[1]);
644
+ else if (rule(k)) result = [CONTENT_OMITTED_MARKER, 1];
645
+ else if (VALUE_RULE_PREFIXES.has(k)) result = omitBelow(attrs[k], k);
646
+ else continue;
647
+ attrs[k] = result[0];
648
+ n += result[1];
649
+ }
354
650
  return n;
355
651
  }
652
+ function stripOwned(holder, rule = isContentKey) {
653
+ const attrs = holder.attributes;
654
+ if (!attrs || typeof attrs !== "object" || !Object.keys(attrs).some((k) => rule(k) || reachesValueRule(k))) {
655
+ return 0;
656
+ }
657
+ const copy = { ...attrs };
658
+ try {
659
+ holder.attributes = copy;
660
+ } catch {
661
+ return stripAttributes(attrs, rule);
662
+ }
663
+ if (holder.attributes !== copy) return stripAttributes(attrs, rule);
664
+ return stripAttributes(copy, rule);
665
+ }
356
666
  function stripContent(span) {
357
667
  let stripped = 0;
358
668
  if (span.attributes && typeof span.attributes === "object") {
@@ -361,14 +671,15 @@ function stripContent(span) {
361
671
  if (Array.isArray(span.events)) {
362
672
  for (const event of span.events) {
363
673
  if (event?.attributes && typeof event.attributes === "object") {
364
- stripped += stripAttributes(event.attributes);
674
+ const messageEvent = typeof event.name === "string" && isContentEvent(event.name);
675
+ stripped += stripOwned(event, messageEvent ? isContentEventAttribute : isContentKey);
365
676
  }
366
677
  }
367
678
  }
368
679
  if (Array.isArray(span.links)) {
369
680
  for (const link of span.links) {
370
681
  if (link?.attributes && typeof link.attributes === "object") {
371
- stripped += stripAttributes(link.attributes);
682
+ stripped += stripOwned(link);
372
683
  }
373
684
  }
374
685
  }
@@ -560,6 +871,12 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
560
871
  _beforeExitHandler = null;
561
872
  // Retry tracking for failed batches (Audit #5)
562
873
  _retryCounts = /* @__PURE__ */ new Map();
874
+ /**
875
+ * The HTTP requests that the failed rounds of each re-queued span sent, by span id (issue
876
+ * #57). It has the same life as `_retryCounts`: `_forgetRetry` ends both. NaN = a round for
877
+ * which the exporter did not say. Empty for an exporter that does not state it.
878
+ */
879
+ _retryRequests = /* @__PURE__ */ new Map();
563
880
  static MAX_RETRIES = 3;
564
881
  _lastRefusalWarnAt = Number.NEGATIVE_INFINITY;
565
882
  _lastUnackWarnAt = Number.NEGATIVE_INFINITY;
@@ -774,6 +1091,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
774
1091
  await shutdownExporter(exporter, Math.max(0, shutdownDeadline - Date.now()));
775
1092
  }
776
1093
  this._retryCounts.clear();
1094
+ this._retryRequests.clear();
777
1095
  debug(
778
1096
  `BatchSpanProcessor shutdown. Exported: ${this.exportedSpans}, Dropped: ${this.droppedSpans}, Failed: ${this.failedExports}`
779
1097
  );
@@ -790,7 +1108,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
790
1108
  if (this._queue.length >= this._maxQueueSize) {
791
1109
  if (this._quotaPaused()) {
792
1110
  const oldest = this._queue.shift();
793
- if (oldest !== void 0) this._retryCounts.delete(oldest.spanId);
1111
+ if (oldest !== void 0) this._forgetRetry(oldest.spanId);
794
1112
  this._recordDropped("quota_exceeded");
795
1113
  for (const exporter of this._exporters) {
796
1114
  try {
@@ -985,13 +1303,37 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
985
1303
  }
986
1304
  }
987
1305
  }
988
- /** The requests in one export round, when every exporter that delivers states it. */
989
- _requestsPerRound() {
1306
+ /** The one exporter that delivers, when there is exactly one. */
1307
+ _soleDeliverer() {
990
1308
  const delivering = this._exporters.filter((e) => e.countsAsDelivery !== false);
991
- if (delivering.length !== 1) return void 0;
992
- const n = delivering[0].attemptsPerExport;
1309
+ return delivering.length === 1 ? delivering[0] : void 0;
1310
+ }
1311
+ /** The most requests in one export round, when every exporter that delivers states it. */
1312
+ _requestsPerRound() {
1313
+ const n = this._soleDeliverer()?.attemptsPerExport;
993
1314
  return typeof n === "number" && Number.isFinite(n) && n > 0 ? n : void 0;
994
1315
  }
1316
+ /**
1317
+ * The HTTP requests that the failed round for `batch` really sent (issue #57). `undefined`
1318
+ * when the exporter that delivers does not state it, so that the WARNING keeps its "up to"
1319
+ * text. NaN when the exporter has no record of the round.
1320
+ */
1321
+ _requestsSent(batch) {
1322
+ const exporter = this._soleDeliverer();
1323
+ if (exporter === void 0 || typeof exporter.takeAttempts !== "function") return void 0;
1324
+ try {
1325
+ const n = exporter.takeAttempts(batch);
1326
+ return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : Number.NaN;
1327
+ } catch (e) {
1328
+ debug(`takeAttempts of ${exporter.name} failed: ${describeThrown(e)}`);
1329
+ return Number.NaN;
1330
+ }
1331
+ }
1332
+ /** End the retry tracking of one span (retry-map drain sites 1 and 2 of 3, and the queue drop). */
1333
+ _forgetRetry(spanId) {
1334
+ this._retryCounts.delete(spanId);
1335
+ this._retryRequests.delete(spanId);
1336
+ }
995
1337
  /**
996
1338
  * One export round.
997
1339
  *
@@ -1054,7 +1396,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
1054
1396
  this._countDelivered(batch.length - unserializable.size, ack);
1055
1397
  batchExported = true;
1056
1398
  for (const span of batch) {
1057
- this._retryCounts.delete(span.spanId);
1399
+ this._forgetRetry(span.spanId);
1058
1400
  }
1059
1401
  }
1060
1402
  } else {
@@ -1070,16 +1412,21 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
1070
1412
  if (unserializable.size > 0) this._recordDropped("unacknowledged", unserializable.size);
1071
1413
  if (!batchExported) {
1072
1414
  let dropped = 0;
1415
+ const sent = this._requestsSent(batch);
1416
+ const droppedRequests = [];
1073
1417
  const retryable = batch.filter((span) => {
1074
1418
  if (unserializable.has(span)) return false;
1075
1419
  const count = (this._retryCounts.get(span.spanId) ?? 0) + 1;
1420
+ const requests = sent === void 0 ? void 0 : (this._retryRequests.get(span.spanId) ?? 0) + sent;
1076
1421
  if (count > _BatchSpanProcessor.MAX_RETRIES) {
1077
- this._retryCounts.delete(span.spanId);
1422
+ this._forgetRetry(span.spanId);
1423
+ if (requests !== void 0) droppedRequests.push(requests);
1078
1424
  this._recordDropped("transport_refused");
1079
1425
  dropped++;
1080
1426
  return false;
1081
1427
  }
1082
1428
  this._retryCounts.set(span.spanId, count);
1429
+ if (requests !== void 0) this._retryRequests.set(span.spanId, requests);
1083
1430
  return true;
1084
1431
  });
1085
1432
  if (retryable.length > 0) {
@@ -1092,8 +1439,21 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
1092
1439
  this._lastRefusalWarnAt = now;
1093
1440
  const rounds = _BatchSpanProcessor.MAX_RETRIES + 1;
1094
1441
  const perRound = this._requestsPerRound();
1442
+ const stated = droppedRequests.length > 0 && droppedRequests.every((n) => Number.isFinite(n));
1443
+ let requestsText = "";
1444
+ if (stated) {
1445
+ let lo = droppedRequests[0];
1446
+ let hi = lo;
1447
+ for (const n of droppedRequests) {
1448
+ if (n < lo) lo = n;
1449
+ if (n > hi) hi = n;
1450
+ }
1451
+ requestsText = lo === hi ? ` (${hi} HTTP ${hi === 1 ? "request" : "requests"} sent)` : ` (${lo} to ${hi} HTTP requests sent)`;
1452
+ } else if (perRound !== void 0) {
1453
+ requestsText = ` (up to ${rounds * perRound} HTTP requests: ${perRound} in each round)`;
1454
+ }
1095
1455
  warn(
1096
- `${dropped} span(s) DISCARDED (reason=transport_refused) after ${rounds} failed export rounds each` + (perRound !== void 0 ? ` (up to ${rounds * perRound} HTTP requests: ${perRound} in each round)` : "") + ` \u2014 the endpoint is not accepting spans and the retry budget is spent. ${this.droppedSpansByReason.transport_refused} span(s) discarded this way so far in this process. This data is gone; check the apiKey and the endpoint.`
1456
+ `${dropped} span(s) DISCARDED (reason=transport_refused) after ${rounds} failed export rounds each` + requestsText + ` \u2014 the endpoint is not accepting spans and the retry budget is spent. ${this.droppedSpansByReason.transport_refused} span(s) discarded this way so far in this process. This data is gone; check the apiKey and the endpoint.`
1097
1457
  );
1098
1458
  }
1099
1459
  }
@@ -1151,7 +1511,7 @@ function resolveConfig(config) {
1151
1511
  const environment = config?.environment || env.RISICARE_ENVIRONMENT || "development";
1152
1512
  const serviceName = config?.serviceName ?? env.RISICARE_SERVICE_NAME;
1153
1513
  const serviceVersion = config?.serviceVersion ?? env.RISICARE_SERVICE_VERSION;
1154
- const traceContent = config?.traceContent ?? parseBool(env.RISICARE_TRACE_CONTENT, false);
1514
+ const traceContent = config?.traceContent ?? parseBool(env.RISICARE_TRACE_CONTENT, true);
1155
1515
  const sampleRateRaw = config?.sampleRate ?? parseFloat(env.RISICARE_SAMPLE_RATE ?? "1.0");
1156
1516
  const debug2 = config?.debug ?? parseBool(env.RISICARE_DEBUG, false);
1157
1517
  const compress = config?.compress ?? parseBool(env.RISICARE_COMPRESS, false);
@@ -2356,7 +2716,7 @@ function markCancel(span, error) {
2356
2716
  }
2357
2717
 
2358
2718
  // src/version.ts
2359
- var SDK_VERSION = "0.9.1";
2719
+ var SDK_VERSION = "0.10.0";
2360
2720
 
2361
2721
  // src/exporters/quota.ts
2362
2722
  var QUOTA_REASON = "monthly_quota_exceeded";
@@ -2501,6 +2861,8 @@ var HttpExporter = class {
2501
2861
  _calls = /* @__PURE__ */ new Map();
2502
2862
  /** The ack of each finished call, by its batch. Read once by `takeAck(spans)`. */
2503
2863
  _acks = /* @__PURE__ */ new WeakMap();
2864
+ /** The requests that each finished call sent, by its batch. Read once by `takeAttempts(spans)`. */
2865
+ _requests = /* @__PURE__ */ new WeakMap();
2504
2866
  /** The batch processor dropped span(s) from a full queue in the quota pause (S-1). */
2505
2867
  noteQuotaDrop(count = 1) {
2506
2868
  this._quota.addDrops(count);
@@ -2552,6 +2914,18 @@ var HttpExporter = class {
2552
2914
  get attemptsPerExport() {
2553
2915
  return this._maxRetries;
2554
2916
  }
2917
+ /**
2918
+ * Returns the number of HTTP requests that the `export()` call for `spans` sent, and clears
2919
+ * it. This is the number that was sent, not the most that the call may send
2920
+ * (`attemptsPerExport`): a 401 or 403 stops the loop after one request, and an open circuit
2921
+ * breaker sends none. Returns `null` when no call is on record for `spans`. The answer is
2922
+ * kept per batch, as `takeAck` keeps the ack.
2923
+ */
2924
+ takeAttempts(spans) {
2925
+ const n = this._requests.get(spans) ?? null;
2926
+ this._requests.delete(spans);
2927
+ return n;
2928
+ }
2555
2929
  /**
2556
2930
  * Returns the counts of the ack that the `export()` call for `spans` received, and clears
2557
2931
  * them. The answer is kept per batch, not on the instance: two processors that share this
@@ -2596,13 +2970,15 @@ var HttpExporter = class {
2596
2970
  misroute: null,
2597
2971
  noRetry: false,
2598
2972
  status: null,
2599
- error: null
2973
+ error: null,
2974
+ attempts: 0
2600
2975
  };
2601
2976
  this._calls.set(spans, call);
2602
2977
  try {
2603
2978
  return await this._export(spans, call);
2604
2979
  } finally {
2605
2980
  this._calls.delete(spans);
2981
+ this._requests.set(spans, this._endpointHasCredentials ? 0 : call.attempts);
2606
2982
  }
2607
2983
  }
2608
2984
  async _export(spans, call) {
@@ -2642,14 +3018,13 @@ var HttpExporter = class {
2642
3018
  isHalfOpen = true;
2643
3019
  }
2644
3020
  const maxAttempts = isHalfOpen ? 1 : this._maxRetries;
2645
- let attempts = 0;
2646
3021
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
2647
3022
  call.refusalAfterMs = null;
2648
3023
  call.misroute = null;
2649
3024
  call.noRetry = false;
2650
3025
  call.status = null;
2651
3026
  call.error = null;
2652
- attempts++;
3027
+ call.attempts++;
2653
3028
  const result = await this._sendRequest(payload, parts.length, call, spans);
2654
3029
  if (cancelled.aborted) {
2655
3030
  this._acks.delete(spans);
@@ -2671,7 +3046,7 @@ var HttpExporter = class {
2671
3046
  }
2672
3047
  if (call.refusalAfterMs !== null) {
2673
3048
  warn(
2674
- `Risicare: the ingest endpoint refused this batch for capacity (HTTP 429/503) after ${attempts} attempt(s). This is a healthy server shedding load, not an outage. This export of the batch failed; the circuit breaker does not count it. Reduce batch size or export rate if it persists.`
3049
+ `Risicare: the ingest endpoint refused this batch for capacity (HTTP 429/503) after ${call.attempts} attempt(s). This is a healthy server shedding load, not an outage. This export of the batch failed; the circuit breaker does not count it. Reduce batch size or export rate if it persists.`
2675
3050
  );
2676
3051
  return "failure" /* FAILURE */;
2677
3052
  }
@@ -4437,7 +4812,10 @@ function init(config) {
4437
4812
  "environment",
4438
4813
  "serviceName",
4439
4814
  "serviceVersion",
4440
- "sampleRate"
4815
+ "sampleRate",
4816
+ // Capture is on by default (R9): a library's early init() must not
4817
+ // make the program's traceContent: false void in silence.
4818
+ "traceContent"
4441
4819
  ];
4442
4820
  for (const k of checkedKeys) {
4443
4821
  if (incoming[k] !== existing.config[k]) {