@armoriq/sdk-dev 0.6.8 → 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 (99) hide show
  1. package/README.md +168 -1
  2. package/dist/_version.d.ts +1 -1
  3. package/dist/_version.js +1 -1
  4. package/dist/cli/commands/auth.d.ts +12 -0
  5. package/dist/cli/commands/auth.d.ts.map +1 -1
  6. package/dist/cli/commands/auth.js +460 -42
  7. package/dist/cli/commands/auth.js.map +1 -1
  8. package/dist/cli/index.js +0 -0
  9. package/dist/client.d.ts +8 -15
  10. package/dist/client.d.ts.map +1 -1
  11. package/dist/client.js +20 -18
  12. package/dist/client.js.map +1 -1
  13. package/dist/config.d.ts +0 -17
  14. package/dist/config.d.ts.map +1 -1
  15. package/dist/config.js +1 -19
  16. package/dist/config.js.map +1 -1
  17. package/dist/index.d.ts +3 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +8 -14
  20. package/dist/index.js.map +1 -1
  21. package/dist/integrations/google_adk.d.ts +168 -6
  22. package/dist/integrations/google_adk.d.ts.map +1 -1
  23. package/dist/integrations/google_adk.js +797 -103
  24. package/dist/integrations/google_adk.js.map +1 -1
  25. package/dist/integrations/langchain.d.ts +51 -1
  26. package/dist/integrations/langchain.d.ts.map +1 -1
  27. package/dist/integrations/langchain.js +563 -30
  28. package/dist/integrations/langchain.js.map +1 -1
  29. package/dist/integrations/strands.d.ts +48 -0
  30. package/dist/integrations/strands.d.ts.map +1 -1
  31. package/dist/integrations/strands.js +441 -27
  32. package/dist/integrations/strands.js.map +1 -1
  33. package/dist/models.d.ts +2 -2
  34. package/dist/models.d.ts.map +1 -1
  35. package/dist/observability/content-capture.d.ts +75 -0
  36. package/dist/observability/content-capture.d.ts.map +1 -0
  37. package/dist/observability/content-capture.js +339 -0
  38. package/dist/observability/content-capture.js.map +1 -0
  39. package/dist/observability/index.d.ts +6 -7
  40. package/dist/observability/index.d.ts.map +1 -1
  41. package/dist/observability/index.js +18 -27
  42. package/dist/observability/index.js.map +1 -1
  43. package/dist/observability/otel-config.d.ts +47 -0
  44. package/dist/observability/otel-config.d.ts.map +1 -0
  45. package/dist/observability/otel-config.js +268 -0
  46. package/dist/observability/otel-config.js.map +1 -0
  47. package/dist/observability/otel-export-ceiling.d.ts +96 -0
  48. package/dist/observability/otel-export-ceiling.d.ts.map +1 -0
  49. package/dist/observability/otel-export-ceiling.js +264 -0
  50. package/dist/observability/otel-export-ceiling.js.map +1 -0
  51. package/dist/observability/otel-runtime.d.ts +103 -0
  52. package/dist/observability/otel-runtime.d.ts.map +1 -0
  53. package/dist/observability/otel-runtime.js +668 -0
  54. package/dist/observability/otel-runtime.js.map +1 -0
  55. package/dist/observability/otel-session.d.ts +168 -0
  56. package/dist/observability/otel-session.d.ts.map +1 -0
  57. package/dist/observability/otel-session.js +621 -0
  58. package/dist/observability/otel-session.js.map +1 -0
  59. package/dist/observability/otel-shutdown.d.ts +17 -0
  60. package/dist/observability/otel-shutdown.d.ts.map +1 -0
  61. package/dist/observability/otel-shutdown.js +54 -0
  62. package/dist/observability/otel-shutdown.js.map +1 -0
  63. package/dist/observability/policy-lease.d.ts +22 -0
  64. package/dist/observability/policy-lease.d.ts.map +1 -0
  65. package/dist/observability/policy-lease.js +102 -0
  66. package/dist/observability/policy-lease.js.map +1 -0
  67. package/dist/plan_builder.d.ts +5 -4
  68. package/dist/plan_builder.d.ts.map +1 -1
  69. package/dist/plan_builder.js +14 -15
  70. package/dist/plan_builder.js.map +1 -1
  71. package/dist/session.d.ts +61 -93
  72. package/dist/session.d.ts.map +1 -1
  73. package/dist/session.js +388 -812
  74. package/dist/session.js.map +1 -1
  75. package/dist/token_usage.d.ts +11 -18
  76. package/dist/token_usage.d.ts.map +1 -1
  77. package/dist/token_usage.js +29 -94
  78. package/dist/token_usage.js.map +1 -1
  79. package/dist/tool_name.d.ts +18 -0
  80. package/dist/tool_name.d.ts.map +1 -0
  81. package/dist/tool_name.js +29 -0
  82. package/dist/tool_name.js.map +1 -0
  83. package/dist/tool_push.d.ts +28 -0
  84. package/dist/tool_push.d.ts.map +1 -0
  85. package/dist/tool_push.js +151 -0
  86. package/dist/tool_push.js.map +1 -0
  87. package/dist/tool_registry.d.ts +100 -0
  88. package/dist/tool_registry.d.ts.map +1 -0
  89. package/dist/tool_registry.js +440 -0
  90. package/dist/tool_registry.js.map +1 -0
  91. package/dist/tool_schema.d.ts +22 -0
  92. package/dist/tool_schema.d.ts.map +1 -0
  93. package/dist/tool_schema.js +163 -0
  94. package/dist/tool_schema.js.map +1 -0
  95. package/package.json +13 -7
  96. package/dist/integrations/microsoft_copilot.d.ts +0 -84
  97. package/dist/integrations/microsoft_copilot.d.ts.map +0 -1
  98. package/dist/integrations/microsoft_copilot.js +0 -126
  99. package/dist/integrations/microsoft_copilot.js.map +0 -1
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ /**
3
+ * Export-time capture-mode ceiling re-application for buffered spans.
4
+ *
5
+ * `ArmorIQTelemetryRuntime.safeAttributes` (otel-runtime.ts) already governs
6
+ * what a span is *allowed to receive* at the moment its attributes are set,
7
+ * using whatever policy lease was current at that instant. That is not
8
+ * enough on its own: `BatchSpanProcessor` buffers ended spans in memory and
9
+ * ships them later, on a timer or when the queue fills. A span populated
10
+ * with rich content under an `enhanced`/`debug` lease can still be sitting
11
+ * in that buffer, un-exported, when the organization's lease becomes
12
+ * stricter -- because the policy changed, or because a refresh came back
13
+ * lower after the previous lease expired. Without a check at the moment
14
+ * spans actually leave the process, the stale, too-permissive attributes
15
+ * baked onto the span at creation time would still ship, even though the
16
+ * CURRENT lease no longer authorizes them.
17
+ *
18
+ * This module closes that gap at two points, both delegating to the exact
19
+ * same governance the runtime uses at span-creation time
20
+ * (`ArmorIQTelemetryRuntime.currentCeilingSnapshot` /
21
+ * `reapplyContentCeiling`, which in turn shares `contentAuthority` with
22
+ * `safeAttributesWithAuthority`), so there is exactly one place that defines
23
+ * "what counts as content" and "what survives a given capture mode":
24
+ *
25
+ * - `CeilingReapplyingSpanExporter` wraps the real span exporter. Its
26
+ * `export` re-reads the current policy snapshot immediately before
27
+ * handing spans to the wrapped exporter -- this runs whenever the
28
+ * batching processor actually flushes, so it catches a span regardless of
29
+ * how long it sat queued.
30
+ * - `CeilingReapplyingSpanProcessor` wraps the real span processor. Its
31
+ * `onEnd` performs the same re-check at the moment a span is handed off
32
+ * for export, closing the narrower window between when a long-running
33
+ * operation's attributes were set and when `span.end()` is finally
34
+ * called.
35
+ *
36
+ * Both are no-ops when the current snapshot still authorizes everything
37
+ * already on the span, so a session whose lease never changes exports
38
+ * exactly what it would have exported before this module existed.
39
+ *
40
+ * This is a privacy boundary, so re-governance fails CLOSED in two tiers
41
+ * rather than fail-open. A policy-lookup or re-governance failure used to
42
+ * leave a span exactly as it was, after which it would export with content
43
+ * the current lease may have revoked. Instead:
44
+ *
45
+ * 1. Replace the attributes with the same withheld-content markers
46
+ * `projectTelemetryContent` produces for a disallowed capture mode. This
47
+ * keeps the span itself -- name, timing, status, parent/child structure
48
+ * -- which is the point of the telemetry, while guaranteeing no governed
49
+ * content ships.
50
+ * 2. Only if even that replacement cannot be written is the span dropped
51
+ * outright: the exporter filters it out and the processor never queues
52
+ * it. A batch left empty by privacy drops reports `SUCCESS`, not
53
+ * `FAILED` -- the drop is a deliberate, permanent verdict, and `FAILED`
54
+ * would have `BatchSpanProcessor` treat it as a retryable transport
55
+ * problem.
56
+ */
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ exports.CeilingReapplyingSpanProcessor = exports.CeilingReapplyingSpanExporter = void 0;
59
+ const core_1 = require("@opentelemetry/core");
60
+ const content_capture_1 = require("./content-capture");
61
+ /** The reason recorded when even the ceiling itself could not be resolved. */
62
+ const POLICY_UNAVAILABLE_AUTHORITY = {
63
+ mode: 'off',
64
+ external: false,
65
+ contentAllowed: false,
66
+ reasonCode: 'policy_unavailable',
67
+ };
68
+ function hasOwn(value, key) {
69
+ return Object.prototype.hasOwnProperty.call(value, key);
70
+ }
71
+ /**
72
+ * Overwrite an already-ended span's attribute mapping in place.
73
+ *
74
+ * Unlike OpenTelemetry Python's `BoundedAttributes` (which freezes on
75
+ * `span.end()` and requires an unsupported private-field thaw), the Node SDK
76
+ * keeps a completed span's `attributes` as a plain, ordinarily-mutable
77
+ * object -- there is no supported *setter*, but replacing its contents does
78
+ * not require fighting an immutability flag. A test that wants to prove the
79
+ * mutation-failure tier freezes that object (`Object.freeze(span.attributes)`),
80
+ * which makes the `delete`/assign below throw, exactly like a real
81
+ * environment where some other guard made the object non-writable.
82
+ *
83
+ * Returns true when the span now carries exactly `attributes`.
84
+ */
85
+ function writeAttributes(span, attributes) {
86
+ try {
87
+ const target = span;
88
+ if (typeof target.attributes !== 'object' || target.attributes === null)
89
+ return false;
90
+ for (const key of Object.keys(target.attributes))
91
+ delete target.attributes[key];
92
+ Object.assign(target.attributes, attributes);
93
+ return true;
94
+ }
95
+ catch {
96
+ return false;
97
+ }
98
+ }
99
+ function attributesEqual(a, b) {
100
+ const aKeys = Object.keys(a);
101
+ if (aKeys.length !== Object.keys(b).length)
102
+ return false;
103
+ return aKeys.every((key) => hasOwn(b, key) && Object.is(a[key], b[key]));
104
+ }
105
+ /**
106
+ * Replace a span's attributes with the known-safe withheld marker set.
107
+ *
108
+ * Used when the ceiling itself could not be computed or applied: a policy
109
+ * lookup or re-governance failure must never leave the stale, possibly
110
+ * unauthorized attributes in place. Nothing the lease might no longer
111
+ * authorize survives -- every content-scoped key is replaced with the exact
112
+ * placeholders `projectTelemetryContent` writes for a disallowed capture
113
+ * mode, reported under `policy_unavailable` since the real reason could not
114
+ * be determined. Non-content attributes (tool name, durations, ids, ...)
115
+ * are untouched: they are not content, so a failure to re-govern content
116
+ * does not require rewriting them.
117
+ *
118
+ * Returns true when the span is safe to export, false when it must be
119
+ * dropped because even this replacement could not be written.
120
+ */
121
+ function withholdContent(span, currentAttributes) {
122
+ try {
123
+ const hasInput = hasOwn(currentAttributes, 'gen_ai.input.messages') || hasOwn(currentAttributes, 'armoriq.content.input');
124
+ const hasOutput = hasOwn(currentAttributes, 'gen_ai.output.messages') || hasOwn(currentAttributes, 'armoriq.content.output');
125
+ const hasToolArguments = hasOwn(currentAttributes, 'gen_ai.tool.call.arguments');
126
+ const hasToolResult = hasOwn(currentAttributes, 'gen_ai.tool.call.result');
127
+ const hasErrorSummary = hasOwn(currentAttributes, 'armoriq.observability.error.summary');
128
+ const presence = {};
129
+ if (hasInput)
130
+ presence.input = undefined;
131
+ if (hasOutput)
132
+ presence.output = undefined;
133
+ if (hasToolArguments)
134
+ presence.toolArguments = undefined;
135
+ if (hasToolResult)
136
+ presence.toolResult = undefined;
137
+ if (hasErrorSummary)
138
+ presence.errorSummary = undefined;
139
+ const projected = (0, content_capture_1.projectTelemetryContent)(presence, POLICY_UNAVAILABLE_AUTHORITY);
140
+ const next = { ...currentAttributes };
141
+ // Unconditional: every content-scoped key is cleared regardless of which
142
+ // fields were present, so an error-summary-only span (no input/output/
143
+ // tool-call keys at all) is still fully purged.
144
+ for (const key of content_capture_1.CONTENT_ATTRIBUTE_KEYS)
145
+ delete next[key];
146
+ Object.assign(next, projected.attributes);
147
+ return writeAttributes(span, next);
148
+ }
149
+ catch {
150
+ // Even reading which content keys are present failed. Nothing on this
151
+ // span can be inspected, so nothing on it can be cleared selectively;
152
+ // strip it to the empty attribute set.
153
+ return writeAttributes(span, {});
154
+ }
155
+ }
156
+ /**
157
+ * Recompute one span's attributes under the policy current right now.
158
+ *
159
+ * Returns true when the span may be exported, false when it must be
160
+ * dropped.
161
+ */
162
+ function reapplyCeiling(runtime, span) {
163
+ let currentAttributes;
164
+ try {
165
+ currentAttributes = { ...(span.attributes ?? {}) };
166
+ }
167
+ catch {
168
+ // The span's own attribute mapping is unreadable. Nothing on it can be
169
+ // inspected, so nothing on it can be cleared selectively.
170
+ return writeAttributes(span, {});
171
+ }
172
+ let governed;
173
+ try {
174
+ const snapshot = runtime.currentCeilingSnapshot();
175
+ governed = runtime.reapplyContentCeiling(snapshot, currentAttributes);
176
+ }
177
+ catch {
178
+ // Policy lookup or re-governance failed. Fail closed rather than ship
179
+ // the span exactly as it was.
180
+ return withholdContent(span, currentAttributes);
181
+ }
182
+ if (attributesEqual(governed, currentAttributes))
183
+ return true;
184
+ if (writeAttributes(span, governed))
185
+ return true;
186
+ // The rewrite that just failed is the only way to purge the stale
187
+ // attributes, so re-governing is impossible; drop rather than ship them.
188
+ return false;
189
+ }
190
+ /**
191
+ * Re-govern span attributes against the CURRENT lease before shipping.
192
+ *
193
+ * This is the true export-time gate: `export` runs whenever the wrapped
194
+ * batching processor actually flushes its buffer, so a span that has been
195
+ * queued for any length of time is re-evaluated against the lease that is
196
+ * authoritative right now, not the one that was authoritative when it was
197
+ * created or ended.
198
+ */
199
+ class CeilingReapplyingSpanExporter {
200
+ exporter;
201
+ runtime;
202
+ constructor(exporter, runtime) {
203
+ this.exporter = exporter;
204
+ this.runtime = runtime;
205
+ }
206
+ export(spans, resultCallback) {
207
+ const exportable = spans.filter((span) => reapplyCeiling(this.runtime, span));
208
+ if (exportable.length === 0) {
209
+ // Every span was dropped for privacy. Report SUCCESS, not FAILED:
210
+ // FAILED tells BatchSpanProcessor the batch did not ship, which it
211
+ // treats as a retryable transport problem. A ceiling drop is a
212
+ // deliberate, permanent decision -- the span must never ship -- so a
213
+ // retry would be pointless work over the same verdict.
214
+ resultCallback({ code: core_1.ExportResultCode.SUCCESS });
215
+ return;
216
+ }
217
+ this.exporter.export(exportable, resultCallback);
218
+ }
219
+ shutdown() {
220
+ return this.exporter.shutdown();
221
+ }
222
+ forceFlush() {
223
+ return this.exporter.forceFlush ? this.exporter.forceFlush() : Promise.resolve();
224
+ }
225
+ }
226
+ exports.CeilingReapplyingSpanExporter = CeilingReapplyingSpanExporter;
227
+ /**
228
+ * Re-govern span attributes at the `onEnd` hand-off boundary.
229
+ *
230
+ * Complements `CeilingReapplyingSpanExporter`: this closes the window
231
+ * between when a span's attributes were last set (which can be well before
232
+ * a long-running operation actually calls `span.end()`) and when it is
233
+ * handed to the wrapped processor for batching. `shutdown`/`forceFlush`
234
+ * delegate to the wrapped processor unchanged -- this class only adds a
235
+ * re-governance step, it does not change close/flush lifecycle semantics.
236
+ */
237
+ class CeilingReapplyingSpanProcessor {
238
+ processor;
239
+ runtime;
240
+ constructor(processor, runtime) {
241
+ this.processor = processor;
242
+ this.runtime = runtime;
243
+ }
244
+ onStart(span, parentContext) {
245
+ this.processor.onStart(span, parentContext);
246
+ }
247
+ onEnd(span) {
248
+ if (!reapplyCeiling(this.runtime, span)) {
249
+ // Undeliverable: the span could not be re-governed and could not be
250
+ // stripped either. Never queue it -- once it is inside the wrapped
251
+ // processor's buffer this module cannot reach it again.
252
+ return;
253
+ }
254
+ this.processor.onEnd(span);
255
+ }
256
+ shutdown() {
257
+ return this.processor.shutdown();
258
+ }
259
+ forceFlush() {
260
+ return this.processor.forceFlush();
261
+ }
262
+ }
263
+ exports.CeilingReapplyingSpanProcessor = CeilingReapplyingSpanProcessor;
264
+ //# sourceMappingURL=otel-export-ceiling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel-export-ceiling.js","sourceRoot":"","sources":["../../src/observability/otel-export-ceiling.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;;;AAIH,8CAAuD;AAEvD,uDAAyI;AAGzI,8EAA8E;AAC9E,MAAM,4BAA4B,GAA4B;IAC5D,IAAI,EAAE,KAAK;IACX,QAAQ,EAAE,KAAK;IACf,cAAc,EAAE,KAAK;IACrB,UAAU,EAAE,oBAAoB;CACjC,CAAC;AAEF,SAAS,MAAM,CAAC,KAAwC,EAAE,GAAW;IACnE,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,eAAe,CAAC,IAAkB,E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AAgB,CAAC,OAAO,EAAE,CAAC,CAAC;YACnD,OAAO;QACT,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACnD,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAClC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IACnF,CAAC;CACF;AA3BD,sEA2BC;AAED;;;;;;;;;GASG;AACH,MAAa,8BAA8B;IAEtB;IACA;IAFnB,YACmB,SAAwB,EACxB,OAAgC;QADhC,cAAS,GAAT,SAAS,CAAe;QACxB,YAAO,GAAP,OAAO,CAAyB;IAChD,CAAC;IAEJ,OAAO,CAAC,IAAU,EAAE,aAAsB;QACxC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,IAAkB;QACtB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;YACxC,oEAAoE;YACpE,mEAAmE;YACnE,wDAAwD;YACxD,OAAO;QACT,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;IACnC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;CACF;AA3BD,wEA2BC"}
@@ -0,0 +1,103 @@
1
+ /** SDK-owned OpenTelemetry runtime. It never registers a global provider. */
2
+ import type { Tracer } from '@opentelemetry/api';
3
+ import { type ObservabilityOptions, type ResolvedOtelConfig } from './otel-config';
4
+ import { type PolicyLease } from './policy-lease';
5
+ import { type ContentCaptureAuthority } from './content-capture';
6
+ export type TelemetryAttributeValue = string | number | boolean | string[];
7
+ export type TelemetryAttributes = Readonly<Record<string, unknown>>;
8
+ export interface AttributeContext {
9
+ traceName: string;
10
+ sessionId: string;
11
+ /** Caller must provide this deliberately. It is sanitized before export. */
12
+ userId?: string | null;
13
+ }
14
+ export interface TelemetryRuntimeOptions {
15
+ backendEndpoint: string;
16
+ apiKey: string;
17
+ sdkVersion: string;
18
+ options?: ObservabilityOptions;
19
+ /** Test/host hook; production defaults to the policy-lease HTTP endpoint. */
20
+ leaseFetcher?: (signal?: AbortSignal) => Promise<PolicyLease>;
21
+ }
22
+ /**
23
+ * Manages one private exporter, or borrows a caller-owned provider. A runtime
24
+ * is request/session scoped and `close()` is idempotent and fail-open.
25
+ */
26
+ export declare class ArmorIQTelemetryRuntime {
27
+ readonly config: ResolvedOtelConfig;
28
+ private readonly backendEndpoint;
29
+ private readonly apiKey;
30
+ private readonly sdkVersion;
31
+ private readonly leaseFetcher?;
32
+ private lease;
33
+ private refreshing;
34
+ private firstExternalAuthorityAwaited;
35
+ private externalAuthorityUnavailable;
36
+ private nextRefreshAt;
37
+ private provider;
38
+ private policyLeaseAbort;
39
+ private readonly ownedAgents;
40
+ private closed;
41
+ constructor(options: TelemetryRuntimeOptions);
42
+ policySnapshot(options?: {
43
+ awaitFresh?: boolean;
44
+ }): Promise<PolicyLease>;
45
+ /** Start at most one control-plane request; request callers never await it. */
46
+ private refreshInBackground;
47
+ private applyCeiling;
48
+ /**
49
+ * The ceiling-applied lease this runtime already knows about, computed
50
+ * synchronously from whatever is cached. Never performs network I/O and
51
+ * never blocks: a batching span processor flushes on its own timer, from
52
+ * whatever thread that is, and must get an immediate answer. When nothing
53
+ * current is cached, this fails closed to the same `authoritative: false`
54
+ * fallback `policySnapshot()` uses, which `applyCeiling` maps to `off`.
55
+ *
56
+ * This is the true export-time gate's policy read: `CeilingReapplyingSpanExporter`
57
+ * and `CeilingReapplyingSpanProcessor` (otel-export-ceiling.ts) call it
58
+ * immediately before a buffered span is allowed to leave the process, so a
59
+ * span queued under a since-revoked lease is re-governed against whatever
60
+ * is authoritative right now -- not whatever was authoritative when the
61
+ * span was created or ended.
62
+ */
63
+ currentCeilingSnapshot(): PolicyLease;
64
+ /**
65
+ * Re-govern a span's already-baked attributes under a (possibly new)
66
+ * policy snapshot. Shares `contentAuthority` -- the exact function that
67
+ * decides content authority at span-creation time -- with
68
+ * `safeAttributesWithAuthority`, so there is exactly one place that
69
+ * defines "is content allowed right now." When it is, every content-bearing
70
+ * key present is re-bounded against the current mode's limits (via
71
+ * `reboundCapturedJson`): a session whose lease never changes and whose
72
+ * mode never changes must export exactly what it would have exported
73
+ * before this method existed, but content captured under debug's looser
74
+ * limits cannot keep those limits once the ceiling has downgraded to
75
+ * enhanced. When capture is not allowed at all, every key in
76
+ * `CONTENT_ATTRIBUTE_KEYS` present on the span is replaced with the same
77
+ * withheld-content markers `projectTelemetryContent` produces at creation
78
+ * time for a disallowed capture mode.
79
+ */
80
+ reapplyContentCeiling(snapshot: PolicyLease, attributes: TelemetryAttributes): Record<string, TelemetryAttributeValue>;
81
+ private fetchPolicyLease;
82
+ tracer(snapshot: PolicyLease): Tracer | null;
83
+ private privateProvider;
84
+ /**
85
+ * Construct the OTLP delegate from explicit values. The convenience
86
+ * exporter reads process.env while merging defaults, which could leak a
87
+ * caller's external headers into an ArmorIQ-only exporter.
88
+ */
89
+ private createExporter;
90
+ safeAttributes(snapshot: PolicyLease, attributes: TelemetryAttributes, context: AttributeContext): Record<string, TelemetryAttributeValue>;
91
+ /** Final tool boundary: retain safe lifecycle facts and content-state markers even when capture is now off. */
92
+ finalToolAttributes(snapshot: PolicyLease, attributes: TelemetryAttributes, context: AttributeContext): Record<string, TelemetryAttributeValue>;
93
+ private safeAttributesWithAuthority;
94
+ private externalAttributeAllowed;
95
+ /** Shared by span-creation attribute assembly and export-time re-governance. */
96
+ contentAuthority(snapshot: PolicyLease, external: boolean): ContentCaptureAuthority;
97
+ private extractContent;
98
+ /** Stable, externally safe root span names prevent identifier leakage. */
99
+ externalTraceName(value: string): string;
100
+ forceFlush(): Promise<void>;
101
+ close(): Promise<void>;
102
+ }
103
+ //# sourceMappingURL=otel-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel-runtime.d.ts","sourceRoot":"","sources":["../../src/observability/otel-runtime.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAOjD,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAIL,KAAK,uBAAuB,EAG7B,MAAM,mBAAmB,CAAC;AAI3B,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAC;AAC3E,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEpE,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,6EAA6E;IAC7E,YAAY,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;CAC/D;AAkLD;;;GAGG;AACH,qBAAa,uBAAuB;IAClC,QAAQ,CAA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