@armoriq/sdk-dev 0.6.10 → 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 (96) hide show
  1. package/README.md +168 -1
  2. package/dist/_version.d.ts +1 -1
  3. package/dist/_version.d.ts.map +1 -1
  4. package/dist/_version.js +1 -1
  5. package/dist/_version.js.map +1 -1
  6. package/dist/cli/commands/auth.d.ts +12 -0
  7. package/dist/cli/commands/auth.d.ts.map +1 -1
  8. package/dist/cli/commands/auth.js +460 -42
  9. package/dist/cli/commands/auth.js.map +1 -1
  10. package/dist/client.d.ts +8 -15
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +20 -18
  13. package/dist/client.js.map +1 -1
  14. package/dist/config.d.ts +0 -17
  15. package/dist/config.d.ts.map +1 -1
  16. package/dist/config.js +1 -19
  17. package/dist/config.js.map +1 -1
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +8 -14
  21. package/dist/index.js.map +1 -1
  22. package/dist/integrations/google_adk.d.ts +155 -7
  23. package/dist/integrations/google_adk.d.ts.map +1 -1
  24. package/dist/integrations/google_adk.js +727 -46
  25. package/dist/integrations/google_adk.js.map +1 -1
  26. package/dist/integrations/langchain.d.ts +48 -2
  27. package/dist/integrations/langchain.d.ts.map +1 -1
  28. package/dist/integrations/langchain.js +528 -33
  29. package/dist/integrations/langchain.js.map +1 -1
  30. package/dist/integrations/strands.d.ts +46 -1
  31. package/dist/integrations/strands.d.ts.map +1 -1
  32. package/dist/integrations/strands.js +421 -36
  33. package/dist/integrations/strands.js.map +1 -1
  34. package/dist/models.d.ts +2 -2
  35. package/dist/models.d.ts.map +1 -1
  36. package/dist/observability/content-capture.d.ts +75 -0
  37. package/dist/observability/content-capture.d.ts.map +1 -0
  38. package/dist/observability/content-capture.js +339 -0
  39. package/dist/observability/content-capture.js.map +1 -0
  40. package/dist/observability/index.d.ts +6 -7
  41. package/dist/observability/index.d.ts.map +1 -1
  42. package/dist/observability/index.js +18 -27
  43. package/dist/observability/index.js.map +1 -1
  44. package/dist/observability/otel-config.d.ts +47 -0
  45. package/dist/observability/otel-config.d.ts.map +1 -0
  46. package/dist/observability/otel-config.js +268 -0
  47. package/dist/observability/otel-config.js.map +1 -0
  48. package/dist/observability/otel-export-ceiling.d.ts +96 -0
  49. package/dist/observability/otel-export-ceiling.d.ts.map +1 -0
  50. package/dist/observability/otel-export-ceiling.js +264 -0
  51. package/dist/observability/otel-export-ceiling.js.map +1 -0
  52. package/dist/observability/otel-runtime.d.ts +103 -0
  53. package/dist/observability/otel-runtime.d.ts.map +1 -0
  54. package/dist/observability/otel-runtime.js +668 -0
  55. package/dist/observability/otel-runtime.js.map +1 -0
  56. package/dist/observability/otel-session.d.ts +168 -0
  57. package/dist/observability/otel-session.d.ts.map +1 -0
  58. package/dist/observability/otel-session.js +621 -0
  59. package/dist/observability/otel-session.js.map +1 -0
  60. package/dist/observability/otel-shutdown.d.ts +17 -0
  61. package/dist/observability/otel-shutdown.d.ts.map +1 -0
  62. package/dist/observability/otel-shutdown.js +54 -0
  63. package/dist/observability/otel-shutdown.js.map +1 -0
  64. package/dist/observability/policy-lease.d.ts +22 -0
  65. package/dist/observability/policy-lease.d.ts.map +1 -0
  66. package/dist/observability/policy-lease.js +102 -0
  67. package/dist/observability/policy-lease.js.map +1 -0
  68. package/dist/plan_builder.d.ts +5 -4
  69. package/dist/plan_builder.d.ts.map +1 -1
  70. package/dist/plan_builder.js +14 -15
  71. package/dist/plan_builder.js.map +1 -1
  72. package/dist/session.d.ts +61 -93
  73. package/dist/session.d.ts.map +1 -1
  74. package/dist/session.js +388 -804
  75. package/dist/session.js.map +1 -1
  76. package/dist/token_usage.d.ts +11 -18
  77. package/dist/token_usage.d.ts.map +1 -1
  78. package/dist/token_usage.js +29 -94
  79. package/dist/token_usage.js.map +1 -1
  80. package/dist/tool_name.d.ts +18 -0
  81. package/dist/tool_name.d.ts.map +1 -0
  82. package/dist/tool_name.js +29 -0
  83. package/dist/tool_name.js.map +1 -0
  84. package/dist/tool_push.d.ts +28 -0
  85. package/dist/tool_push.d.ts.map +1 -0
  86. package/dist/tool_push.js +151 -0
  87. package/dist/tool_push.js.map +1 -0
  88. package/dist/tool_registry.d.ts +100 -0
  89. package/dist/tool_registry.d.ts.map +1 -0
  90. package/dist/tool_registry.js +440 -0
  91. package/dist/tool_registry.js.map +1 -0
  92. package/dist/tool_schema.d.ts +22 -0
  93. package/dist/tool_schema.d.ts.map +1 -0
  94. package/dist/tool_schema.js +163 -0
  95. package/dist/tool_schema.js.map +1 -0
  96. package/package.json +12 -7
