@opengeni/observability 6.8.0 → 6.9.1-canary.41937124785001

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.
@@ -13,6 +13,12 @@
13
13
  * code-written message with every variable part (window titles, page text,
14
14
  * paths, free-text reasons) redacted, so an operator can tell driver failures
15
15
  * apart. The message is redacted again at the log boundary.
16
+ *
17
+ * A second reviewed exception: an API request that fails with an unclassified
18
+ * internal error (500 `internal_error`, not mapped to a response by any route)
19
+ * logs its cause's message as `causeMessage`, so the server log says why. The
20
+ * message is scrubbed of credentials and query strings and bounded exactly
21
+ * like a web client error message, and only the server log carries it.
16
22
  */
17
23
  /** Reviewed error classes whose names carry no data. Wrappers that only
18
24
  * translate another error into a response are skipped to reach the cause. */
@@ -31,5 +37,18 @@ export type ErrorCauseAttributes = {
31
37
  };
32
38
  /** Classify the first non-wrapper error in a cause chain. */
33
39
  export declare function errorCauseAttributes(error: unknown): ErrorCauseAttributes;
40
+ /** Largest UTF-8 byte length of a logged cause message. */
41
+ export declare const ERROR_CAUSE_MESSAGE_MAX_BYTES: 1024;
42
+ /**
43
+ * The scrubbed, bounded message of the first non-wrapper error in a cause
44
+ * chain, for the server log of an unclassified internal error only. A query
45
+ * builder's error quotes its SQL and parameters, so its database cause's
46
+ * message is used instead.
47
+ */
48
+ export declare function errorCauseMessage(error: unknown): string | undefined;
34
49
  /** Re-validate attributes at the log boundary; callers may pass anything. */
35
50
  export declare function projectErrorCauseAttributes(attributes: Record<string, unknown>): ErrorCauseAttributes;
51
+ /** Re-validate a cause message at the log boundary: only an exact projection passes. */
52
+ export declare function projectErrorCauseMessage(attributes: Record<string, unknown>): {
53
+ causeMessage?: string;
54
+ };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Registry } from "prom-client";
2
2
  import { type ChildSpanRecorder, type SpanKind, type TraceContext } from "./trace-context.js";
3
3
  import { type FailureDiagnosticInput } from "./failure-diagnostic.js";
4
- export { errorCauseAttributes, PUBLIC_ERROR_CAUSE_NAMES, PUBLIC_INTERACTION_ERROR_CODES, type ErrorCauseAttributes, } from "./error-cause.js";
4
+ export { errorCauseAttributes, errorCauseMessage, ERROR_CAUSE_MESSAGE_MAX_BYTES, PUBLIC_ERROR_CAUSE_NAMES, PUBLIC_INTERACTION_ERROR_CODES, type ErrorCauseAttributes, } from "./error-cause.js";
5
5
  export type { FailureDiagnosticInput } from "./failure-diagnostic.js";
6
6
  export { AGENT_TOOL_CALL_OUTCOMES, AGENT_TOOL_METRIC_FAMILIES, agentToolCallOutcome, agentToolMetricFamily, recordAgentToolCall, type AgentToolCallOutcome, type AgentToolMetricFamily, } from "./agent-tool-metrics.js";
7
7
  export { failureDiagnostic } from "./failure-diagnostic.js";
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  CLIENT_DESKTOP_APP_VERSION_PATTERN,
7
7
  CLIENT_ERROR_REVISION_PATTERN,
8
8
  CLIENT_ERROR_ROUTE_PATTERN,
9
- isProjectedClientErrorText
9
+ isProjectedClientErrorText as isProjectedClientErrorText2
10
10
  } from "@opengeni/contracts/client-error-report";
11
11
 
12
12
  // src/trace-context.ts
@@ -375,6 +375,12 @@ import {
375
375
  parseInteractionDriverDiagnostic,
376
376
  redactInteractionDriverMessage
377
377
  } from "@opengeni/contracts";
