risicare 0.5.2 → 0.7.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 (41) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +43 -10
  3. package/dist/frameworks/instructor.cjs.map +1 -1
  4. package/dist/frameworks/instructor.js.map +1 -1
  5. package/dist/frameworks/langchain.cjs.map +1 -1
  6. package/dist/frameworks/langchain.js.map +1 -1
  7. package/dist/frameworks/langgraph.cjs.map +1 -1
  8. package/dist/frameworks/langgraph.js.map +1 -1
  9. package/dist/frameworks/llamaindex.cjs.map +1 -1
  10. package/dist/frameworks/llamaindex.js.map +1 -1
  11. package/dist/index.cjs +185 -24
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +16 -2
  14. package/dist/index.d.ts +16 -2
  15. package/dist/index.js +185 -24
  16. package/dist/index.js.map +1 -1
  17. package/dist/providers/anthropic/index.cjs.map +1 -1
  18. package/dist/providers/anthropic/index.js.map +1 -1
  19. package/dist/providers/bedrock/index.cjs.map +1 -1
  20. package/dist/providers/bedrock/index.js.map +1 -1
  21. package/dist/providers/cerebras/index.cjs.map +1 -1
  22. package/dist/providers/cerebras/index.js.map +1 -1
  23. package/dist/providers/cohere/index.cjs.map +1 -1
  24. package/dist/providers/cohere/index.js.map +1 -1
  25. package/dist/providers/google/index.cjs.map +1 -1
  26. package/dist/providers/google/index.js.map +1 -1
  27. package/dist/providers/groq/index.cjs.map +1 -1
  28. package/dist/providers/groq/index.js.map +1 -1
  29. package/dist/providers/huggingface/index.cjs.map +1 -1
  30. package/dist/providers/huggingface/index.js.map +1 -1
  31. package/dist/providers/mistral/index.cjs.map +1 -1
  32. package/dist/providers/mistral/index.js.map +1 -1
  33. package/dist/providers/ollama/index.cjs.map +1 -1
  34. package/dist/providers/ollama/index.js.map +1 -1
  35. package/dist/providers/openai/index.cjs.map +1 -1
  36. package/dist/providers/openai/index.js.map +1 -1
  37. package/dist/providers/together/index.cjs.map +1 -1
  38. package/dist/providers/together/index.js.map +1 -1
  39. package/dist/providers/vercel-ai/index.cjs.map +1 -1
  40. package/dist/providers/vercel-ai/index.js.map +1 -1
  41. package/package.json +5 -12