@@ -6,34 +6,25 @@
6
6
  * consumers import from. Every export here is a stable, documented surface.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.__setObservabilitySinkForTests = exports.flushObservability = exports.endTrace = exports.closeSpan = exports.openSpan = exports.recordEvent = exports.recordGeneration = exports.recordPolicyCall = exports.recordSpan = exports.startTrace = exports.isValidUuid = exports.isValidIngestPayload = exports.isValidIngestBatch = exports.isValidEventAttributes = exports.isValidGenerationAttributes = exports.isValidPolicyCallAttributes = exports.isValidSpanAttributes = exports.isValidSpanRecord = exports.isValidTraceRecord = exports.MODEL_PRICES = exports.computeCostUsd = exports.ObservabilityShipper = exports.ObservabilityRecorder = void 0;
10
- var recorder_1 = require("./recorder");
11
- Object.defineProperty(exports, "ObservabilityRecorder", { enumerable: true, get: function () { return recorder_1.ObservabilityRecorder; } });
12
- var shipper_1 = require("./shipper");
13
- Object.defineProperty(exports, "ObservabilityShipper", { enumerable: true, get: function () { return shipper_1.ObservabilityShipper; } });
9
+ exports.OtelSession = exports.__ownedTelemetryRuntimeCountForTests = exports.METADATA_CONTENT_PLACEHOLDER = exports.projectTelemetryContent = exports.isLeaseCurrent = exports.fallbackPolicyLease = exports.parsePolicyLease = exports.ArmorIQTelemetryRuntime = exports.CAPTURE_RANK = exports.lowerCaptureMode = exports.resolveOtelConfig = exports.MODEL_PRICES = exports.computeCostUsd = void 0;
14
10
  var model_prices_1 = require("./model-prices");
15
11
  Object.defineProperty(exports, "computeCostUsd", { enumerable: true, get: function () { return model_prices_1.computeCostUsd; } });
16
12
  Object.defineProperty(exports, "MODEL_PRICES", { enumerable: true, get: function () { return model_prices_1.MODEL_PRICES; } });
