agentfootprint 2.8.1 → 2.8.3
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.
- package/dist/adapters/observability/agentcore.js +14 -138
- package/dist/adapters/observability/agentcore.js.map +1 -1
- package/dist/adapters/observability/cloudwatch.js +203 -0
- package/dist/adapters/observability/cloudwatch.js.map +1 -0
- package/dist/adapters/observability/xray.js +370 -0
- package/dist/adapters/observability/xray.js.map +1 -0
- package/dist/esm/adapters/observability/agentcore.js +14 -138
- package/dist/esm/adapters/observability/agentcore.js.map +1 -1
- package/dist/esm/adapters/observability/cloudwatch.js +198 -0
- package/dist/esm/adapters/observability/cloudwatch.js.map +1 -0
- package/dist/esm/adapters/observability/xray.js +366 -0
- package/dist/esm/adapters/observability/xray.js.map +1 -0
- package/dist/esm/observability-providers.js +4 -2
- package/dist/esm/observability-providers.js.map +1 -1
- package/dist/observability-providers.js +7 -3
- package/dist/observability-providers.js.map +1 -1
- package/dist/types/adapters/observability/agentcore.d.ts +21 -40
- package/dist/types/adapters/observability/agentcore.d.ts.map +1 -1
- package/dist/types/adapters/observability/cloudwatch.d.ts +97 -0
- package/dist/types/adapters/observability/cloudwatch.d.ts.map +1 -0
- package/dist/types/adapters/observability/xray.d.ts +83 -0
- package/dist/types/adapters/observability/xray.d.ts.map +1 -0
- package/dist/types/observability-providers.d.ts +4 -2
- package/dist/types/observability-providers.d.ts.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* xrayObservability — AWS X-Ray distributed-tracing adapter.
|
|
4
|
+
*
|
|
5
|
+
* Maps agentfootprint's event taxonomy onto AWS X-Ray segment trees:
|
|
6
|
+
*
|
|
7
|
+
* agent.turn_start ↦ root segment (one trace per turn)
|
|
8
|
+
* agent.turn_end ↦ close root segment + flush
|
|
9
|
+
* agent.iteration_start ↦ push subsegment under root
|
|
10
|
+
* agent.iteration_end ↦ close iteration subsegment
|
|
11
|
+
* stream.llm_start ↦ push leaf subsegment (model call)
|
|
12
|
+
* stream.llm_end ↦ close llm subsegment
|
|
13
|
+
* stream.tool_start ↦ push leaf subsegment (tool call)
|
|
14
|
+
* stream.tool_end ↦ close tool subsegment
|
|
15
|
+
*
|
|
16
|
+
* The result in the X-Ray Trace Map: a hierarchical timeline of every
|
|
17
|
+
* agent run — turn → iteration → llm-call/tool-call — queryable in
|
|
18
|
+
* X-Ray Insights, joinable with the rest of your AWS distributed
|
|
19
|
+
* trace via `AWSTraceHeader` propagation (consumer's responsibility
|
|
20
|
+
* to wire upstream/downstream IDs).
|
|
21
|
+
*
|
|
22
|
+
* Subpath: `agentfootprint/observability-providers`
|
|
23
|
+
* Peer dep: `@aws-sdk/client-xray` (OPTIONAL — installed only when
|
|
24
|
+
* this adapter is used).
|
|
25
|
+
*
|
|
26
|
+
* Sampling:
|
|
27
|
+
* By default every turn produces one trace. Pass `sampleRate: 0.1`
|
|
28
|
+
* to sample 10% of turns — sampling decisions are made at
|
|
29
|
+
* `turn_start` and persist for the whole turn (so partial traces
|
|
30
|
+
* never reach X-Ray).
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { xrayObservability } from 'agentfootprint/observability-providers';
|
|
35
|
+
* import { microtaskBatchDriver } from 'footprintjs/detach';
|
|
36
|
+
*
|
|
37
|
+
* agent.enable.observability({
|
|
38
|
+
* strategy: xrayObservability({
|
|
39
|
+
* region: 'us-east-1',
|
|
40
|
+
* serviceName: 'my-agent',
|
|
41
|
+
* sampleRate: 0.1, // 10% sampling
|
|
42
|
+
* }),
|
|
43
|
+
* detach: { driver: microtaskBatchDriver, mode: 'forget' },
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example Test injection
|
|
48
|
+
* ```ts
|
|
49
|
+
* xrayObservability({
|
|
50
|
+
* serviceName: 'test',
|
|
51
|
+
* _client: {
|
|
52
|
+
* putTraceSegments: async (input) => { capturedDocs.push(input); },
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
exports.xrayObservability = void 0;
|
|
59
|
+
const lazyRequire_js_1 = require("../../lib/lazyRequire.js");
|
|
60
|
+
// ─── Strategy factory ────────────────────────────────────────────────
|
|
61
|
+
function xrayObservability(opts) {
|
|
62
|
+
if (!opts.serviceName) {
|
|
63
|
+
throw new TypeError(`[xrayObservability] \`serviceName\` is required. ` +
|
|
64
|
+
`Pass an identifier visible in your X-Ray service map, e.g. 'my-agent-prod'.`);
|
|
65
|
+
}
|
|
66
|
+
const sampleRate = opts.sampleRate ?? 1;
|
|
67
|
+
const maxBatchSegments = opts.maxBatchSegments ?? 25;
|
|
68
|
+
const flushIntervalMs = opts.flushIntervalMs ?? 1000;
|
|
69
|
+
// Per-turn state. agentfootprint events arrive interleaved across
|
|
70
|
+
// multiple in-flight turns; we key the active stack by `runId`
|
|
71
|
+
// (every event payload carries it after enrichment).
|
|
72
|
+
const activeTurns = new Map();
|
|
73
|
+
// Outbound segment buffer (flat list of closed segments ready for
|
|
74
|
+
// PutTraceSegments). Drained by flush() / size-trigger / time-trigger.
|
|
75
|
+
const outbox = [];
|
|
76
|
+
let lastFlushPromise = Promise.resolve();
|
|
77
|
+
let timer;
|
|
78
|
+
let stopped = false;
|
|
79
|
+
let onErrorHook;
|
|
80
|
+
// Lazy SDK client.
|
|
81
|
+
let client = opts._client;
|
|
82
|
+
function ensureClient() {
|
|
83
|
+
if (client)
|
|
84
|
+
return client;
|
|
85
|
+
client = createXRayClient(opts.region);
|
|
86
|
+
return client;
|
|
87
|
+
}
|
|
88
|
+
function scheduleTimedFlush() {
|
|
89
|
+
if (timer || flushIntervalMs <= 0 || stopped)
|
|
90
|
+
return;
|
|
91
|
+
timer = setTimeout(() => {
|
|
92
|
+
timer = undefined;
|
|
93
|
+
void doFlush();
|
|
94
|
+
}, flushIntervalMs);
|
|
95
|
+
}
|
|
96
|
+
async function doFlush() {
|
|
97
|
+
if (outbox.length === 0 || stopped)
|
|
98
|
+
return;
|
|
99
|
+
const batch = outbox.splice(0, maxBatchSegments);
|
|
100
|
+
try {
|
|
101
|
+
await ensureClient().putTraceSegments({
|
|
102
|
+
TraceSegmentDocuments: batch.map((s) => JSON.stringify(s)),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
onErrorHook?.(err instanceof Error ? err : new Error(String(err)));
|
|
107
|
+
}
|
|
108
|
+
// If outbox grew during the put (size > maxBatchSegments emits
|
|
109
|
+
// arrived), chain another flush.
|
|
110
|
+
if (outbox.length > 0 && !stopped) {
|
|
111
|
+
lastFlushPromise = lastFlushPromise.then(doFlush, doFlush);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function pushSegment(turnState, name) {
|
|
115
|
+
const parent = turnState.stack[turnState.stack.length - 1];
|
|
116
|
+
const seg = {
|
|
117
|
+
name,
|
|
118
|
+
id: hexId(16),
|
|
119
|
+
trace_id: turnState.traceId,
|
|
120
|
+
...(parent && { parent_id: parent.id }),
|
|
121
|
+
start_time: nowSeconds(),
|
|
122
|
+
in_progress: true,
|
|
123
|
+
};
|
|
124
|
+
turnState.stack.push(seg);
|
|
125
|
+
return seg;
|
|
126
|
+
}
|
|
127
|
+
function popSegment(turnState, expectedName) {
|
|
128
|
+
// Defensive: pop the topmost segment whose name matches (if
|
|
129
|
+
// provided). Out-of-order events would otherwise leave dangling
|
|
130
|
+
// segments. If no match, pop the topmost.
|
|
131
|
+
let idx = turnState.stack.length - 1;
|
|
132
|
+
if (expectedName) {
|
|
133
|
+
while (idx >= 0 && turnState.stack[idx].name !== expectedName)
|
|
134
|
+
idx--;
|
|
135
|
+
}
|
|
136
|
+
if (idx < 0)
|
|
137
|
+
return undefined;
|
|
138
|
+
const seg = turnState.stack.splice(idx, 1)[0];
|
|
139
|
+
seg.end_time = nowSeconds();
|
|
140
|
+
delete seg.in_progress;
|
|
141
|
+
return seg;
|
|
142
|
+
}
|
|
143
|
+
function closeSegment(turnState, expectedName, extra) {
|
|
144
|
+
const seg = popSegment(turnState, expectedName);
|
|
145
|
+
if (!seg)
|
|
146
|
+
return;
|
|
147
|
+
if (extra?.error)
|
|
148
|
+
seg.error = true;
|
|
149
|
+
if (extra?.annotations)
|
|
150
|
+
seg.annotations = { ...seg.annotations, ...extra.annotations };
|
|
151
|
+
if (extra?.metadata)
|
|
152
|
+
seg.metadata = { default: { ...(seg.metadata?.default ?? {}), ...extra.metadata } };
|
|
153
|
+
if (turnState.sampled) {
|
|
154
|
+
turnState.closed.push(seg);
|
|
155
|
+
// Once the root closes, the whole turn graduates to outbox.
|
|
156
|
+
if (turnState.stack.length === 0) {
|
|
157
|
+
outbox.push(...turnState.closed);
|
|
158
|
+
if (outbox.length >= maxBatchSegments) {
|
|
159
|
+
lastFlushPromise = lastFlushPromise.then(doFlush, doFlush);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
scheduleTimedFlush();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// ─── Event-to-segment dispatch ─────────────────────────────────────
|
|
168
|
+
function handleEvent(event) {
|
|
169
|
+
if (stopped)
|
|
170
|
+
return;
|
|
171
|
+
const runId = event.payload?.runId;
|
|
172
|
+
if (!runId)
|
|
173
|
+
return; // Events without a turn anchor — skip.
|
|
174
|
+
switch (event.type) {
|
|
175
|
+
case 'agentfootprint.agent.turn_start': {
|
|
176
|
+
const sampled = sampleRate >= 1 || Math.random() < sampleRate;
|
|
177
|
+
const turnState = {
|
|
178
|
+
traceId: makeTraceId(),
|
|
179
|
+
stack: [],
|
|
180
|
+
closed: [],
|
|
181
|
+
sampled,
|
|
182
|
+
};
|
|
183
|
+
activeTurns.set(runId, turnState);
|
|
184
|
+
if (sampled)
|
|
185
|
+
pushSegment(turnState, opts.serviceName);
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
case 'agentfootprint.agent.turn_end': {
|
|
189
|
+
const t = activeTurns.get(runId);
|
|
190
|
+
if (!t)
|
|
191
|
+
break;
|
|
192
|
+
// Close everything still on the stack — defensive against
|
|
193
|
+
// missing `_end` events (e.g., pause/resume mid-turn).
|
|
194
|
+
while (t.stack.length > 0)
|
|
195
|
+
closeSegment(t, undefined);
|
|
196
|
+
activeTurns.delete(runId);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case 'agentfootprint.agent.iteration_start': {
|
|
200
|
+
const t = activeTurns.get(runId);
|
|
201
|
+
if (t?.sampled)
|
|
202
|
+
pushSegment(t, `iteration:${event.payload.iteration ?? '?'}`);
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case 'agentfootprint.agent.iteration_end': {
|
|
206
|
+
const t = activeTurns.get(runId);
|
|
207
|
+
if (t?.sampled)
|
|
208
|
+
closeSegment(t, undefined);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case 'agentfootprint.stream.llm_start': {
|
|
212
|
+
const t = activeTurns.get(runId);
|
|
213
|
+
if (!t?.sampled)
|
|
214
|
+
break;
|
|
215
|
+
const seg = pushSegment(t, 'llm');
|
|
216
|
+
const model = event.payload.model;
|
|
217
|
+
if (model)
|
|
218
|
+
seg.annotations = { model };
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
case 'agentfootprint.stream.llm_end': {
|
|
222
|
+
const t = activeTurns.get(runId);
|
|
223
|
+
if (!t?.sampled)
|
|
224
|
+
break;
|
|
225
|
+
closeSegment(t, 'llm', {
|
|
226
|
+
metadata: { event: event.payload },
|
|
227
|
+
});
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case 'agentfootprint.stream.tool_start': {
|
|
231
|
+
const t = activeTurns.get(runId);
|
|
232
|
+
if (!t?.sampled)
|
|
233
|
+
break;
|
|
234
|
+
const toolName = event.payload.toolName ?? 'tool';
|
|
235
|
+
const seg = pushSegment(t, `tool:${toolName}`);
|
|
236
|
+
seg.annotations = { toolName };
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
case 'agentfootprint.stream.tool_end': {
|
|
240
|
+
const t = activeTurns.get(runId);
|
|
241
|
+
if (!t?.sampled)
|
|
242
|
+
break;
|
|
243
|
+
const toolName = event.payload.toolName;
|
|
244
|
+
closeSegment(t, toolName ? `tool:${toolName}` : undefined, {
|
|
245
|
+
error: event.payload.error !== undefined,
|
|
246
|
+
});
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
// Other events become annotations on the topmost active segment
|
|
250
|
+
// (cheaper than spawning a subsegment per event).
|
|
251
|
+
default: {
|
|
252
|
+
const t = activeTurns.get(runId);
|
|
253
|
+
const top = t?.stack[t.stack.length - 1];
|
|
254
|
+
if (!t?.sampled || !top)
|
|
255
|
+
break;
|
|
256
|
+
// Annotate cost ticks specially so they're queryable in
|
|
257
|
+
// X-Ray Insights.
|
|
258
|
+
if (event.type === 'agentfootprint.cost.tick') {
|
|
259
|
+
const p = event.payload;
|
|
260
|
+
if (typeof p.cumulativeCostUsd === 'number') {
|
|
261
|
+
top.annotations = { ...top.annotations, cumulativeCostUsd: p.cumulativeCostUsd };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
name: 'xray',
|
|
270
|
+
capabilities: { events: true, traces: true },
|
|
271
|
+
exportEvent: handleEvent,
|
|
272
|
+
async flush() {
|
|
273
|
+
// Force-close any in-flight turn segments so partial traces
|
|
274
|
+
// make it into X-Ray on shutdown.
|
|
275
|
+
for (const [, t] of activeTurns) {
|
|
276
|
+
if (!t.sampled)
|
|
277
|
+
continue;
|
|
278
|
+
while (t.stack.length > 0)
|
|
279
|
+
closeSegment(t, undefined);
|
|
280
|
+
}
|
|
281
|
+
while (outbox.length > 0) {
|
|
282
|
+
const before = lastFlushPromise;
|
|
283
|
+
await before;
|
|
284
|
+
if (outbox.length > 0) {
|
|
285
|
+
lastFlushPromise = doFlush();
|
|
286
|
+
}
|
|
287
|
+
if (lastFlushPromise === before && outbox.length === 0)
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
stop() {
|
|
292
|
+
stopped = true;
|
|
293
|
+
if (timer) {
|
|
294
|
+
clearTimeout(timer);
|
|
295
|
+
timer = undefined;
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
_onError(err, event) {
|
|
299
|
+
onErrorHook =
|
|
300
|
+
onErrorHook ??
|
|
301
|
+
((e) => {
|
|
302
|
+
// eslint-disable-next-line no-console
|
|
303
|
+
console.error(`[xrayObservability] flush failed:`, e.message);
|
|
304
|
+
});
|
|
305
|
+
onErrorHook(err, event);
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
exports.xrayObservability = xrayObservability;
|
|
310
|
+
// ─── ID + time helpers ───────────────────────────────────────────────
|
|
311
|
+
/**
|
|
312
|
+
* Generate an X-Ray trace ID. Format:
|
|
313
|
+
* `1-{8-hex-of-unix-timestamp}-{24-hex-random}`
|
|
314
|
+
* (Note X-Ray's docs say "12 hex" for the random part; the actual
|
|
315
|
+
* spec is 24 hex / 96-bit. AWS examples use 24.)
|
|
316
|
+
*/
|
|
317
|
+
function makeTraceId() {
|
|
318
|
+
const seconds = Math.floor(Date.now() / 1000);
|
|
319
|
+
return `1-${seconds.toString(16).padStart(8, '0')}-${hexId(24)}`;
|
|
320
|
+
}
|
|
321
|
+
/** Generate a hex string of `len` chars, cryptographically-strong
|
|
322
|
+
* where available, falling back to Math.random for environments
|
|
323
|
+
* without `crypto.getRandomValues` (older runtimes). */
|
|
324
|
+
function hexId(len) {
|
|
325
|
+
const bytes = Math.ceil(len / 2);
|
|
326
|
+
// Try the Web Crypto / Node Crypto API first.
|
|
327
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
328
|
+
const cryptoApi = globalThis.crypto;
|
|
329
|
+
if (cryptoApi?.getRandomValues) {
|
|
330
|
+
const buf = new Uint8Array(bytes);
|
|
331
|
+
cryptoApi.getRandomValues(buf);
|
|
332
|
+
return Array.from(buf, (b) => b.toString(16).padStart(2, '0'))
|
|
333
|
+
.join('')
|
|
334
|
+
.slice(0, len);
|
|
335
|
+
}
|
|
336
|
+
// Fallback (deterministic-quality, NOT for security-critical IDs —
|
|
337
|
+
// X-Ray IDs aren't security boundaries, just trace correlation).
|
|
338
|
+
let s = '';
|
|
339
|
+
while (s.length < len)
|
|
340
|
+
s += Math.random().toString(16).slice(2);
|
|
341
|
+
return s.slice(0, len);
|
|
342
|
+
}
|
|
343
|
+
/** X-Ray timestamps are unix seconds with fractional precision. */
|
|
344
|
+
function nowSeconds() {
|
|
345
|
+
return Date.now() / 1000;
|
|
346
|
+
}
|
|
347
|
+
// ─── SDK construction (lazy) ─────────────────────────────────────────
|
|
348
|
+
function createXRayClient(region) {
|
|
349
|
+
let mod;
|
|
350
|
+
try {
|
|
351
|
+
mod = (0, lazyRequire_js_1.lazyRequire)('@aws-sdk/client-xray');
|
|
352
|
+
}
|
|
353
|
+
catch {
|
|
354
|
+
throw new Error('xrayObservability requires the `@aws-sdk/client-xray` peer dependency.\n' +
|
|
355
|
+
' Install: npm install @aws-sdk/client-xray\n' +
|
|
356
|
+
' Or pass `_client` for test injection.');
|
|
357
|
+
}
|
|
358
|
+
if (!mod.XRayClient || !mod.PutTraceSegmentsCommand) {
|
|
359
|
+
throw new Error('xrayObservability: `@aws-sdk/client-xray` is installed but `XRayClient` / ' +
|
|
360
|
+
'`PutTraceSegmentsCommand` was not found. Update the SDK.');
|
|
361
|
+
}
|
|
362
|
+
const sdkClient = new mod.XRayClient({ ...(region && { region }) });
|
|
363
|
+
return {
|
|
364
|
+
async putTraceSegments(input) {
|
|
365
|
+
const cmd = new mod.PutTraceSegmentsCommand(input);
|
|
366
|
+
await sdkClient.send(cmd);
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=xray.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xray.js","sourceRoot":"","sources":["../../../src/adapters/observability/xray.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;;;AAGH,6DAAuD;AAyDvD,wEAAwE;AAExE,SAAgB,iBAAiB,CAAC,IAA8B;IAC9D,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACtB,MAAM,IAAI,SAAS,CACjB,mDAAmD;YACjD,6EAA6E,CAChF,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC;IACxC,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,IAAI,EAAE,CAAC;IACrD,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC;IAErD,kEAAkE;IAClE,+DAA+D;IAC/D,qDAAqD;IACrD,MAAM,WAAW,GAAG,IAAI,GAAG,EAQxB,CAAC;IAEJ,kEAAkE;IAClE,uEAAuE;IACvE,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,IAAI,gBAAgB,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IACxD,IAAI,KAAgD,CAAC;IACrD,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,WAA4E,CAAC;IAEjF,mBAAmB;IACnB,IAAI,MAAM,GAA+B,IAAI,CAAC,OAAO,CAAC;IACtD,SAAS,YAAY;QACnB,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QAC1B,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,SAAS,kBAAkB;QACzB,IAAI,KAAK,IAAI,eAAe,IAA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AAM,EAAE,CAAC,EAAE,CAEjE,CAAC;IACF,OAAO;QACL,KAAK,CAAC,gBAAgB,CAAC,KAAK;YAC1B,MAAM,GAAG,GAAG,IAAK,GAAG,CAAC,uBAAuD,CAAC,KAAK,CAAC,CAAC;YACpF,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
* only when this adapter is used; declared via
|
|
17
17
|
* `peerDependenciesMeta.{name}.optional = true`).
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
19
|
+
* **Implementation:** thin wrapper over `cloudwatchObservability`'s
|
|
20
|
+
* shared base. The only difference is the strategy `name` (used for
|
|
21
|
+
* registry lookup + diagnostics). All batching, flush, error-routing,
|
|
22
|
+
* and SDK-loading behavior is identical. As we evolve the CloudWatch
|
|
23
|
+
* shipping path (retry, sequence tokens, metrics emission), every
|
|
24
|
+
* CloudWatch-shaped adapter inherits the improvement.
|
|
24
25
|
*
|
|
25
26
|
* @example Basic
|
|
26
27
|
* ```ts
|
|
@@ -46,139 +47,14 @@
|
|
|
46
47
|
* });
|
|
47
48
|
* ```
|
|
48
49
|
*/
|
|
49
|
-
import {
|
|
50
|
-
|
|
50
|
+
import { _buildCloudWatchObservability, } from './cloudwatch.js';
|
|
51
|
+
/**
|
|
52
|
+
* Build an AgentCore-flavored CloudWatch Logs observability strategy.
|
|
53
|
+
* Functionally identical to `cloudwatchObservability` except for the
|
|
54
|
+
* strategy `name`, which lets registry-lookup + diagnostics
|
|
55
|
+
* distinguish AgentCore-targeted shipping from generic CloudWatch.
|
|
56
|
+
*/
|
|
51
57
|
export function agentcoreObservability(opts) {
|
|
52
|
-
|
|
53
|
-
throw new TypeError(`[agentcoreObservability] \`logGroupName\` is required. ` +
|
|
54
|
-
`Pass an existing CloudWatch log group, e.g. '/agentfootprint/my-agent'.`);
|
|
55
|
-
}
|
|
56
|
-
const logStreamName = opts.logStreamName ?? 'agentfootprint';
|
|
57
|
-
const maxBatchEvents = opts.maxBatchEvents ?? 100;
|
|
58
|
-
const maxBatchBytes = opts.maxBatchBytes ?? 10_240;
|
|
59
|
-
const flushIntervalMs = opts.flushIntervalMs ?? 1000;
|
|
60
|
-
// Buffered batch — drained by `flush()` / size-trigger / time-trigger.
|
|
61
|
-
const buffer = [];
|
|
62
|
-
let bufferBytes = 0;
|
|
63
|
-
let lastFlushPromise = Promise.resolve();
|
|
64
|
-
let timer;
|
|
65
|
-
let stopped = false;
|
|
66
|
-
let onErrorHook;
|
|
67
|
-
// Lazy-resolved on first flush so consumers who never trigger a
|
|
68
|
-
// flush (because nothing was emitted) don't even hit the SDK.
|
|
69
|
-
let client = opts._client;
|
|
70
|
-
function ensureClient() {
|
|
71
|
-
if (client)
|
|
72
|
-
return client;
|
|
73
|
-
client = createCloudWatchClient(opts.region);
|
|
74
|
-
return client;
|
|
75
|
-
}
|
|
76
|
-
function scheduleTimedFlush() {
|
|
77
|
-
if (timer || flushIntervalMs <= 0 || stopped)
|
|
78
|
-
return;
|
|
79
|
-
timer = setTimeout(() => {
|
|
80
|
-
timer = undefined;
|
|
81
|
-
void doFlush();
|
|
82
|
-
}, flushIntervalMs);
|
|
83
|
-
}
|
|
84
|
-
async function doFlush() {
|
|
85
|
-
if (buffer.length === 0 || stopped)
|
|
86
|
-
return;
|
|
87
|
-
// Snapshot + clear so concurrent emits during the in-flight put
|
|
88
|
-
// accumulate into the next batch.
|
|
89
|
-
const batch = buffer.splice(0);
|
|
90
|
-
bufferBytes = 0;
|
|
91
|
-
try {
|
|
92
|
-
await ensureClient().putLogEvents({
|
|
93
|
-
logGroupName: opts.logGroupName,
|
|
94
|
-
logStreamName,
|
|
95
|
-
logEvents: batch,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
catch (err) {
|
|
99
|
-
onErrorHook?.(err instanceof Error ? err : new Error(String(err)));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function enqueue(event) {
|
|
103
|
-
if (stopped)
|
|
104
|
-
return;
|
|
105
|
-
const message = JSON.stringify(event);
|
|
106
|
-
const bytes = Buffer.byteLength(message, 'utf8');
|
|
107
|
-
buffer.push({ timestamp: Date.now(), message });
|
|
108
|
-
bufferBytes += bytes;
|
|
109
|
-
if (buffer.length >= maxBatchEvents || bufferBytes >= maxBatchBytes) {
|
|
110
|
-
// Size trigger — flush immediately. Chain onto last to preserve
|
|
111
|
-
// CloudWatch's per-stream ordering requirement.
|
|
112
|
-
lastFlushPromise = lastFlushPromise.then(doFlush, doFlush);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
scheduleTimedFlush();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
name: 'agentcore',
|
|
120
|
-
capabilities: { events: true, logs: true },
|
|
121
|
-
exportEvent: enqueue,
|
|
122
|
-
async flush() {
|
|
123
|
-
// Drain anything pending. Awaits both an in-flight put AND any
|
|
124
|
-
// newly-buffered events that arrived during it.
|
|
125
|
-
while (buffer.length > 0 || lastFlushPromise !== Promise.resolve()) {
|
|
126
|
-
const before = lastFlushPromise;
|
|
127
|
-
await before;
|
|
128
|
-
if (buffer.length > 0) {
|
|
129
|
-
lastFlushPromise = doFlush();
|
|
130
|
-
}
|
|
131
|
-
// Loop one more pass if the chained doFlush() queued more
|
|
132
|
-
// work, then bail.
|
|
133
|
-
if (lastFlushPromise === before && buffer.length === 0)
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
stop() {
|
|
138
|
-
stopped = true;
|
|
139
|
-
if (timer) {
|
|
140
|
-
clearTimeout(timer);
|
|
141
|
-
timer = undefined;
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
_onError(err, event) {
|
|
145
|
-
// Capture for use inside doFlush (the strategy doesn't know what
|
|
146
|
-
// the consumer's error sink is unless they wire `_onError` via
|
|
147
|
-
// the strategy options. We store it on this hook so put-failures
|
|
148
|
-
// route correctly).
|
|
149
|
-
onErrorHook =
|
|
150
|
-
onErrorHook ??
|
|
151
|
-
((e) => {
|
|
152
|
-
// eslint-disable-next-line no-console
|
|
153
|
-
console.error('[agentcoreObservability] flush failed:', e.message);
|
|
154
|
-
});
|
|
155
|
-
onErrorHook(err, event);
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
// ─── SDK client construction (lazy) ──────────────────────────────────
|
|
160
|
-
function createCloudWatchClient(region) {
|
|
161
|
-
let mod;
|
|
162
|
-
try {
|
|
163
|
-
mod = lazyRequire('@aws-sdk/client-cloudwatch-logs');
|
|
164
|
-
}
|
|
165
|
-
catch {
|
|
166
|
-
throw new Error('agentcoreObservability requires the `@aws-sdk/client-cloudwatch-logs` peer dependency.\n' +
|
|
167
|
-
' Install: npm install @aws-sdk/client-cloudwatch-logs\n' +
|
|
168
|
-
' Or pass `_client` for test injection.');
|
|
169
|
-
}
|
|
170
|
-
if (!mod.CloudWatchLogsClient || !mod.PutLogEventsCommand) {
|
|
171
|
-
throw new Error('agentcoreObservability: `@aws-sdk/client-cloudwatch-logs` is installed but ' +
|
|
172
|
-
'`CloudWatchLogsClient` / `PutLogEventsCommand` was not found. Update the SDK.');
|
|
173
|
-
}
|
|
174
|
-
const sdkClient = new mod.CloudWatchLogsClient({ ...(region && { region }) });
|
|
175
|
-
return {
|
|
176
|
-
async putLogEvents(input) {
|
|
177
|
-
// Cast the SDK constructor to the call shape — same trick as the
|
|
178
|
-
// memory adapter to stay forward-compat with SDK shape drift.
|
|
179
|
-
const cmd = new mod.PutLogEventsCommand(input);
|
|
180
|
-
await sdkClient.send(cmd);
|
|
181
|
-
},
|
|
182
|
-
};
|
|
58
|
+
return _buildCloudWatchObservability(opts, 'agentcore');
|
|
183
59
|
}
|
|
184
60
|
//# sourceMappingURL=agentcore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentcore.js","sourceRoot":"","sources":["../../../../src/adapters/observability/agentcore.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"agentcore.js","sourceRoot":"","sources":["../../../../src/adapters/observability/agentcore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAIH,OAAO,EACL,6BAA6B,GAE9B,MAAM,iBAAiB,CAAC;AAWzB;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAmC;IACxE,OAAO,6BAA6B,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAC1D,CAAC"}
|