package/dist/index.d.cts CHANGED
@@ -274,8 +274,14 @@ declare const MASK_ERROR_MARKER = "<risicare:mask-error>";
274
274
  interface RisicareConfig {
275
275
  /** API key for authentication (format: "rsk-{random}"). Each key is scoped to one project. */
276
276
  apiKey?: string;
277
- /** Gateway endpoint URL */
277
+ /** Ingest gateway URL. It receives spans only. */
278
278
  endpoint?: string;
279
+ /**
280
+ * Api URL. It serves active-fix reads and scores.
281
+ * Falls back to `endpoint` when only that one is given, so a single-host
282
+ * deployment keeps every URL shape on the one host.
283
+ */
284
+ apiEndpoint?: string;
279
285
  /**
280
286
  * @deprecated Project is determined by your API key. This field is ignored
281
287
  * by the gateway and will be removed in v1.0. Use `serviceName` and
@@ -311,6 +317,14 @@ interface RisicareConfig {
311
317
  debug?: boolean;
312
318
  /** Enable gzip compression for HTTP exports (default: false) */
313
319
  compress?: boolean;
320
+ /**
321
+ * Whether FixRuntime starts (or `RISICARE_FIX_RUNTIME=true`).
322
+ *
323
+ * **Default `false` since 0.7.0** (it started whenever an `apiKey` was set).
324
+ * When true, the SDK polls `/fixes/active` every 60 s and applies the active
325
+ * fixes to LLM calls. When false, nothing polls and nothing is applied.
326
+ */
327
+ fixRuntime?: boolean;
314
328
  /** Custom metadata attached to all spans */
315
329
  metadata?: Record<string, unknown>;
316
330
  /**
@@ -951,7 +965,7 @@ declare function isProviderInstrumentationSuppressed(): boolean;
951
965
  * Port of Python SDK's runtime/config.py adapted for Node.js patterns.
952
966
  */
953
967
  interface FixRuntimeConfig {
954
- /** API endpoint URL (e.g., "https://app.risicare.ai") */
968
+ /** Api URL, serving /v1/fixes/active (e.g., "https://api.risicare.ai") */
955
969
  apiEndpoint: string;
956
970
  /** API key for authentication (format: "rsk-{random}") */
957
971
  apiKey: string;
package/dist/index.d.ts CHANGED
@@ -274,8 +274,14 @@ declare const MASK_ERROR_MARKER = "<risicare:mask-error>";
274
274
  interface RisicareConfig {
275
275
  /** API key for authentication (format: "rsk-{random}"). Each key is scoped to one project. */
276
276
  apiKey?: string;
277
- /** Gateway endpoint URL */
277
+ /** Ingest gateway URL. It receives spans only. */
278
278
  endpoint?: string;
279
+ /**
280
+ * Api URL. It serves active-fix reads and scores.
281
+ * Falls back to `endpoint` when only that one is given, so a single-host
282
+ * deployment keeps every URL shape on the one host.
283
+ */
284
+ apiEndpoint?: string;
279
285
  /**
280
286
  * @deprecated Project is determined by your API key. This field is ignored
281
287
  * by the gateway and will be removed in v1.0. Use `serviceName` and
@@ -311,6 +317,14 @@ interface RisicareConfig {
311
317
  debug?: boolean;
312
318
  /** Enable gzip compression for HTTP exports (default: false) */
313
319
  compress?: boolean;
320
+ /**
321
+ * Whether FixRuntime starts (or `RISICARE_FIX_RUNTIME=true`).
322
+ *
323
+ * **Default `false` since 0.7.0** (it started whenever an `apiKey` was set).
324
+ * When true, the SDK polls `/fixes/active` every 60 s and applies the active
325
+ * fixes to LLM calls. When false, nothing polls and nothing is applied.
326
+ */
327
+ fixRuntime?: boolean;
314
328
  /** Custom metadata attached to all spans */
315
329
  metadata?: Record<string, unknown>;
316
330
  /**
@@ -951,7 +965,7 @@ declare function isProviderInstrumentationSuppressed(): boolean;
951
965
  * Port of Python SDK's runtime/config.py adapted for Node.js patterns.
952
966
  */
953
967
  interface FixRuntimeConfig {
954
- /** API endpoint URL (e.g., "https://app.risicare.ai") */
968
+ /** Api URL, serving /v1/fixes/active (e.g., "https://api.risicare.ai") */
955
969
  apiEndpoint: string;
956
970
  /** API key for authentication (format: "rsk-{random}") */
957
971
  apiKey: string;
package/dist/index.js CHANGED
@@ -130,15 +130,121 @@ function applyMask(span, mask, onError) {
130
130
  markMasked(span);
131
131
  }
132
132
  var CONTENT_KEYS_EXACT = /* @__PURE__ */ new Set([
133
+ // spec v1
133
134
  "gen_ai.system_prompt",
134
- "gen_ai.prompt.message"
135
+ // anthropic, bedrock
136
+ "gen_ai.prompt.message",
137
+ // cohere
138
+ "gen_ai.prompt",
139
+ // OTel GenAI (deprecated form)
140
+ "gen_ai.completion",
141
+ "gen_ai.input.messages",
142
+ // OTel GenAI
143
+ "gen_ai.output.messages",
144
+ "gen_ai.system_instructions",
145
+ "gen_ai.tool.call.arguments",
146
+ "gen_ai.tool.call.result",
147
+ "input.value",
148
+ // OpenInference
149
+ "output.value",
150
+ "llm.prompts",
151
+ "llm.prompt_template.template",
152
+ "llm.prompt_template.variables",
153
+ "task_description",
154
+ // CrewAI
155
+ // ⚠ EXTENSION to spec v1: content keys that the Python SDK's integrations emit
156
+ // and that no v1 rule strips. Kept here too, so the two SDKs agree on the rule.
157
+ "framework.crewai.task_description",
158
+ "framework.crewai.agent_goal",
159
+ "framework.crewai.agent_output",
160
+ "framework.crewai.result",
161
+ "framework.autogen.last_message",
162
+ "framework.autogen.reply",
163
+ "framework.autogen.response",
164
+ "framework.openai_agents.input",
165
+ "framework.openai_agents.output",
166
+ "framework.dspy.signature",
167
+ "gen_ai.request.messages",
168
+ "agent.action.input",
169
+ "agent.action.log",
170
+ "agent.finish.output",
171
+ "tool.input",
172
+ "tool.output",
173
+ "retriever.query",
174
+ "retriever.first_doc",
175
+ // ⚠ FAIL CLOSED: third-party content keys that no other rule strips.
176
+ "gen_ai.retrieval.query.text",
177
+ // OTel GenAI
178
+ "gen_ai.retrieval.documents",
179
+ "gen_ai.evaluation.explanation",
180
+ "llm.function_call",
181
+ // OpenInference
182
+ "llm.choices",
183
+ "reranker.query",
184
+ "audio.transcript",
185
+ "traceloop.entity.input",
186
+ // OpenLLMetry
187
+ "traceloop.entity.output"
135
188
  ]);
189
+ var CONTENT_LAST_SEGMENT_IN_CONTEXT = /* @__PURE__ */ new Map([
190
+ ["function_call_arguments_json", /* @__PURE__ */ new Set()],
191
+ // OpenInference `message.*`
192
+ ["data", /* @__PURE__ */ new Set(["message_content"])],
193
+ ["url", /* @__PURE__ */ new Set(["image"])],
194
+ // `image.url` can hold base64 data
195
+ ["metadata", /* @__PURE__ */ new Set(["document", "documents"])]
196
+ ]);
197
+ var CONTENT_CONTAINER_SEGMENTS = /* @__PURE__ */ new Set([
198
+ "message",
199
+ "messages",
200
+ "message_content",
201
+ "contents",
202
+ "embedding",
203
+ "embeddings",
204
+ "document",
205
+ "documents",
206
+ "tool_call",
207
+ "tool_calls",
208
+ "function"
209
+ ]);
210
+ var CONTENT_KEYS_KEEP_EXACT = /* @__PURE__ */ new Set([
211
+ "gen_ai.response.content_type",
212
+ "gen_ai.response.content_blocks",
213
+ "gen_ai.prompt.parts",
214
+ "gen_ai.prompt.count",
215
+ "gen_ai.response.choices",
216
+ "gen_ai.completion.tool_calls"
217
+ ]);
218
+ var KEEP_LAST_SEGMENTS = /* @__PURE__ */ new Set([
219
+ "role",
220
+ "name",
221
+ "id",
222
+ "type",
223
+ "count",
224
+ "index",
225
+ "model",
226
+ "finish_reason",
227
+ "mime_type"
228
+ ]);
229
+ var KEEP_LAST_SUFFIXES = ["_length", "_tokens", "_count"];
136
230
  var CONTENT_OMITTED_MARKER = "<risicare:content-omitted>";
137
231
  function isContentKey(key) {
138
- if (CONTENT_KEYS_EXACT.has(key)) return true;
139
- const lastSegment = key.slice(key.lastIndexOf(".") + 1);
140
- if (lastSegment === "content") return true;
141
- return key.endsWith("_content");
232
+ if (CONTENT_KEYS_KEEP_EXACT.has(key)) return false;
233
+ if (CONTENT_KEYS_EXACT.has(key) || key.endsWith("_content")) return true;
234
+ const segments = key.split(".");
235
+ const last = segments[segments.length - 1];
236
+ const context = CONTENT_LAST_SEGMENT_IN_CONTEXT.get(last);
237
+ if (context && (context.size === 0 || segments.slice(0, -1).some((s) => context.has(s)))) {
238
+ return true;
239
+ }
240
+ if (KEEP_LAST_SEGMENTS.has(last) || KEEP_LAST_SUFFIXES.some((x) => last.endsWith(x))) {
241
+ return false;
242
+ }
243
+ if (last === "content") return true;
244
+ if (last === "text" || last === "arguments") {
245
+ return segments.slice(0, -1).some((s) => CONTENT_CONTAINER_SEGMENTS.has(s));
246
+ }
247
+ return false;
142
248
  }
143
249
  function stripAttributes(attrs) {
144
250
  let n = 0;
@@ -621,11 +727,13 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
621
727
  };
622
728
 
623
729
  // src/config.ts
624
- var DEFAULT_ENDPOINT = "https://app.risicare.ai";
730
+ var DEFAULT_ENDPOINT = "https://ingest.risicare.ai";
731
+ var DEFAULT_API_ENDPOINT = "https://api.risicare.ai";
625
732
  function resolveConfig(config) {
626
733
  const env = process.env;
627
734
  const apiKey = config?.apiKey ?? env.RISICARE_API_KEY;
628
735
  const endpoint = config?.endpoint ?? env.RISICARE_ENDPOINT ?? DEFAULT_ENDPOINT;
736
+ const apiEndpoint = config?.apiEndpoint ?? env.RISICARE_API_ENDPOINT ?? config?.endpoint ?? env.RISICARE_ENDPOINT ?? DEFAULT_API_ENDPOINT;
629
737
  const projectId = config?.projectId ?? env.RISICARE_PROJECT_ID;
630
738
  if (config?.projectId || env.RISICARE_PROJECT_ID) {
631
739
  console.warn(
@@ -639,6 +747,7 @@ function resolveConfig(config) {
639
747
  const sampleRateRaw = config?.sampleRate ?? parseFloat(env.RISICARE_SAMPLE_RATE ?? "1.0");
640
748
  const debug2 = config?.debug ?? parseBool(env.RISICARE_DEBUG, false);
641
749
  const compress = config?.compress ?? parseBool(env.RISICARE_COMPRESS, false);
750
+ const fixRuntime = config?.fixRuntime ?? parseBool(env.RISICARE_FIX_RUNTIME, false);
642
751
  const batchSizeRaw = config?.batchSize ?? parseNumericEnv(env.RISICARE_BATCH_SIZE, DEFAULT_BATCH_SIZE);
643
752
  const batchTimeoutMsRaw = config?.batchTimeoutMs ?? parseNumericEnv(env.RISICARE_BATCH_TIMEOUT_MS, 1e3);
644
753
  const maxQueueSizeRaw = config?.maxQueueSize ?? parseNumericEnv(env.RISICARE_MAX_QUEUE_SIZE, 1e4);
@@ -662,6 +771,7 @@ function resolveConfig(config) {
662
771
  return {
663
772
  apiKey: apiKey ?? "",
664
773
  endpoint,
774
+ apiEndpoint,
665
775
  projectId: projectId ?? "",
666
776
  environment,
667
777
  serviceName: serviceName ?? "",
@@ -674,6 +784,7 @@ function resolveConfig(config) {
674
784
  maxQueueSize,
675
785
  debug: debug2,
676
786
  compress,
787
+ fixRuntime,
677
788
  metadata: config?.metadata ?? {},
678
789
  // No env fallback — see the field's note on RisicareConfig.
679
790
  mask: config?.mask
@@ -1757,13 +1868,14 @@ var Tracer = class {
1757
1868
  };
1758
1869
 
1759
1870
  // src/version.ts
1760
- var SDK_VERSION = "0.5.2";
1871
+ var SDK_VERSION = "0.7.0";
1761
1872
 
1762
1873
  // src/exporters/http.ts
1763
1874
  var CAPACITY_REFUSAL_STATUSES = /* @__PURE__ */ new Set([429, 503]);
1764
1875
  var RETRY_AFTER_CEILING_MS = 1e4;
1765
1876
  var REFUSAL_BACKOFF_BASE_MS = 1e3;
1766
1877
  var REFUSAL_NO_HINT = -1;
1878
+ var MISROUTE_WARN_WINDOW_MS = 3e5;
1767
1879
  var HttpExporter = class {
1768
1880
  name = "http";
1769
1881
  _endpoint;
@@ -1791,6 +1903,9 @@ var HttpExporter = class {
1791
1903
  * same reason (its `_send_request` signature is pin-locked).
1792
1904
  */
1793
1905
  _lastRefusalAfterMs = null;
1906
+ /** Set by `_sendRequest` on a MISROUTE: a short description of the answer. `null` = none. */
1907
+ _lastMisroute = null;
1908
+ _lastMisrouteWarnAt = -Infinity;
1794
1909
  _circuitOpenUntil = 0;
1795
1910
  _circuitBreakerThreshold = 5;
1796
1911
  _circuitBreakerCooldownMs = 6e4;
@@ -1821,11 +1936,13 @@ var HttpExporter = class {
1821
1936
  const maxAttempts = isHalfOpen ? 1 : this._maxRetries;
1822
1937
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
1823
1938
  this._lastRefusalAfterMs = null;
1939
+ this._lastMisroute = null;
1824
1940
  const result = await this._sendRequest(body);
1825
1941
  if (result === "success" /* SUCCESS */) {
1826
1942
  this._consecutiveFailures = 0;
1827
1943
  return result;
1828
1944
  }
1945
+ if (this._lastMisroute !== null) break;
1829
1946
  if (attempt < maxAttempts - 1) {
1830
1947
  const refusal = this._lastRefusalAfterMs;
1831
1948
  const delay = refusal === null ? 100 * Math.pow(2, attempt) : refusal === REFUSAL_NO_HINT ? REFUSAL_BACKOFF_BASE_MS * Math.pow(2, attempt) : refusal;
@@ -1840,6 +1957,14 @@ var HttpExporter = class {
1840
1957
  );
1841
1958
  return "failure" /* FAILURE */;
1842
1959
  }
1960
+ const misroute = this._lastMisroute;
1961
+ this._lastMisroute = null;
1962
+ if (misroute !== null && Date.now() - this._lastMisrouteWarnAt > MISROUTE_WARN_WINDOW_MS) {
1963
+ this._lastMisrouteWarnAt = Date.now();
1964
+ warn(
1965
+ `Risicare: spans are NOT reaching ${this._endpoint}. It answered POST /v1/spans with ${misroute}. That is not the Risicare ingest gateway, so the endpoint is probably wrong (for example the dashboard URL instead of the ingest gateway URL). The SDK does not follow redirects, and this batch is counted as NOT delivered. Set endpoint or RISICARE_ENDPOINT to the ingest gateway URL.`
1966
+ );
1967
+ }
1843
1968
  this._consecutiveFailures++;
1844
1969
  if (this._consecutiveFailures >= this._circuitBreakerThreshold) {
1845
1970
  this._circuitOpenUntil = Date.now() + this._circuitBreakerCooldownMs;
@@ -1849,6 +1974,12 @@ var HttpExporter = class {
1849
1974
  }
1850
1975
  return "failure" /* FAILURE */;
1851
1976
  }
1977
+ /** Record a MISROUTE for the retry loop and the breaker. Always returns FAILURE. */
1978
+ _noteMisroute(answer) {
1979
+ this._lastMisroute = answer.slice(0, 300);
1980
+ debug(`Ingest misroute: ${this._lastMisroute}`);
1981
+ return "failure" /* FAILURE */;
1982
+ }
1852
1983
  /**
1853
1984
  * Record a CAPACITY REFUSAL for the retry loop. Returns true if it was one.
1854
1985
  *
@@ -1873,7 +2004,13 @@ var HttpExporter = class {
1873
2004
  const url = `${this._endpoint}/v1/spans`;
1874
2005
  const headers = {
1875
2006
  "Content-Type": "application/json",
1876
- "User-Agent": `risicare-js/${SDK_VERSION} node/${process.version}`
2007
+ "User-Agent": `risicare-js/${SDK_VERSION} node/${process.version}`,
2008
+ // F-SDKVER-001 parity. Python's ingest exporter has always sent
2009
+ // `X-Risicare-SDK-Version`; JS sent only a User-Agent, so the two SDKs
2010
+ // disagreed about how a client identifies itself. A parser-free header is
2011
+ // strictly easier for the gateway to consume than picking a version out of
2012
+ // a UA string.
2013
+ "X-Risicare-SDK-Version": SDK_VERSION
1877
2014
  };
1878
2015
  if (this._apiKey) {
1879
2016
  headers["Authorization"] = `Bearer ${this._apiKey}`;
@@ -1895,11 +2032,23 @@ var HttpExporter = class {
1895
2032
  method: "POST",
1896
2033
  headers,
1897
2034
  body: payload,
1898
- signal: controller.signal
2035
+ signal: controller.signal,
2036
+ // Never follow: a redirect is a misroute (see MISROUTE_WARN_WINDOW_MS). Node returns
2037
+ // the 3xx itself; a browser-like runtime returns type 'opaqueredirect' with status 0.
2038
+ redirect: "manual"
1899
2039
  });
1900
2040
  clearTimeout(timeoutId);
1901
- if (response.status < 300) {
1902
- return await checkAck(response);
2041
+ const redirected = response.type === "opaqueredirect";
2042
+ if (redirected || response.status >= 300 && response.status < 400) {
2043
+ const location = response.headers?.get?.("Location");
2044
+ const target = location ? location.slice(0, 200) : "no Location header";
2045
+ return this._noteMisroute(`HTTP ${response.status || "3xx"}, a redirect to ${target}`);
2046
+ }
2047
+ if (response.status >= 200 && response.status < 300) {
2048
+ const ack = await checkAck(response);
2049
+ return ack === null ? this._noteMisroute(
2050
+ `HTTP ${response.status} and a body that is not a Risicare ack (content-type: ${response.headers?.get?.("Content-Type") || "none"})`
2051
+ ) : ack;
1903
2052
  } else if (response.status === 408 || response.status === 504) {
1904
2053
  debug(`HTTP export timeout: ${response.status}`);
1905
2054
  return "timeout" /* TIMEOUT */;
@@ -1926,17 +2075,16 @@ async function checkAck(response) {
1926
2075
  try {
1927
2076
  payload = await response.json();
1928
2077
  } catch {
1929
- return "success" /* SUCCESS */;
2078
+ return null;
1930
2079
  }
1931
2080
  if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
1932
- return "success" /* SUCCESS */;
2081
+ return null;
1933
2082
  }
1934
2083
  const body = payload;
1935
2084
  const accepted = asCount(body.accepted);
1936
2085
  const rejected = asCount(body.rejected);
1937
- if (accepted === void 0 || rejected === void 0 || rejected <= 0) {
1938
- return "success" /* SUCCESS */;
1939
- }
2086
+ if (accepted === void 0 || rejected === void 0) return null;
2087
+ if (rejected === 0) return "success" /* SUCCESS */;
1940
2088
  const errors = body.errors;
1941
2089
  const detail = typeof body.errorMessage === "string" && body.errorMessage || typeof body.error_message === "string" && body.error_message || (Array.isArray(errors) && errors.length > 0 ? JSON.stringify(errors[0]) : "") || "No reason was returned.";
1942
2090
  const total = accepted + rejected;
@@ -2637,7 +2785,7 @@ var FixLoader = class _FixLoader {
2637
2785
  }
2638
2786
  try {
2639
2787
  const endpoint = this._config.apiEndpoint.replace(/\/+$/, "");
2640
- const url = `${endpoint}/api/v1/fixes/active`;
2788
+ const url = `${endpoint}/v1/fixes/active`;
2641
2789
  const controller = new AbortController();
2642
2790
  const timeoutId = setTimeout(
2643
2791
  () => controller.abort(),
@@ -3049,10 +3197,10 @@ var RisicareClient = class {
3049
3197
  serviceVersion: this.config.serviceVersion
3050
3198
  });
3051
3199
  this.processor.start();
3052
- if (this.config.apiKey && this.config.enabled) {
3200
+ if (this.config.apiKey && this.config.enabled && this.config.fixRuntime) {
3053
3201
  try {
3054
3202
  initFixRuntime({
3055
- apiEndpoint: this.config.endpoint,
3203
+ apiEndpoint: this.config.apiEndpoint,
3056
3204
  apiKey: this.config.apiKey,
3057
3205
  enabled: true,
3058
3206
  debug: this.config.debug
@@ -3074,6 +3222,11 @@ var RisicareClient = class {
3074
3222
  this._registerShutdownHooks();
3075
3223
  setDebug(this.config.debug);
3076
3224
  debug(`Initialized: enabled=${this.config.enabled}, endpoint=${this.config.endpoint}`);
3225
+ if (!this.config.fixRuntime) {
3226
+ debug(
3227
+ "FixRuntime is off: nothing polls /fixes/active and no fix is applied. Opt in with fixRuntime: true or RISICARE_FIX_RUNTIME=true."
3228
+ );
3229
+ }
3077
3230
  }
3078
3231
  get enabled() {
3079
3232
  return this.tracer.enabled;
@@ -3312,6 +3465,7 @@ function reportError(error, options) {
3312
3465
  span.setAttribute("error.message", err.message.slice(0, 2e3));
3313
3466
  if (err.stack) span.setAttribute("error.stack", err.stack.slice(0, 4e3));
3314
3467
  span.setAttribute("risicare.reported_error", true);
3468
+ attachErrorCode(span, err);
3315
3469
  if (options?.attributes) {
3316
3470
  for (const [k, v] of Object.entries(options.attributes)) {
3317
3471
  span.setAttribute(k, v);
@@ -3334,8 +3488,8 @@ function score(traceId, name, value, options) {
3334
3488
  }
3335
3489
  const client = getClient();
3336
3490
  if (!client?.enabled || !client.config.apiKey) return;
3337
- const endpoint = client.config.endpoint.replace(/\/$/, "");
3338
- const url = `${endpoint}/api/v1/scores`;
3491
+ const endpoint = client.config.apiEndpoint.replace(/\/+$/, "");
3492
+ const url = `${endpoint}/v1/scores`;
3339
3493
  let comment = options?.comment;
3340
3494
  if (comment !== void 0 && client.config.mask) {
3341
3495
  comment = maskText(client.config.mask, SCORE_COMMENT_KEY, comment);
@@ -3352,7 +3506,14 @@ function score(traceId, name, value, options) {
3352
3506
  method: "POST",
3353
3507
  headers: {
3354
3508
  "Content-Type": "application/json",
3355
- "Authorization": `Bearer ${client.config.apiKey}`
3509
+ "Authorization": `Bearer ${client.config.apiKey}`,
3510
+ // F-SDKVER-001 — see the Python twin. `score()` reaches the FastAPI
3511
+ // server under /v1/, which `main.py::audit_logging_middleware` audits
3512
+ // into `audit_logs.user_agent`; ingest reaches the Rust gateway, which
3513
+ // discards it. This is the one client-identity visible with no gateway
3514
+ // change.
3515
+ "User-Agent": `risicare-js/${SDK_VERSION} node/${process.version}`,
3516
+ "X-Risicare-SDK-Version": SDK_VERSION
3356
3517
  },
3357
3518
  body
3358
3519
  }).catch((err) => debug(`score: send failed: ${err}`));
@@ -3505,14 +3666,14 @@ function withSession(options, fn) {
3505
3666
  parentSessionId: options.parentSessionId,
3506
3667
  turnNumber: options.turnNumber ?? 1
3507
3668
  };
3508
- return runWithContext({ session: session2 }, fn);
3669
+ return runWithContext({ session: session2 }, () => withSessionEndMarker(fn));
3509
3670
  }
3510
3671
 
3511
3672
  // src/decorators/session.ts
3512
3673
  function _wrapSession(optionsOrResolver, fn) {
3513
3674
  return (...args) => {
3514
3675
  const options = typeof optionsOrResolver === "function" ? optionsOrResolver(...args) : optionsOrResolver;
3515
- return withSession(options, () => withSessionEndMarker(() => fn(...args)));
3676
+ return withSession(options, () => fn(...args));
3516
3677
  };
3517
3678
  }
3518
3679
  function session(optionsOrResolver, fn) {