17
- var schema_1 = require("./schema");
18
- Object.defineProperty(exports, "isValidTraceRecord", { enumerable: true, get: function () { return schema_1.isValidTraceRecord; } });
19
- Object.defineProperty(exports, "isValidSpanRecord", { enumerable: true, get: function () { return schema_1.isValidSpanRecord; } });
20
- Object.defineProperty(exports, "isValidSpanAttributes", { enumerable: true, get: function () { return schema_1.isValidSpanAttributes; } });
21
- Object.defineProperty(exports, "isValidPolicyCallAttributes", { enumerable: true, get: function () { return schema_1.isValidPolicyCallAttributes; } });
22
- Object.defineProperty(exports, "isValidGenerationAttributes", { enumerable: true, get: function () { return schema_1.isValidGenerationAttributes; } });
23
- Object.defineProperty(exports, "isValidEventAttributes", { enumerable: true, get: function () { return schema_1.isValidEventAttributes; } });
24
- Object.defineProperty(exports, "isValidIngestBatch", { enumerable: true, get: function () { return schema_1.isValidIngestBatch; } });
25
- Object.defineProperty(exports, "isValidIngestPayload", { enumerable: true, get: function () { return schema_1.isValidIngestPayload; } });
26
- Object.defineProperty(exports, "isValidUuid", { enumerable: true, get: function () { return schema_1.isValidUuid; } });
27
- var handle_1 = require("./handle");
28
- Object.defineProperty(exports, "startTrace", { enumerable: true, get: function () { return handle_1.startTrace; } });
29
- Object.defineProperty(exports, "recordSpan", { enumerable: true, get: function () { return handle_1.recordSpan; } });
30
- Object.defineProperty(exports, "recordPolicyCall", { enumerable: true, get: function () { return handle_1.recordPolicyCall; } });
31
- Object.defineProperty(exports, "recordGeneration", { enumerable: true, get: function () { return handle_1.recordGeneration; } });
32
- Object.defineProperty(exports, "recordEvent", { enumerable: true, get: function () { return handle_1.recordEvent; } });
33
- Object.defineProperty(exports, "openSpan", { enumerable: true, get: function () { return handle_1.openSpan; } });
34
- Object.defineProperty(exports, "closeSpan", { enumerable: true, get: function () { return handle_1.closeSpan; } });
35
- Object.defineProperty(exports, "endTrace", { enumerable: true, get: function () { return handle_1.endTrace; } });
36
- Object.defineProperty(exports, "flushObservability", { enumerable: true, get: function () { return handle_1.flushObservability; } });
37
- var recorder_2 = require("./recorder");
38
- Object.defineProperty(exports, "__setObservabilitySinkForTests", { enumerable: true, get: function () { return recorder_2.__setObservabilitySinkForTests; } });
13
+ var otel_config_1 = require("./otel-config");
14
+ Object.defineProperty(exports, "resolveOtelConfig", { enumerable: true, get: function () { return otel_config_1.resolveOtelConfig; } });
15
+ Object.defineProperty(exports, "lowerCaptureMode", { enumerable: true, get: function () { return otel_config_1.lowerCaptureMode; } });
16
+ Object.defineProperty(exports, "CAPTURE_RANK", { enumerable: true, get: function () { return otel_config_1.CAPTURE_RANK; } });
17
+ var otel_runtime_1 = require("./otel-runtime");
18
+ Object.defineProperty(exports, "ArmorIQTelemetryRuntime", { enumerable: true, get: function () { return otel_runtime_1.ArmorIQTelemetryRuntime; } });
19
+ var policy_lease_1 = require("./policy-lease");
20
+ Object.defineProperty(exports, "parsePolicyLease", { enumerable: true, get: function () { return policy_lease_1.parsePolicyLease; } });
21
+ Object.defineProperty(exports, "fallbackPolicyLease", { enumerable: true, get: function () { return policy_lease_1.fallbackPolicyLease; } });
22
+ Object.defineProperty(exports, "isLeaseCurrent", { enumerable: true, get: function () { return policy_lease_1.isLeaseCurrent; } });
23
+ var content_capture_1 = require("./content-capture");
24
+ Object.defineProperty(exports, "projectTelemetryContent", { enumerable: true, get: function () { return content_capture_1.projectTelemetryContent; } });
25
+ Object.defineProperty(exports, "METADATA_CONTENT_PLACEHOLDER", { enumerable: true, get: function () { return content_capture_1.METADATA_CONTENT_PLACEHOLDER; } });
26
+ var otel_shutdown_1 = require("./otel-shutdown");
27
+ Object.defineProperty(exports, "__ownedTelemetryRuntimeCountForTests", { enumerable: true, get: function () { return otel_shutdown_1.__ownedTelemetryRuntimeCountForTests; } });
28
+ var otel_session_1 = require("./otel-session");
29
+ Object.defineProperty(exports, "OtelSession", { enumerable: true, get: function () { return otel_session_1.OtelSession; } });
39
30
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uCAA6E;AAApE,iHAAA,qBAAqB,OAAA;AAC9B,qCAAqE;AAA5D,+GAAA,oBAAoB,OAAA;AAC7B,+CAA+E;AAAtE,8GAAA,cAAc,OAAA;AAAE,4GAAA,YAAY,OAAA;AAsBrC,mCAUkB;AAThB,4GAAA,kBAAkB,OAAA;AAClB,2GAAA,iBAAiB,OAAA;AACjB,+GAAA,qBAAqB,OAAA;AACrB,qHAAA,2BAA2B,OAAA;AAC3B,qHAAA,2BAA2B,OAAA;AAC3B,gHAAA,sBAAsB,OAAA;AACtB,4GAAA,kBAAkB,OAAA;AAClB,8GAAA,oBAAoB,OAAA;AACpB,qGAAA,WAAW,OAAA;AAGb,mCAUkB;AAThB,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,0GAAA,gBAAgB,OAAA;AAChB,0GAAA,gBAAgB,OAAA;AAChB,qGAAA,WAAW,OAAA;AACX,kGAAA,QAAQ,OAAA;AACR,mGAAA,SAAS,OAAA;AACT,kGAAA,QAAQ,OAAA;AACR,4GAAA,kBAAkB,OAAA;AAGpB,uCAA4D;AAAnD,0HAAA,8BAA8B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+CAA+E;AAAtE,8GAAA,cAAc,OAAA;AAAE,4GAAA,YAAY,OAAA;AAErC,6CASuB;AARrB,gHAAA,iBAAiB,OAAA;AACjB,+GAAA,gBAAgB,OAAA;AAChB,2GAAA,YAAY,OAAA;AAQd,+CAMwB;AALtB,uHAAA,uBAAuB,OAAA;AAMzB,+CAAyG;AAAhG,gHAAA,gBAAgB,OAAA;AAAE,mHAAA,mBAAmB,OAAA;AAAE,8GAAA,cAAc,OAAA;AAC9D,qDAO2B;AANzB,0HAAA,uBAAuB,OAAA;AACvB,+HAAA,4BAA4B,OAAA;AAM9B,iDAAuE;AAA9D,qIAAA,oCAAoC,OAAA;AAC7C,+CAYwB;AAXtB,2GAAA,WAAW,OAAA"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Immutable, fail-safe OpenTelemetry configuration.
3
+ *
4
+ * The public contract intentionally follows standard OTLP environment
5
+ * variables. It never identifies or configures a specific external vendor.
6
+ */
7
+ import type { TracerProvider } from '@opentelemetry/api';
8
+ export type CaptureMode = 'off' | 'metadata' | 'enhanced' | 'debug';
9
+ export type OtelExporterMode = 'armoriq' | 'external' | 'provider';
10
+ export type OtelProtocol = 'http/protobuf';
11
+ export interface ObservabilityOptions {
12
+ enabled?: boolean;
13
+ exporter?: OtelExporterMode;
14
+ /** Explicit complete OTLP traces endpoint. */
15
+ endpoint?: string;
16
+ /** Explicit OTLP base endpoint; `/v1/traces` is appended. */
17
+ baseEndpoint?: string;
18
+ headers?: Readonly<Record<string, string>>;
19
+ protocol?: OtelProtocol;
20
+ timeoutMillis?: number;
21
+ resourceAttributes?: Readonly<Record<string, string>>;
22
+ tracerProvider?: TracerProvider;
23
+ captureMode?: CaptureMode;
24
+ serviceName?: string;
25
+ /** Explicit caller-owned user identity for external OTel export. */
26
+ userId?: string;
27
+ }
28
+ export interface ResolvedOtelConfig {
29
+ readonly enabled: boolean;
30
+ readonly exporter: OtelExporterMode;
31
+ readonly endpoint?: string;
32
+ readonly headers: Readonly<Record<string, string>>;
33
+ readonly protocol: OtelProtocol;
34
+ readonly timeoutMillis: number;
35
+ readonly resourceAttributes: Readonly<Record<string, string>>;
36
+ readonly tracerProvider?: TracerProvider;
37
+ readonly captureMode: CaptureMode;
38
+ readonly serviceName: string;
39
+ readonly disabledReason?: string;
40
+ }
41
+ /** Returns an externally safe value, or no value when it could identify a person. */
42
+ export declare function sanitizeExternalTelemetryValue(value: string, maxLength?: number): string | undefined;
43
+ /** Resolve without network I/O. No returned object is mutable by a caller. */
44
+ export declare function resolveOtelConfig(options?: ObservabilityOptions): ResolvedOtelConfig;
45
+ export declare const CAPTURE_RANK: Readonly<Record<CaptureMode, number>>;
46
+ export declare function lowerCaptureMode(left: CaptureMode, right: CaptureMode): CaptureMode;
47
+ //# sourceMappingURL=otel-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel-config.d.ts","sourceRoot":"","sources":["../../src/observability/otel-config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;AACpE,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AACnE,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC;AAE3C,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3C,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9D,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAiDD,qFAAqF;AACrF,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,GAAG,SAAS,CAIzG;AA+JD,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,oBAAyB,GAAG,kBAAkB,CAyBxF;AAED,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAK7D,CAAC;AAEH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,GAAG,WAAW,CAEnF"}
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ /**
3
+ * Immutable, fail-safe OpenTelemetry configuration.
4
+ *
5
+ * The public contract intentionally follows standard OTLP environment
6
+ * variables. It never identifies or configures a specific external vendor.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.CAPTURE_RANK = void 0;
10
+ exports.sanitizeExternalTelemetryValue = sanitizeExternalTelemetryValue;
11
+ exports.resolveOtelConfig = resolveOtelConfig;
12
+ exports.lowerCaptureMode = lowerCaptureMode;
13
+ const CAPTURE_MODES = new Set(['off', 'metadata', 'enhanced', 'debug']);
14
+ const EXPORTERS = new Set(['armoriq', 'external', 'provider']);
15
+ const SAFE_RESOURCE_KEYS = new Set([
16
+ 'service.version',
17
+ 'service.namespace',
18
+ 'service.instance.id',
19
+ 'deployment.environment.name',
20
+ 'telemetry.sdk.name',
21
+ 'telemetry.sdk.version',
22
+ ]);
23
+ const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
24
+ const RESERVED_TRANSPORT_HEADERS = new Set([
25
+ 'connection', 'content-length', 'content-type', 'host', 'keep-alive',
26
+ 'proxy-authenticate', 'proxy-authorization', 'te', 'trailer',
27
+ 'transfer-encoding', 'upgrade',
28
+ ]);
29
+ const SENSITIVE_VALUE = /(?:\beyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b|\b(?:ak|sk|pk|rk|ghp|github_pat)_[A-Za-z0-9_-]{12,}\b|-----BEGIN [A-Z0-9 ]+-----)/i;
30
+ const EMAIL = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i;
31
+ const DEFAULT_TIMEOUT_MS = 3_000;
32
+ /**
33
+ * Numeric personal identifiers are unsafe even when their attribute name is
34
+ * harmless. Match phone-length runs, the SSN shape, and payment-card-length
35
+ * runs rather than relying on caller-provided field names.
36
+ */
37
+ function hasNumericPersonalIdentifier(value) {
38
+ if (/(?:^|\D)\d{3}[- ]?\d{2}[- ]?\d{4}(?:$|\D)/.test(value))
39
+ return true;
40
+ const candidates = value.match(/\+?\d(?:[ .()-]*\d){8,18}/g) ?? [];
41
+ return candidates.some((candidate) => {
42
+ const digits = candidate.replace(/\D/g, '');
43
+ return digits.length >= 10 && digits.length <= 15
44
+ || (digits.length >= 13 && digits.length <= 19 && passesLuhn(digits));
45
+ });
46
+ }
47
+ function passesLuhn(digits) {
48
+ let sum = 0;
49
+ let alternate = false;
50
+ for (let index = digits.length - 1; index >= 0; index -= 1) {
51
+ let digit = Number(digits[index]);
52
+ if (alternate && (digit *= 2) > 9)
53
+ digit -= 9;
54
+ sum += digit;
55
+ alternate = !alternate;
56
+ }
57
+ return sum % 10 === 0;
58
+ }
59
+ /** Returns an externally safe value, or no value when it could identify a person. */
60
+ function sanitizeExternalTelemetryValue(value, maxLength = 256) {
61
+ const trimmed = value.trim();
62
+ if (!trimmed || /[\r\n\0]/.test(trimmed) || SENSITIVE_VALUE.test(trimmed) || EMAIL.test(trimmed) || hasNumericPersonalIdentifier(trimmed))
63
+ return undefined;
64
+ return trimmed.slice(0, maxLength);
65
+ }
66
+ function env(name) {
67
+ const value = process.env[name]?.trim();
68
+ return value || undefined;
69
+ }
70
+ function isDisabledByEnvironment() {
71
+ return ['0', 'false', 'off', 'no', 'disabled'].includes((env('ARMORIQ_OBSERVABILITY') ?? '').toLowerCase())
72
+ || (env('OTEL_SDK_DISABLED') ?? '').toLowerCase() === 'true'
73
+ || (env('OTEL_TRACES_EXPORTER') ?? '').toLowerCase() === 'none';
74
+ }
75
+ function captureMode(value, fallback) {
76
+ const normalized = String(value ?? '').trim().toLowerCase();
77
+ return CAPTURE_MODES.has(normalized) ? normalized : fallback;
78
+ }
79
+ function endpointConfigured(options) {
80
+ return Boolean(options.endpoint?.trim() || options.baseEndpoint?.trim() || env('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT') || env('OTEL_EXPORTER_OTLP_ENDPOINT') || env('ARMORIQ_OTEL_ENDPOINT'));
81
+ }
82
+ function exporter(options) {
83
+ if (options.exporter)
84
+ return EXPORTERS.has(options.exporter) ? options.exporter : 'armoriq';
85
+ const configured = env('ARMORIQ_OTEL_EXPORTER')?.toLowerCase();
86
+ if (configured && EXPORTERS.has(configured))
87
+ return configured;
88
+ return endpointConfigured(options) ? 'external' : 'armoriq';
89
+ }
90
+ /**
91
+ * `http:` carries configured authorization headers and lease-authorized
92
+ * enhanced/debug content in plaintext, so it is only safe for a collector
93
+ * running on the same machine — never an arbitrary remote host. Remote
94
+ * endpoints must use `https:`.
95
+ */
96
+ function isLoopbackHostname(hostname) {
97
+ const normalized = hostname.replace(/^\[|\]$/g, '').toLowerCase();
98
+ return normalized === 'localhost' || normalized === '127.0.0.1' || normalized === '::1';
99
+ }
100
+ function validateUrl(value) {
101
+ try {
102
+ const url = new URL(value);
103
+ if ((url.protocol !== 'https:' && url.protocol !== 'http:') || url.username || url.password || url.search || url.hash)
104
+ return undefined;
105
+ if (url.protocol === 'http:' && !isLoopbackHostname(url.hostname))
106
+ return undefined;
107
+ return url.toString().replace(/\/$/, '');
108
+ }
109
+ catch {
110
+ return undefined;
111
+ }
112
+ }
113
+ function appendTracePath(value) {
114
+ const endpoint = validateUrl(value);
115
+ if (!endpoint)
116
+ return undefined;
117
+ const url = new URL(endpoint);
118
+ const pathname = url.pathname.replace(/\/+$/, '');
119
+ url.pathname = pathname.endsWith('/v1/traces') ? pathname : `${pathname}/v1/traces`;
120
+ return url.toString().replace(/\/$/, '');
121
+ }
122
+ function resolveEndpoint(options) {
123
+ if (options.endpoint?.trim())
124
+ return validateUrl(options.endpoint.trim());
125
+ if (options.baseEndpoint?.trim())
126
+ return appendTracePath(options.baseEndpoint.trim());
127
+ const tracesEndpoint = env('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT');
128
+ if (tracesEndpoint)
129
+ return validateUrl(tracesEndpoint);
130
+ const baseEndpoint = env('OTEL_EXPORTER_OTLP_ENDPOINT');
131
+ if (baseEndpoint)
132
+ return appendTracePath(baseEndpoint);
133
+ const convenienceEndpoint = env('ARMORIQ_OTEL_ENDPOINT');
134
+ return convenienceEndpoint ? validateUrl(convenienceEndpoint) : undefined;
135
+ }
136
+ function decodeHeaderValue(value) {
137
+ try {
138
+ const decoded = decodeURIComponent(value.trim());
139
+ return decoded && !/[\r\n\0]/.test(decoded) ? decoded : undefined;
140
+ }
141
+ catch {
142
+ return undefined;
143
+ }
144
+ }
145
+ function parseHeaderString(value) {
146
+ if (!value)
147
+ return {};
148
+ const parsed = {};
149
+ for (const pair of value.split(',')) {
150
+ const separator = pair.indexOf('=');
151
+ if (separator <= 0)
152
+ return undefined;
153
+ const key = pair.slice(0, separator).trim();
154
+ const decoded = decodeHeaderValue(pair.slice(separator + 1));
155
+ if (!HEADER_NAME.test(key) || decoded === undefined)
156
+ return undefined;
157
+ if (!RESERVED_TRANSPORT_HEADERS.has(key.toLowerCase()))
158
+ parsed[key.toLowerCase()] = decoded;
159
+ }
160
+ return parsed;
161
+ }
162
+ function parseHeaderObject(value) {
163
+ if (!value)
164
+ return {};
165
+ const parsed = {};
166
+ for (const [key, raw] of Object.entries(value)) {
167
+ if (!HEADER_NAME.test(key) || typeof raw !== 'string' || !raw || /[\r\n\0]/.test(raw))
168
+ return undefined;
169
+ if (!RESERVED_TRANSPORT_HEADERS.has(key.toLowerCase()))
170
+ parsed[key.toLowerCase()] = raw;
171
+ }
172
+ return parsed;
173
+ }
174
+ function resolveHeaders(options) {
175
+ const general = parseHeaderString(env('OTEL_EXPORTER_OTLP_HEADERS'));
176
+ const traces = parseHeaderString(env('OTEL_EXPORTER_OTLP_TRACES_HEADERS'));
177
+ const explicit = parseHeaderObject(options.headers);
178
+ if (!general || !traces || !explicit)
179
+ return undefined;
180
+ return Object.freeze({ ...general, ...traces, ...explicit });
181
+ }
182
+ function resolveProtocol(options) {
183
+ const value = options.protocol ?? env('OTEL_EXPORTER_OTLP_TRACES_PROTOCOL') ?? env('OTEL_EXPORTER_OTLP_PROTOCOL') ?? 'http/protobuf';
184
+ return String(value).trim().toLowerCase() === 'http/protobuf' ? 'http/protobuf' : undefined;
185
+ }
186
+ function parseTimeout(value) {
187
+ if (value === undefined || value === null || value === '')
188
+ return DEFAULT_TIMEOUT_MS;
189
+ const parsed = typeof value === 'number' ? value : Number(String(value).trim());
190
+ return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;
191
+ }
192
+ function resolveTimeout(options) {
193
+ return parseTimeout(options.timeoutMillis ?? env('OTEL_EXPORTER_OTLP_TRACES_TIMEOUT') ?? env('OTEL_EXPORTER_OTLP_TIMEOUT'));
194
+ }
195
+ function safeServiceName(value) {
196
+ const trimmed = value?.trim() ?? '';
197
+ return /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/.test(trimmed) && sanitizeExternalTelemetryValue(trimmed, 128)
198
+ ? trimmed
199
+ : 'armoriq-sdk';
200
+ }
201
+ function parseResources(value) {
202
+ if (!value)
203
+ return {};
204
+ const entries = typeof value === 'string'
205
+ ? value.split(',').map((pair) => {
206
+ const separator = pair.indexOf('=');
207
+ return separator <= 0 ? undefined : [pair.slice(0, separator).trim(), pair.slice(separator + 1).trim()];
208
+ })
209
+ : Object.entries(value);
210
+ const parsed = {};
211
+ for (const entry of entries) {
212
+ if (!entry)
213
+ continue;
214
+ const [key, raw] = entry;
215
+ const value = typeof raw === 'string' ? sanitizeExternalTelemetryValue(raw) : undefined;
216
+ if (!SAFE_RESOURCE_KEYS.has(key) || !value)
217
+ continue;
218
+ parsed[key] = value;
219
+ }
220
+ return parsed;
221
+ }
222
+ function resolveResources(options) {
223
+ const environmental = parseResources(env('OTEL_RESOURCE_ATTRIBUTES'));
224
+ const explicit = parseResources(options.resourceAttributes);
225
+ return Object.freeze(environmental && explicit ? { ...environmental, ...explicit } : {});
226
+ }
227
+ /** Resolve without network I/O. No returned object is mutable by a caller. */
228
+ function resolveOtelConfig(options = {}) {
229
+ const resolvedExporter = exporter(options);
230
+ const endpoint = resolvedExporter === 'external' ? resolveEndpoint(options) : undefined;
231
+ const headers = resolveHeaders(options);
232
+ const protocol = resolveProtocol(options);
233
+ const timeoutMillis = resolveTimeout(options);
234
+ const serviceName = safeServiceName(options.serviceName ?? env('OTEL_SERVICE_NAME'));
235
+ const base = {
236
+ enabled: options.enabled !== false && !isDisabledByEnvironment(),
237
+ exporter: resolvedExporter,
238
+ endpoint,
239
+ headers: headers ?? Object.freeze({}),
240
+ protocol: protocol ?? 'http/protobuf',
241
+ timeoutMillis: timeoutMillis ?? DEFAULT_TIMEOUT_MS,
242
+ resourceAttributes: resolveResources(options),
243
+ tracerProvider: options.tracerProvider,
244
+ captureMode: captureMode(options.captureMode ?? env('ARMORIQ_OTEL_CAPTURE_MODE') ?? 'debug', 'debug'),
245
+ serviceName,
246
+ };
247
+ if (resolvedExporter === 'external' && !endpoint)
248
+ return Object.freeze({ ...base, enabled: false, disabledReason: 'external endpoint is required' });
249
+ if (resolvedExporter === 'external' && !headers)
250
+ return Object.freeze({ ...base, enabled: false, disabledReason: 'invalid OTLP headers' });
251
+ if (resolvedExporter === 'external' && !protocol)
252
+ return Object.freeze({ ...base, enabled: false, disabledReason: 'only http/protobuf OTLP is supported' });
253
+ if (resolvedExporter === 'external' && !timeoutMillis)
254
+ return Object.freeze({ ...base, enabled: false, disabledReason: 'invalid OTLP timeout' });
255
+ if (resolvedExporter === 'provider' && !options.tracerProvider)
256
+ return Object.freeze({ ...base, enabled: false, disabledReason: 'tracerProvider is required' });
257
+ return Object.freeze(base);
258
+ }
259
+ exports.CAPTURE_RANK = Object.freeze({
260
+ off: 0,
261
+ metadata: 1,
262
+ enhanced: 2,
263
+ debug: 3,
264
+ });
265
+ function lowerCaptureMode(left, right) {
266
+ return exports.CAPTURE_RANK[left] <= exports.CAPTURE_RANK[right] ? left : right;
267
+ }
268
+ //# sourceMappingURL=otel-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel-config.js","sourceRoot":"","sources":["../../src/observability/otel-config.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAwFH,wEAIC;AAgKD,8CAyBC;AASD,4CAEC;AAxPD,MAAM,aAAa,GAAG,IAAI,GAAG,CAAc,CAAC,KAAK,EAAE,UAAU,EAAE,UA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AAO,EAAE,KAAK,EAAE,cAAc,EAAE,4BAA4B,EAAE,CAAC,CAAC;IAChK,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAEY,QAAA,YAAY,GAA0C,MAAM,CAAC,MAAM,CAAC;IAC/E,GAAG,EAAE,CAAC;IACN,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,KAAK,EAAE,CAAC;CACT,CAAC,CAAC;AAEH,SAAgB,gBAAgB,CAAC,IAAiB,EAAE,KAAkB;IACpE,OAAO,oBAAY,CAAC,IAAI,CAAC,IAAI,oBAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AAClE,CAAC"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Export-time capture-mode ceiling re-application for buffered spans.
3
+ *
4
+ * `ArmorIQTelemetryRuntime.safeAttributes` (otel-runtime.ts) already governs
5
+ * what a span is *allowed to receive* at the moment its attributes are set,
6
+ * using whatever policy lease was current at that instant. That is not
7
+ * enough on its own: `BatchSpanProcessor` buffers ended spans in memory and
8
+ * ships them later, on a timer or when the queue fills. A span populated
9
+ * with rich content under an `enhanced`/`debug` lease can still be sitting
10
+ * in that buffer, un-exported, when the organization's lease becomes
11
+ * stricter -- because the policy changed, or because a refresh came back
12
+ * lower after the previous lease expired. Without a check at the moment
13
+ * spans actually leave the process, the stale, too-permissive attributes
14
+ * baked onto the span at creation time would still ship, even though the
15
+ * CURRENT lease no longer authorizes them.
16
+ *
17
+ * This module closes that gap at two points, both delegating to the exact
18
+ * same governance the runtime uses at span-creation time
19
+ * (`ArmorIQTelemetryRuntime.currentCeilingSnapshot` /
20
+ * `reapplyContentCeiling`, which in turn shares `contentAuthority` with
21
+ * `safeAttributesWithAuthority`), so there is exactly one place that defines
22
+ * "what counts as content" and "what survives a given capture mode":
23
+ *
24
+ * - `CeilingReapplyingSpanExporter` wraps the real span exporter. Its
25
+ * `export` re-reads the current policy snapshot immediately before
26
+ * handing spans to the wrapped exporter -- this runs whenever the
27
+ * batching processor actually flushes, so it catches a span regardless of
28
+ * how long it sat queued.
29
+ * - `CeilingReapplyingSpanProcessor` wraps the real span processor. Its
30
+ * `onEnd` performs the same re-check at the moment a span is handed off
31
+ * for export, closing the narrower window between when a long-running
32
+ * operation's attributes were set and when `span.end()` is finally
33
+ * called.
34
+ *
35
+ * Both are no-ops when the current snapshot still authorizes everything
36
+ * already on the span, so a session whose lease never changes exports
37
+ * exactly what it would have exported before this module existed.
38
+ *
39
+ * This is a privacy boundary, so re-governance fails CLOSED in two tiers
40
+ * rather than fail-open. A policy-lookup or re-governance failure used to
41
+ * leave a span exactly as it was, after which it would export with content
42
+ * the current lease may have revoked. Instead:
43
+ *
44
+ * 1. Replace the attributes with the same withheld-content markers
45
+ * `projectTelemetryContent` produces for a disallowed capture mode. This
46
+ * keeps the span itself -- name, timing, status, parent/child structure
47
+ * -- which is the point of the telemetry, while guaranteeing no governed
48
+ * content ships.
49
+ * 2. Only if even that replacement cannot be written is the span dropped
50
+ * outright: the exporter filters it out and the processor never queues
51
+ * it. A batch left empty by privacy drops reports `SUCCESS`, not
52
+ * `FAILED` -- the drop is a deliberate, permanent verdict, and `FAILED`
53
+ * would have `BatchSpanProcessor` treat it as a retryable transport
54
+ * problem.
55
+ */
56
+ import type { Context } from '@opentelemetry/api';
57
+ import type { ExportResult } from '@opentelemetry/core';
58
+ import type { ReadableSpan, Span, SpanExporter, SpanProcessor } from '@opentelemetry/sdk-trace-base';
59
+ import type { ArmorIQTelemetryRuntime } from './otel-runtime';
60
+ /**
61
+ * Re-govern span attributes against the CURRENT lease before shipping.
62
+ *
63
+ * This is the true export-time gate: `export` runs whenever the wrapped
64
+ * batching processor actually flushes its buffer, so a span that has been
65
+ * queued for any length of time is re-evaluated against the lease that is
66
+ * authoritative right now, not the one that was authoritative when it was
67
+ * created or ended.
68
+ */
69
+ export declare class CeilingReapplyingSpanExporter implements SpanExporter {
70
+ private readonly exporter;
71
+ private readonly runtime;
72
+ constructor(exporter: SpanExporter, runtime: ArmorIQTelemetryRuntime);
73
+ export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
74
+ shutdown(): Promise<void>;
75
+ forceFlush(): Promise<void>;
76
+ }
77
+ /**
78
+ * Re-govern span attributes at the `onEnd` hand-off boundary.
79
+ *
80
+ * Complements `CeilingReapplyingSpanExporter`: this closes the window
81
+ * between when a span's attributes were last set (which can be well before
82
+ * a long-running operation actually calls `span.end()`) and when it is
83
+ * handed to the wrapped processor for batching. `shutdown`/`forceFlush`
84
+ * delegate to the wrapped processor unchanged -- this class only adds a
85
+ * re-governance step, it does not change close/flush lifecycle semantics.
86
+ */
87
+ export declare class CeilingReapplyingSpanProcessor implements SpanProcessor {
88
+ private readonly processor;
89
+ private readonly runtime;
90
+ constructor(processor: SpanProcessor, runtime: ArmorIQTelemetryRuntime);
91
+ onStart(span: Span, parentContext: Context): void;
92
+ onEnd(span: ReadableSpan): void;
93
+ shutdown(): Promise<void>;
94
+ forceFlush(): Promise<void>;
95
+ }
96
+ //# sourceMappingURL=otel-export-ceiling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel-export-ceiling.d.ts","sourceRoot":"","sources":["../../src/observability/otel-export-ceiling.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAErG,OAAO,KAAK,EAAE,uBAAuB,EAA2B,MAAM,gBAAgB,CAAC;AA0HvF;;;;;;;;GAQG;AACH,qBAAa,6BAA8B,YAAW,YAAY;IAE9D,OAAO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