378
+ import {
379
+ boundClientErrorText,
380
+ CLIENT_ERROR_DETAIL_MAX_BYTES,
381
+ isProjectedClientErrorText,
382
+ scrubClientErrorText
383
+ } from "@opengeni/contracts/client-error-report";
378
384
  var PUBLIC_ERROR_CAUSE_NAMES = /* @__PURE__ */ new Set([
379
385
  "Error",
380
386
  "TypeError",
@@ -436,16 +442,36 @@ var PUBLIC_INTERACTION_ERROR_CODES = /* @__PURE__ */ new Set([
436
442
  var WRAPPER_NAMES = /* @__PURE__ */ new Set(["HTTPException", "ApiHttpError"]);
437
443
  var SQLSTATE = /^[0-9A-Z]{5}$/;
438
444
  function errorCauseAttributes(error) {
445
+ const cause = firstCause(error);
446
+ return cause ? classify(cause.error, cause.name) : {};
447
+ }
448
+ var ERROR_CAUSE_MESSAGE_MAX_BYTES = CLIENT_ERROR_DETAIL_MAX_BYTES.message;
449
+ function errorCauseMessage(error) {
450
+ const cause = firstCause(error);
451
+ if (!cause) return void 0;
452
+ let message = ownValue(cause.error, "message");
453
+ if (cause.name === "DrizzleQueryError") {
454
+ const database = ownValue(cause.error, "cause");
455
+ message = database && typeof database === "object" ? ownValue(database, "message") : void 0;
456
+ }
457
+ if (typeof message !== "string") return void 0;
458
+ const projected = boundClientErrorText(
459
+ scrubClientErrorText(message.slice(0, 16384)).trim(),
460
+ ERROR_CAUSE_MESSAGE_MAX_BYTES
461
+ );
462
+ return projected.length > 0 ? projected : void 0;
463
+ }
464
+ function firstCause(error) {
439
465
  const seen = /* @__PURE__ */ new Set();
440
466
  let current = error;
441
467
  for (let depth = 0; depth < 4 && current && typeof current === "object"; depth += 1) {
442
468
  if (seen.has(current)) break;
443
469
  seen.add(current);
444
470
  const name = reviewedName(current);
445
- if (name === null || !WRAPPER_NAMES.has(name)) return classify(current, name);
471
+ if (name === null || !WRAPPER_NAMES.has(name)) return { error: current, name };
446
472
  current = ownValue(current, "cause");
447
473
  }
448
- return {};
474
+ return null;
449
475
  }
450
476
  function projectErrorCauseAttributes(attributes) {
451
477
  const { causeName, causeCode, causeAgentCode, causeStatus, causeSqlState } = attributes;
@@ -465,6 +491,10 @@ function projectErrorCauseAttributes(attributes) {
465
491
  ...typeof causeSqlState === "string" && SQLSTATE.test(causeSqlState) ? { causeSqlState } : {}
466
492
  };
467
493
  }
494
+ function projectErrorCauseMessage(attributes) {
495
+ const { causeMessage } = attributes;
496
+ return typeof causeMessage === "string" && causeMessage.trim() === causeMessage && isProjectedClientErrorText(causeMessage, "message") ? { causeMessage } : {};
497
+ }
468
498
  function classify(error, name) {
469
499
  if (name === null || !PUBLIC_ERROR_CAUSE_NAMES.has(name)) return {};
470
500
  const result = { causeName: name };
@@ -1504,11 +1534,16 @@ var PUBLIC_TELEMETRY_ATTRIBUTE_KEYS = /* @__PURE__ */ new Set([
1504
1534
  "credentialFromIndex",
1505
1535
  "credentialToIndex",
1506
1536
  "credentialCandidates",
1507
- "credentialStale"
1537
+ "credentialStale",
1538
+ // Refused realtime negotiations (apps/api codex-realtime.ts): the provider's
1539
+ // HTTP status for the failed request.
1540
+ "providerStatus"
1508
1541
  ]);
1509
1542
  var HTTP_REJECTION_CODE_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
1510
1543
  var CPU_PROFILE_FRAMES_PATTERN = /^[\w$<>()[\]:./@ |#*,-]{0,2000}$/;
1511
1544
  var HTTP_REJECTION_REASON_PATTERN = /^(?:permission:[a-z][a-z0-9-]*:[a-z][a-z0-9-]*|control:[a-z][a-z0-9_]{0,31}|[A-Za-z][A-Za-z0-9_.-]{0,63})$/;
1545
+ var REALTIME_PROVIDER_ERROR_TOKEN_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 _.:-]{0,63}$/;
1546
+ var REALTIME_PROVIDER_VALUE_PATTERN = /^[a-z0-9][a-z0-9._-]{0,127}$/i;
1512
1547
  var PUBLIC_TELEMETRY_OPAQUE_ATTRIBUTE_PATTERNS = /* @__PURE__ */ new Map([
1513
1548
  ["mcpCallKey", /^mcp_[0-9a-f]{32}$/],
1514
1549
  ["sandboxLeaseKey", /^slk_[0-9a-f]{32}$/],
@@ -1556,7 +1591,20 @@ var PUBLIC_TELEMETRY_OPAQUE_ATTRIBUTE_PATTERNS = /* @__PURE__ */ new Map([
1556
1591
  // password file could not be read, and its errno code.
1557
1592
  ["databasePool", /^[a-z][a-z0-9-]{0,63}$/],
1558
1593
  ["credentialFile", /^(?:current|previous)$/],
1559
- ["credentialFileErrorCode", /^[A-Z][A-Z0-9_]{0,31}$/]
1594
+ ["credentialFileErrorCode", /^[A-Z][A-Z0-9_]{0,31}$/],
1595
+ // Refused realtime negotiations (apps/api codex-realtime.ts): the failing
1596
+ // stage, the adapter's own code-authored failure message, identifier-shaped
1597
+ // provider error fields, and the provider call parameters with their source.
1598
+ // Never a provider response body, credential, account or request content.
1599
+ ["realtimeStage", /^(?:request|config|call)$/],
1600
+ ["realtimeFailureMessage", /^[A-Za-z][A-Za-z0-9 ._:()/-]{0,159}$/],
1601
+ ["providerErrorCode", REALTIME_PROVIDER_ERROR_TOKEN_PATTERN],
1602
+ ["providerErrorType", REALTIME_PROVIDER_ERROR_TOKEN_PATTERN],
1603
+ ["providerErrorParam", REALTIME_PROVIDER_ERROR_TOKEN_PATTERN],
1604
+ ["realtimeConfigSource", /^(?:remote|fallback)$/],
1605
+ ["realtimeAdvertisedVersion", REALTIME_PROVIDER_VALUE_PATTERN],
1606
+ ["realtimeProviderModel", REALTIME_PROVIDER_VALUE_PATTERN],
1607
+ ["realtimeProviderArchitecture", REALTIME_PROVIDER_VALUE_PATTERN]
1560
1608
  ]);
1561
1609
  var PUBLIC_TELEMETRY_CLIENT_ERROR_TEXT_ATTRIBUTES = /* @__PURE__ */ new Map([
1562
1610
  ["clientErrorName", "name"],
@@ -2622,7 +2670,7 @@ function projectPublicTelemetryAttributes(attributes) {
2622
2670
  if (PUBLIC_TELEMETRY_ATTRIBUTE_KEYS.has(key)) return true;
2623
2671
  const clientErrorField = PUBLIC_TELEMETRY_CLIENT_ERROR_TEXT_ATTRIBUTES.get(key);
2624
2672
  if (clientErrorField) {
2625
- return typeof value === "string" && isProjectedClientErrorText(value, clientErrorField);
2673
+ return typeof value === "string" && isProjectedClientErrorText2(value, clientErrorField);
2626
2674
  }
2627
2675
  const pattern = PUBLIC_TELEMETRY_OPAQUE_ATTRIBUTE_PATTERNS.get(key);
2628
2676
  return typeof value === "string" && pattern?.test(value) === true;
@@ -2662,7 +2710,9 @@ function projectHttpDiagnosticAttributes(attributes) {
2662
2710
  "Response"
2663
2711
  ].includes(reasonKind) ? { reasonKind } : {},
2664
2712
  ...typeof diagnosticId === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(diagnosticId) ? { diagnosticId } : {},
2665
- ...projectErrorCauseAttributes(attributes)
2713
+ ...projectErrorCauseAttributes(attributes),
2714
+ // Only an unclassified internal error logs its scrubbed cause message.
2715
+ ...attributes.errorCode === "internal_error" ? projectErrorCauseMessage(attributes) : {}
2666
2716
  };
2667
2717
  }
2668
2718
  function projectStartupDependencyAttributes(attributes) {
@@ -2847,6 +2897,7 @@ async function defaultExporter(url, body, headers) {
2847
2897
  export {
2848
2898
  AGENT_TOOL_CALL_OUTCOMES,
2849
2899
  AGENT_TOOL_METRIC_FAMILIES,
2900
+ ERROR_CAUSE_MESSAGE_MAX_BYTES,
2850
2901
  FULL_HEAP_WALK_DEFAULT_METRICS,
2851
2902
  MCP_EXECUTION_PHASES,
2852
2903
  OPENGENI_OBSERVABILITY_DISTRIBUTION,
@@ -2869,6 +2920,7 @@ export {
2869
2920
  currentTraceContext,
2870
2921
  dropFullHeapWalkMetrics,
2871
2922
  errorCauseAttributes,
2923
+ errorCauseMessage,
2872
2924
  failureDiagnostic,
2873
2925
  installCpuSamplingSignal,
2874
2926
  interactionAuthMetricObserver,