agentfootprint 2.8.1 → 2.8.2

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.
@@ -17,11 +17,12 @@
17
17
  * only when this adapter is used; declared via
18
18
  * `peerDependenciesMeta.{name}.optional = true`).
19
19
  *
20
- * Pattern: Adapter (GoF) translates `AgentfootprintEvent`
21
- * CloudWatch Logs `PutLogEvents` payloads. Buffers in
22
- * `exportEvent()` (sync, non-throwing); flushes in `flush()`
23
- * (async batch). Default flush window: 1s OR 10 KB,
24
- * whichever first matches CloudWatch's own optimal batch.
20
+ * **Implementation:** thin wrapper over `cloudwatchObservability`'s
21
+ * shared base. The only difference is the strategy `name` (used for
22
+ * registry lookup + diagnostics). All batching, flush, error-routing,
23
+ * and SDK-loading behavior is identical. As we evolve the CloudWatch
24
+ * shipping path (retry, sequence tokens, metrics emission), every
25
+ * CloudWatch-shaped adapter inherits the improvement.
25
26
  *
26
27
  * @example Basic
27
28
  * ```ts
@@ -49,140 +50,15 @@
49
50
  */
50
51
  Object.defineProperty(exports, "__esModule", { value: true });
51
52
  exports.agentcoreObservability = void 0;
52
- const lazyRequire_js_1 = require("../../lib/lazyRequire.js");
53
- // ─── Strategy factory ────────────────────────────────────────────────
53
+ const cloudwatch_js_1 = require("./cloudwatch.js");
54
+ /**
55
+ * Build an AgentCore-flavored CloudWatch Logs observability strategy.
56
+ * Functionally identical to `cloudwatchObservability` except for the
57
+ * strategy `name`, which lets registry-lookup + diagnostics
58
+ * distinguish AgentCore-targeted shipping from generic CloudWatch.
59
+ */
54
60
  function agentcoreObservability(opts) {
55
- if (!opts.logGroupName) {
56
- throw new TypeError(`[agentcoreObservability] \`logGroupName\` is required. ` +
57
- `Pass an existing CloudWatch log group, e.g. '/agentfootprint/my-agent'.`);
58
- }
59
- const logStreamName = opts.logStreamName ?? 'agentfootprint';
60
- const maxBatchEvents = opts.maxBatchEvents ?? 100;
61
- const maxBatchBytes = opts.maxBatchBytes ?? 10_240;
62
- const flushIntervalMs = opts.flushIntervalMs ?? 1000;
63
- // Buffered batch — drained by `flush()` / size-trigger / time-trigger.
64
- const buffer = [];
65
- let bufferBytes = 0;
66
- let lastFlushPromise = Promise.resolve();
67
- let timer;
68
- let stopped = false;
69
- let onErrorHook;
70
- // Lazy-resolved on first flush so consumers who never trigger a
71
- // flush (because nothing was emitted) don't even hit the SDK.
72
- let client = opts._client;
73
- function ensureClient() {
74
- if (client)
75
- return client;
76
- client = createCloudWatchClient(opts.region);
77
- return client;
78
- }
79
- function scheduleTimedFlush() {
80
- if (timer || flushIntervalMs <= 0 || stopped)
81
- return;
82
- timer = setTimeout(() => {
83
- timer = undefined;
84
- void doFlush();
85
- }, flushIntervalMs);
86
- }
87
- async function doFlush() {
88
- if (buffer.length === 0 || stopped)
89
- return;
90
- // Snapshot + clear so concurrent emits during the in-flight put
91
- // accumulate into the next batch.
92
- const batch = buffer.splice(0);
93
- bufferBytes = 0;
94
- try {
95
- await ensureClient().putLogEvents({
96
- logGroupName: opts.logGroupName,
97
- logStreamName,
98
- logEvents: batch,
99
- });
100
- }
101
- catch (err) {
102
- onErrorHook?.(err instanceof Error ? err : new Error(String(err)));
103
- }
104
- }
105
- function enqueue(event) {
106
- if (stopped)
107
- return;
108
- const message = JSON.stringify(event);
109
- const bytes = Buffer.byteLength(message, 'utf8');
110
- buffer.push({ timestamp: Date.now(), message });
111
- bufferBytes += bytes;
112
- if (buffer.length >= maxBatchEvents || bufferBytes >= maxBatchBytes) {
113
- // Size trigger — flush immediately. Chain onto last to preserve
114
- // CloudWatch's per-stream ordering requirement.
115
- lastFlushPromise = lastFlushPromise.then(doFlush, doFlush);
116
- }
117
- else {
118
- scheduleTimedFlush();
119
- }
120
- }
121
- return {
122
- name: 'agentcore',
123
- capabilities: { events: true, logs: true },
124
- exportEvent: enqueue,
125
- async flush() {
126
- // Drain anything pending. Awaits both an in-flight put AND any
127
- // newly-buffered events that arrived during it.
128
- while (buffer.length > 0 || lastFlushPromise !== Promise.resolve()) {
129
- const before = lastFlushPromise;
130
- await before;
131
- if (buffer.length > 0) {
132
- lastFlushPromise = doFlush();
133
- }
134
- // Loop one more pass if the chained doFlush() queued more
135
- // work, then bail.
136
- if (lastFlushPromise === before && buffer.length === 0)
137
- break;
138
- }
139
- },
140
- stop() {
141
- stopped = true;
142
- if (timer) {
143
- clearTimeout(timer);
144
- timer = undefined;
145
- }
146
- },
147
- _onError(err, event) {
148
- // Capture for use inside doFlush (the strategy doesn't know what
149
- // the consumer's error sink is unless they wire `_onError` via
150
- // the strategy options. We store it on this hook so put-failures
151
- // route correctly).
152
- onErrorHook =
153
- onErrorHook ??
154
- ((e) => {
155
- // eslint-disable-next-line no-console
156
- console.error('[agentcoreObservability] flush failed:', e.message);
157
- });
158
- onErrorHook(err, event);
159
- },
160
- };
61
+ return (0, cloudwatch_js_1._buildCloudWatchObservability)(opts, 'agentcore');
161
62
  }
162
63
  exports.agentcoreObservability = agentcoreObservability;
163
- // ─── SDK client construction (lazy) ──────────────────────────────────
164
- function createCloudWatchClient(region) {
165
- let mod;
166
- try {
167
- mod = (0, lazyRequire_js_1.lazyRequire)('@aws-sdk/client-cloudwatch-logs');
168
- }
169
- catch {
170
- throw new Error('agentcoreObservability requires the `@aws-sdk/client-cloudwatch-logs` peer dependency.\n' +
171
- ' Install: npm install @aws-sdk/client-cloudwatch-logs\n' +
172
- ' Or pass `_client` for test injection.');
173
- }
174
- if (!mod.CloudWatchLogsClient || !mod.PutLogEventsCommand) {
175
- throw new Error('agentcoreObservability: `@aws-sdk/client-cloudwatch-logs` is installed but ' +
176
- '`CloudWatchLogsClient` / `PutLogEventsCommand` was not found. Update the SDK.');
177
- }
178
- const sdkClient = new mod.CloudWatchLogsClient({ ...(region && { region }) });
179
- return {
180
- async putLogEvents(input) {
181
- // Cast the SDK constructor to the call shape — same trick as the
182
- // memory adapter to stay forward-compat with SDK shape drift.
183
- const cmd = new mod.PutLogEventsCommand(input);
184
- await sdkClient.send(cmd);
185
- },
186
- };
187
- }
188
64
  //# sourceMappingURL=agentcore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agentcore.js","sourceRoot":"","sources":["../../../src/adapters/observability/agentcore.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;;;AAGH,6DAAuD;AA8CvD,wEAAwE;AAExE,SAAgB,sBAAsB,CAAC,IAAmC;IACxE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QACvB,MAAM,IAAI,SAAS,CACjB,yDAAyD;YACvD,yEAAyE,CAC5E,CAAC;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,gBAAgB,CAAC;IAC7D,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,IAAI,GAAG,CAAC;IAClD,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC;IACnD,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC;IAErD,uEAAuE;IACvE,MAAM,MAAM,GAAkD,EAAE,CAAC;IACjE,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,gBAAgB,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IACxD,IAAI,KAAgD,CAAC;IACrD,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,WAA4E,CAAC;IAEjF,gEAAgE;IAChE,8DAA8D;IAC9D,IAAI,MAAM,GAAqC,IAAI,CAAC,OAAO,CAAC;IAC5D,SAAS,YAAY;QACnB,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QAC1B,MAAM,GAAG,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,SAAS,kBAAkB;QACzB,IAAI,KAAK,IAAI,eAAe,IAAI,CAAC,IAAI,OAAO;YAAE,OAAO;QACrD,KAAK,GAAG,UAAU,CAAC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ACxD,IAAI,GAAwB,CAAC;IAC7B,IAAI,CAAC;QACH,GAAG,GAAG,IAAA,4BAAW,EAAsB,iCAAiC,CAAC,CAAC;IAC5E,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,0FAA0F;YACxF,2DAA2D;YAC3D,yCAAyC,CAC5C,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CACb,6EAA6E;YAC3E,+EAA+E,CAClF,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,oBAAoB,CAAC,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAE3E,CAAC;IAEF,OAAO;QACL,KAAK,CAAC,YAAY,CAAC,KAAK;YACtB,iEAAiE;YACjE,8DAA8D;YAC9D,MAAM,GAAG,GAAG,IAAK,GAAG,CAAC,mBAAmD,CAAC,KAAK,CAAC,CAAC;YAChF,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"agentcore.js","sourceRoot":"","sources":["../../../src/adapters/observability/agentcore.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;;;AAIH,mDAGyB;AAWzB;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,IAAmC;IACxE,OAAO,IAAA,6CAA6B,EAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAC1D,CAAC;AAFD,wDAEC"}
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ /**
3
+ * cloudwatchObservability — Generic AWS CloudWatch Logs adapter.
4
+ *
5
+ * Ships every `AgentfootprintEvent` to a CloudWatch Logs stream. Use
6
+ * when you want agent telemetry alongside the rest of your AWS
7
+ * observability stack — CloudWatch Insights queries, alarms,
8
+ * cross-service correlation. Same SDK as `agentcoreObservability`
9
+ * but **without** the AgentCore-specific defaults (log-stream
10
+ * convention, format opinions). Use this when:
11
+ *
12
+ * 1. You're shipping to CloudWatch but NOT running inside Bedrock
13
+ * AgentCore (most common case).
14
+ * 2. You want full control over log group / stream / format and
15
+ * don't need AgentCore's hosted-agent telemetry conventions.
16
+ *
17
+ * Subpath: `agentfootprint/observability-providers`
18
+ * Peer dep: `@aws-sdk/client-cloudwatch-logs` (OPTIONAL — installed
19
+ * only when this adapter is used; declared via
20
+ * `peerDependenciesMeta.{name}.optional = true`).
21
+ *
22
+ * This module also exports the underlying base function used by
23
+ * `agentcoreObservability` — keeps the per-event hot path in one
24
+ * place so improvements (batching, retry, backpressure) flow to
25
+ * every CloudWatch-shaped adapter automatically.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { cloudwatchObservability } from 'agentfootprint/observability-providers';
30
+ * import { microtaskBatchDriver } from 'footprintjs/detach';
31
+ *
32
+ * agent.enable.observability({
33
+ * strategy: cloudwatchObservability({
34
+ * region: 'us-east-1',
35
+ * logGroupName: '/myapp/agent-prod',
36
+ * logStreamName: `${process.env.HOSTNAME}/${Date.now()}`,
37
+ * }),
38
+ * detach: { driver: microtaskBatchDriver, mode: 'forget' },
39
+ * });
40
+ * ```
41
+ */
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.cloudwatchObservability = exports._buildCloudWatchObservability = void 0;
44
+ const lazyRequire_js_1 = require("../../lib/lazyRequire.js");
45
+ // ─── Generic base — also used by agentcoreObservability ──────────────
46
+ /**
47
+ * Internal: shared CloudWatch Logs base used by every adapter that
48
+ * ships to CWL. `cloudwatchObservability` is the public generic
49
+ * factory; `agentcoreObservability` calls this with AgentCore-flavored
50
+ * defaults.
51
+ *
52
+ * Exported for adapter authors only — consumers should call
53
+ * `cloudwatchObservability` or `agentcoreObservability` directly.
54
+ *
55
+ * @internal
56
+ */
57
+ function _buildCloudWatchObservability(opts, strategyName) {
58
+ if (!opts.logGroupName) {
59
+ throw new TypeError(`[${strategyName}Observability] \`logGroupName\` is required. ` +
60
+ `Pass an existing CloudWatch log group, e.g. '/myapp/agent-prod'.`);
61
+ }
62
+ const logStreamName = opts.logStreamName ?? 'agentfootprint';
63
+ const maxBatchEvents = opts.maxBatchEvents ?? 100;
64
+ const maxBatchBytes = opts.maxBatchBytes ?? 10_240;
65
+ const flushIntervalMs = opts.flushIntervalMs ?? 1000;
66
+ // Buffered batch — drained by `flush()` / size-trigger / time-trigger.
67
+ const buffer = [];
68
+ let bufferBytes = 0;
69
+ let lastFlushPromise = Promise.resolve();
70
+ let timer;
71
+ let stopped = false;
72
+ let onErrorHook;
73
+ // Lazy-resolved on first flush so consumers who never trigger a
74
+ // flush (because nothing was emitted) don't even hit the SDK.
75
+ let client = opts._client;
76
+ function ensureClient() {
77
+ if (client)
78
+ return client;
79
+ client = createCloudWatchClient(opts.region, strategyName);
80
+ return client;
81
+ }
82
+ function scheduleTimedFlush() {
83
+ if (timer || flushIntervalMs <= 0 || stopped)
84
+ return;
85
+ timer = setTimeout(() => {
86
+ timer = undefined;
87
+ void doFlush();
88
+ }, flushIntervalMs);
89
+ }
90
+ async function doFlush() {
91
+ if (buffer.length === 0 || stopped)
92
+ return;
93
+ // Snapshot + clear so concurrent emits during the in-flight put
94
+ // accumulate into the next batch.
95
+ const batch = buffer.splice(0);
96
+ bufferBytes = 0;
97
+ try {
98
+ await ensureClient().putLogEvents({
99
+ logGroupName: opts.logGroupName,
100
+ logStreamName,
101
+ logEvents: batch,
102
+ });
103
+ }
104
+ catch (err) {
105
+ onErrorHook?.(err instanceof Error ? err : new Error(String(err)));
106
+ }
107
+ }
108
+ function enqueue(event) {
109
+ if (stopped)
110
+ return;
111
+ const message = JSON.stringify(event);
112
+ const bytes = Buffer.byteLength(message, 'utf8');
113
+ buffer.push({ timestamp: Date.now(), message });
114
+ bufferBytes += bytes;
115
+ if (buffer.length >= maxBatchEvents || bufferBytes >= maxBatchBytes) {
116
+ // Size trigger — flush immediately. Chain onto last to preserve
117
+ // CloudWatch's per-stream ordering requirement.
118
+ lastFlushPromise = lastFlushPromise.then(doFlush, doFlush);
119
+ }
120
+ else {
121
+ scheduleTimedFlush();
122
+ }
123
+ }
124
+ return {
125
+ name: strategyName,
126
+ capabilities: { events: true, logs: true },
127
+ exportEvent: enqueue,
128
+ async flush() {
129
+ // Drain anything pending. Awaits both an in-flight put AND any
130
+ // newly-buffered events that arrived during it.
131
+ while (buffer.length > 0 || lastFlushPromise !== Promise.resolve()) {
132
+ const before = lastFlushPromise;
133
+ await before;
134
+ if (buffer.length > 0) {
135
+ lastFlushPromise = doFlush();
136
+ }
137
+ // Loop one more pass if the chained doFlush() queued more
138
+ // work, then bail.
139
+ if (lastFlushPromise === before && buffer.length === 0)
140
+ break;
141
+ }
142
+ },
143
+ stop() {
144
+ stopped = true;
145
+ if (timer) {
146
+ clearTimeout(timer);
147
+ timer = undefined;
148
+ }
149
+ },
150
+ _onError(err, event) {
151
+ // Capture for use inside doFlush (the strategy doesn't know what
152
+ // the consumer's error sink is unless they wire `_onError` via
153
+ // the strategy options. We store it on this hook so put-failures
154
+ // route correctly).
155
+ onErrorHook =
156
+ onErrorHook ??
157
+ ((e) => {
158
+ // eslint-disable-next-line no-console
159
+ console.error(`[${strategyName}Observability] flush failed:`, e.message);
160
+ });
161
+ onErrorHook(err, event);
162
+ },
163
+ };
164
+ }
165
+ exports._buildCloudWatchObservability = _buildCloudWatchObservability;
166
+ // ─── Public factory: cloudwatchObservability ─────────────────────────
167
+ /**
168
+ * Generic CloudWatch Logs observability adapter. See
169
+ * `CloudwatchObservabilityOptions` for the per-option contract.
170
+ *
171
+ * For AgentCore-specific conventions, use `agentcoreObservability`
172
+ * which thin-wraps this with AgentCore-flavored defaults.
173
+ */
174
+ function cloudwatchObservability(opts) {
175
+ return _buildCloudWatchObservability(opts, 'cloudwatch');
176
+ }
177
+ exports.cloudwatchObservability = cloudwatchObservability;
178
+ // ─── SDK client construction (lazy) ──────────────────────────────────
179
+ function createCloudWatchClient(region, strategyName) {
180
+ let mod;
181
+ try {
182
+ mod = (0, lazyRequire_js_1.lazyRequire)('@aws-sdk/client-cloudwatch-logs');
183
+ }
184
+ catch {
185
+ throw new Error(`[${strategyName}Observability] requires the \`@aws-sdk/client-cloudwatch-logs\` peer dependency.\n` +
186
+ ` Install: npm install @aws-sdk/client-cloudwatch-logs\n` +
187
+ ` Or pass \`_client\` for test injection.`);
188
+ }
189
+ if (!mod.CloudWatchLogsClient || !mod.PutLogEventsCommand) {
190
+ throw new Error(`[${strategyName}Observability]: \`@aws-sdk/client-cloudwatch-logs\` is installed but ` +
191
+ `\`CloudWatchLogsClient\` / \`PutLogEventsCommand\` was not found. Update the SDK.`);
192
+ }
193
+ const sdkClient = new mod.CloudWatchLogsClient({ ...(region && { region }) });
194
+ return {
195
+ async putLogEvents(input) {
196
+ // Cast the SDK constructor to the call shape — same trick as
197
+ // the memory adapter to stay forward-compat with SDK shape drift.
198
+ const cmd = new mod.PutLogEventsCommand(input);
199
+ await sdkClient.send(cmd);
200
+ },
201
+ };
202
+ }
203
+ //# sourceMappingURL=cloudwatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudwatch.js","sourceRoot":"","sources":["../../../src/adapters/observability/cloudwatch.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;;;AAGH,6DAAuD;AA+CvD,wEAAwE;AAExE;;;;;;;;;;GAUG;AACH,SAAgB,6BAA6B,CAC3C,IAAoC,EACpC,YAAoB;IAEpB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QACvB,MAAM,IAAI,SAAS,CACjB,IAAI,YAAY,+CAA+C;YAC7D,kEAAkE,CACrE,CAAC;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,gBAAgB,CAAC;IAC7D,MAAM,cAAc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AG,CAAC,mBAAmB,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CACb,IAAI,YAAY,uEAAuE;YACrF,mFAAmF,CACtF,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,oBAAoB,CAAC,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAE3E,CAAC;IAEF,OAAO;QACL,KAAK,CAAC,YAAY,CAAC,KAAK;YACtB,6DAA6D;YAC7D,kEAAkE;YAClE,MAAM,GAAG,GAAG,IAAK,GAAG,CAAC,mBAAmD,CAAC,KAAK,CAAC,CAAC;YAChF,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
- * Pattern: Adapter (GoF) translates `AgentfootprintEvent`
20
- * CloudWatch Logs `PutLogEvents` payloads. Buffers in
21
- * `exportEvent()` (sync, non-throwing); flushes in `flush()`
22
- * (async batch). Default flush window: 1s OR 10 KB,
23
- * whichever first matches CloudWatch's own optimal batch.
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 { lazyRequire } from '../../lib/lazyRequire.js';
50
- // ─── Strategy factory ────────────────────────────────────────────────
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
- if (!opts.logGroupName) {
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AA8CvD,wEAAwE;AAExE,MAAM,UAAU,sBAAsB,CAAC,IAAmC;IACxE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QACvB,MAAM,IAAI,SAAS,CACjB,yDAAyD;YACvD,yEAAyE,CAC5E,CAAC;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,gBAAgB,CAAC;IAC7D,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,IAAI,GAAG,CAAC;IAClD,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC;IACnD,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC;IAErD,uEAAuE;IACvE,MAAM,MAAM,GAAkD,EAAE,CAAC;IACjE,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,gBAAgB,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IACxD,IAAI,KAAgD,CAAC;IACrD,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,WAA4E,CAAC;IAEjF,gEAAgE;IAChE,8DAA8D;IAC9D,IAAI,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AAM,iBAAiB,CAAC;AAWzB;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAmC;IACxE,OAAO,6BAA6B,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,198 @@
1
+ /**
2
+ * cloudwatchObservability — Generic AWS CloudWatch Logs adapter.
3
+ *
4
+ * Ships every `AgentfootprintEvent` to a CloudWatch Logs stream. Use
5
+ * when you want agent telemetry alongside the rest of your AWS
6
+ * observability stack — CloudWatch Insights queries, alarms,
7
+ * cross-service correlation. Same SDK as `agentcoreObservability`
8
+ * but **without** the AgentCore-specific defaults (log-stream
9
+ * convention, format opinions). Use this when:
10
+ *
11
+ * 1. You're shipping to CloudWatch but NOT running inside Bedrock
12
+ * AgentCore (most common case).
13
+ * 2. You want full control over log group / stream / format and
14
+ * don't need AgentCore's hosted-agent telemetry conventions.
15
+ *
16
+ * Subpath: `agentfootprint/observability-providers`
17
+ * Peer dep: `@aws-sdk/client-cloudwatch-logs` (OPTIONAL — installed
18
+ * only when this adapter is used; declared via
19
+ * `peerDependenciesMeta.{name}.optional = true`).
20
+ *
21
+ * This module also exports the underlying base function used by
22
+ * `agentcoreObservability` — keeps the per-event hot path in one
23
+ * place so improvements (batching, retry, backpressure) flow to
24
+ * every CloudWatch-shaped adapter automatically.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { cloudwatchObservability } from 'agentfootprint/observability-providers';
29
+ * import { microtaskBatchDriver } from 'footprintjs/detach';
30
+ *
31
+ * agent.enable.observability({
32
+ * strategy: cloudwatchObservability({
33
+ * region: 'us-east-1',
34
+ * logGroupName: '/myapp/agent-prod',
35
+ * logStreamName: `${process.env.HOSTNAME}/${Date.now()}`,
36
+ * }),
37
+ * detach: { driver: microtaskBatchDriver, mode: 'forget' },
38
+ * });
39
+ * ```
40
+ */
41
+ import { lazyRequire } from '../../lib/lazyRequire.js';
42
+ // ─── Generic base — also used by agentcoreObservability ──────────────
43
+ /**
44
+ * Internal: shared CloudWatch Logs base used by every adapter that
45
+ * ships to CWL. `cloudwatchObservability` is the public generic
46
+ * factory; `agentcoreObservability` calls this with AgentCore-flavored
47
+ * defaults.
48
+ *
49
+ * Exported for adapter authors only — consumers should call
50
+ * `cloudwatchObservability` or `agentcoreObservability` directly.
51
+ *
52
+ * @internal
53
+ */
54
+ export function _buildCloudWatchObservability(opts, strategyName) {
55
+ if (!opts.logGroupName) {
56
+ throw new TypeError(`[${strategyName}Observability] \`logGroupName\` is required. ` +
57
+ `Pass an existing CloudWatch log group, e.g. '/myapp/agent-prod'.`);
58
+ }
59
+ const logStreamName = opts.logStreamName ?? 'agentfootprint';
60
+ const maxBatchEvents = opts.maxBatchEvents ?? 100;
61
+ const maxBatchBytes = opts.maxBatchBytes ?? 10_240;
62
+ const flushIntervalMs = opts.flushIntervalMs ?? 1000;
63
+ // Buffered batch — drained by `flush()` / size-trigger / time-trigger.
64
+ const buffer = [];
65
+ let bufferBytes = 0;
66
+ let lastFlushPromise = Promise.resolve();
67
+ let timer;
68
+ let stopped = false;
69
+ let onErrorHook;
70
+ // Lazy-resolved on first flush so consumers who never trigger a
71
+ // flush (because nothing was emitted) don't even hit the SDK.
72
+ let client = opts._client;
73
+ function ensureClient() {
74
+ if (client)
75
+ return client;
76
+ client = createCloudWatchClient(opts.region, strategyName);
77
+ return client;
78
+ }
79
+ function scheduleTimedFlush() {
80
+ if (timer || flushIntervalMs <= 0 || stopped)
81
+ return;
82
+ timer = setTimeout(() => {
83
+ timer = undefined;
84
+ void doFlush();
85
+ }, flushIntervalMs);
86
+ }
87
+ async function doFlush() {
88
+ if (buffer.length === 0 || stopped)
89
+ return;
90
+ // Snapshot + clear so concurrent emits during the in-flight put
91
+ // accumulate into the next batch.
92
+ const batch = buffer.splice(0);
93
+ bufferBytes = 0;
94
+ try {
95
+ await ensureClient().putLogEvents({
96
+ logGroupName: opts.logGroupName,
97
+ logStreamName,
98
+ logEvents: batch,
99
+ });
100
+ }
101
+ catch (err) {
102
+ onErrorHook?.(err instanceof Error ? err : new Error(String(err)));
103
+ }
104
+ }
105
+ function enqueue(event) {
106
+ if (stopped)
107
+ return;
108
+ const message = JSON.stringify(event);
109
+ const bytes = Buffer.byteLength(message, 'utf8');
110
+ buffer.push({ timestamp: Date.now(), message });
111
+ bufferBytes += bytes;
112
+ if (buffer.length >= maxBatchEvents || bufferBytes >= maxBatchBytes) {
113
+ // Size trigger — flush immediately. Chain onto last to preserve
114
+ // CloudWatch's per-stream ordering requirement.
115
+ lastFlushPromise = lastFlushPromise.then(doFlush, doFlush);
116
+ }
117
+ else {
118
+ scheduleTimedFlush();
119
+ }
120
+ }
121
+ return {
122
+ name: strategyName,
123
+ capabilities: { events: true, logs: true },
124
+ exportEvent: enqueue,
125
+ async flush() {
126
+ // Drain anything pending. Awaits both an in-flight put AND any
127
+ // newly-buffered events that arrived during it.
128
+ while (buffer.length > 0 || lastFlushPromise !== Promise.resolve()) {
129
+ const before = lastFlushPromise;
130
+ await before;
131
+ if (buffer.length > 0) {
132
+ lastFlushPromise = doFlush();
133
+ }
134
+ // Loop one more pass if the chained doFlush() queued more
135
+ // work, then bail.
136
+ if (lastFlushPromise === before && buffer.length === 0)
137
+ break;
138
+ }
139
+ },
140
+ stop() {
141
+ stopped = true;
142
+ if (timer) {
143
+ clearTimeout(timer);
144
+ timer = undefined;
145
+ }
146
+ },
147
+ _onError(err, event) {
148
+ // Capture for use inside doFlush (the strategy doesn't know what
149
+ // the consumer's error sink is unless they wire `_onError` via
150
+ // the strategy options. We store it on this hook so put-failures
151
+ // route correctly).
152
+ onErrorHook =
153
+ onErrorHook ??
154
+ ((e) => {
155
+ // eslint-disable-next-line no-console
156
+ console.error(`[${strategyName}Observability] flush failed:`, e.message);
157
+ });
158
+ onErrorHook(err, event);
159
+ },
160
+ };
161
+ }
162
+ // ─── Public factory: cloudwatchObservability ─────────────────────────
163
+ /**
164
+ * Generic CloudWatch Logs observability adapter. See
165
+ * `CloudwatchObservabilityOptions` for the per-option contract.
166
+ *
167
+ * For AgentCore-specific conventions, use `agentcoreObservability`
168
+ * which thin-wraps this with AgentCore-flavored defaults.
169
+ */
170
+ export function cloudwatchObservability(opts) {
171
+ return _buildCloudWatchObservability(opts, 'cloudwatch');
172
+ }
173
+ // ─── SDK client construction (lazy) ──────────────────────────────────
174
+ function createCloudWatchClient(region, strategyName) {
175
+ let mod;
176
+ try {
177
+ mod = lazyRequire('@aws-sdk/client-cloudwatch-logs');
178
+ }
179
+ catch {
180
+ throw new Error(`[${strategyName}Observability] requires the \`@aws-sdk/client-cloudwatch-logs\` peer dependency.\n` +
181
+ ` Install: npm install @aws-sdk/client-cloudwatch-logs\n` +
182
+ ` Or pass \`_client\` for test injection.`);
183
+ }
184
+ if (!mod.CloudWatchLogsClient || !mod.PutLogEventsCommand) {
185
+ throw new Error(`[${strategyName}Observability]: \`@aws-sdk/client-cloudwatch-logs\` is installed but ` +
186
+ `\`CloudWatchLogsClient\` / \`PutLogEventsCommand\` was not found. Update the SDK.`);
187
+ }
188
+ const sdkClient = new mod.CloudWatchLogsClient({ ...(region && { region }) });
189
+ return {
190
+ async putLogEvents(input) {
191
+ // Cast the SDK constructor to the call shape — same trick as
192
+ // the memory adapter to stay forward-compat with SDK shape drift.
193
+ const cmd = new mod.PutLogEventsCommand(input);
194
+ await sdkClient.send(cmd);
195
+ },
196
+ };
197
+ }
198
+ //# sourceMappingURL=cloudwatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudwatch.js","sourceRoot":"","sources":["../../../../src/adapters/observability/cloudwatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AA+CvD,wEAAwE;AAExE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,6BAA6B,CAC3C,IAAoC,EACpC,YAAoB;IAEpB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;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KAAK,CACb,IAAI,YAAY,oFAAoF;YAClG,2DAA2D;YAC3D,2CAA2C,CAC9C,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CACb,IAAI,YAAY,uEAAuE;YACrF,mFAAmF,CACtF,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,oBAAoB,CAAC,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAE3E,CAAC;IAEF,OAAO;QACL,KAAK,CAAC,YAAY,CAAC,KAAK;YACtB,6DAA6D;YAC7D,kEAAkE;YAClE,MAAM,GAAG,GAAG,IAAK,GAAG,CAAC,mBAAmD,CAAC,KAAK,CAAC,CAAC;YAChF,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -27,11 +27,12 @@
27
27
  * ```
28
28
  *
29
29
  * Roadmap:
30
- * - agentcoreObservability ← v2.8.1 (this release)
31
- * - cloudwatchObservability ← v2.8.2
30
+ * - agentcoreObservability ← v2.8.1
31
+ * - cloudwatchObservability ← v2.8.2 (this release)
32
32
  * - xrayObservability ← v2.8.3
33
33
  * - otelObservability ← v2.9.x
34
34
  * - datadogObservability ← v2.9.x
35
35
  */
36
36
  export { agentcoreObservability, } from './adapters/observability/agentcore.js';
37
+ export { cloudwatchObservability, } from './adapters/observability/cloudwatch.js';
37
38
  //# sourceMappingURL=observability-providers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"observability-providers.js","sourceRoot":"","sources":["../../src/observability-providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EACL,sBAAsB,GAEvB,MAAM,uCAAuC,CAAC"}
1
+ {"version":3,"file":"observability-providers.js","sourceRoot":"","sources":["../../src/observability-providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EACL,sBAAsB,GAEvB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,uBAAuB,GAExB,MAAM,wCAAwC,CAAC"}
@@ -28,14 +28,16 @@
28
28
  * ```
29
29
  *
30
30
  * Roadmap:
31
- * - agentcoreObservability ← v2.8.1 (this release)
32
- * - cloudwatchObservability ← v2.8.2
31
+ * - agentcoreObservability ← v2.8.1
32
+ * - cloudwatchObservability ← v2.8.2 (this release)
33
33
  * - xrayObservability ← v2.8.3
34
34
  * - otelObservability ← v2.9.x
35
35
  * - datadogObservability ← v2.9.x
36
36
  */
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.agentcoreObservability = void 0;
38
+ exports.cloudwatchObservability = exports.agentcoreObservability = void 0;
39
39
  var agentcore_js_1 = require("./adapters/observability/agentcore.js");
40
40
  Object.defineProperty(exports, "agentcoreObservability", { enumerable: true, get: function () { return agentcore_js_1.agentcoreObservability; } });
41
+ var cloudwatch_js_1 = require("./adapters/observability/cloudwatch.js");
42
+ Object.defineProperty(exports, "cloudwatchObservability", { enumerable: true, get: function () { return cloudwatch_js_1.cloudwatchObservability; } });
41
43
  //# sourceMappingURL=observability-providers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"observability-providers.js","sourceRoot":"","sources":["../src/observability-providers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAEH,sEAG+C;AAF7C,sHAAA,sBAAsB,OAAA"}
1
+ {"version":3,"file":"observability-providers.js","sourceRoot":"","sources":["../src/observability-providers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAEH,sEAG+C;AAF7C,sHAAA,sBAAsB,OAAA;AAGxB,wEAGgD;AAF9C,wHAAA,uBAAuB,OAAA"}
@@ -16,11 +16,12 @@
16
16
  * only when this adapter is used; declared via
17
17
  * `peerDependenciesMeta.{name}.optional = true`).
18
18
  *
19
- * Pattern: Adapter (GoF) translates `AgentfootprintEvent`
20
- * CloudWatch Logs `PutLogEvents` payloads. Buffers in
21
- * `exportEvent()` (sync, non-throwing); flushes in `flush()`
22
- * (async batch). Default flush window: 1s OR 10 KB,
23
- * whichever first matches CloudWatch's own optimal batch.
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
@@ -47,40 +48,20 @@
47
48
  * ```
48
49
  */
49
50
  import type { ObservabilityStrategy } from '../../strategies/types.js';
50
- export interface AgentcoreObservabilityOptions {
51
- /** AWS region. Falls back to AWS_REGION / AWS_DEFAULT_REGION env. */
52
- readonly region?: string;
53
- /** CloudWatch Logs log group. **Required.** Must exist or your IAM
54
- * role must allow `logs:CreateLogGroup`. */
55
- readonly logGroupName: string;
56
- /** CloudWatch Logs log stream within the group. Conventionally
57
- * `<host>/<startTime>` so multi-instance deployments don't collide.
58
- * Created on first put if it doesn't exist (or your role must
59
- * allow `logs:CreateLogStream`). Defaults to `agentfootprint`. */
60
- readonly logStreamName?: string;
61
- /** Max events buffered before forced flush. Default 100. */
62
- readonly maxBatchEvents?: number;
63
- /** Max payload bytes (UTF-8) buffered before forced flush. Default
64
- * 10240 (10 KB). CloudWatch hard caps at 1 MB / batch but we keep
65
- * the default low so latency stays bounded. */
66
- readonly maxBatchBytes?: number;
67
- /** Forced-flush interval when traffic is sparse. Default 1000ms.
68
- * `0` disables time-based flush — only size triggers fire. */
69
- readonly flushIntervalMs?: number;
70
- /** Test injection — bypasses SDK lazy-require entirely. When set,
71
- * `region` / IAM are ignored. */
72
- readonly _client?: CloudWatchLikeClient;
73
- }
74
- interface CloudWatchLikeClient {
75
- putLogEvents(input: {
76
- logGroupName: string;
77
- logStreamName: string;
78
- logEvents: ReadonlyArray<{
79
- timestamp: number;
80
- message: string;
81
- }>;
82
- }): Promise<unknown>;
83
- }
51
+ import { type CloudwatchObservabilityOptions } from './cloudwatch.js';
52
+ /**
53
+ * AgentCore-specific options. Currently identical to the generic
54
+ * `CloudwatchObservabilityOptions` kept as a separate type for
55
+ * future-proofing (AgentCore-specific knobs like
56
+ * `agentcoreSessionId` propagation could land here without a
57
+ * breaking change).
58
+ */
59
+ export type AgentcoreObservabilityOptions = CloudwatchObservabilityOptions;
60
+ /**
61
+ * Build an AgentCore-flavored CloudWatch Logs observability strategy.
62
+ * Functionally identical to `cloudwatchObservability` except for the
63
+ * strategy `name`, which lets registry-lookup + diagnostics
64
+ * distinguish AgentCore-targeted shipping from generic CloudWatch.
65
+ */
84
66
  export declare function agentcoreObservability(opts: AgentcoreObservabilityOptions): ObservabilityStrategy;
85
- export {};
86
67
  //# sourceMappingURL=agentcore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agentcore.d.ts","sourceRoot":"","sources":["../../../../src/adapters/observability/agentcore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAIvE,MAAM,WAAW,6BAA6B;IAC5C,qEAAqE;IACrE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;iDAC6C;IAC7C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;uEAGmE;IACnE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,4DAA4D;IAC5D,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC;;oDAEgD;IAChD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;mEAC+D;IAC/D,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC;sCACkC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC;CACzC;AAID,UAAU,oBAAoB;IAC5B,YAAY,CAAC,KAAK,EAAE;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;QACtB,SAAS,EAAE,aAAa,CAAC;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAClE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtB;AAUD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,6BAA6B,GAAG,qBAAqB,CA8GjG"}
1
+ {"version":3,"file":"agentcore.d.ts","sourceRoot":"","sources":["../../../../src/adapters/observability/agentcore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,iBAAiB,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,GAAG,8BAA8B,CAAC;AAE3E;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,6BAA6B,GAAG,qBAAqB,CAEjG"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * cloudwatchObservability — Generic AWS CloudWatch Logs adapter.
3
+ *
4
+ * Ships every `AgentfootprintEvent` to a CloudWatch Logs stream. Use
5
+ * when you want agent telemetry alongside the rest of your AWS
6
+ * observability stack — CloudWatch Insights queries, alarms,
7
+ * cross-service correlation. Same SDK as `agentcoreObservability`
8
+ * but **without** the AgentCore-specific defaults (log-stream
9
+ * convention, format opinions). Use this when:
10
+ *
11
+ * 1. You're shipping to CloudWatch but NOT running inside Bedrock
12
+ * AgentCore (most common case).
13
+ * 2. You want full control over log group / stream / format and
14
+ * don't need AgentCore's hosted-agent telemetry conventions.
15
+ *
16
+ * Subpath: `agentfootprint/observability-providers`
17
+ * Peer dep: `@aws-sdk/client-cloudwatch-logs` (OPTIONAL — installed
18
+ * only when this adapter is used; declared via
19
+ * `peerDependenciesMeta.{name}.optional = true`).
20
+ *
21
+ * This module also exports the underlying base function used by
22
+ * `agentcoreObservability` — keeps the per-event hot path in one
23
+ * place so improvements (batching, retry, backpressure) flow to
24
+ * every CloudWatch-shaped adapter automatically.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { cloudwatchObservability } from 'agentfootprint/observability-providers';
29
+ * import { microtaskBatchDriver } from 'footprintjs/detach';
30
+ *
31
+ * agent.enable.observability({
32
+ * strategy: cloudwatchObservability({
33
+ * region: 'us-east-1',
34
+ * logGroupName: '/myapp/agent-prod',
35
+ * logStreamName: `${process.env.HOSTNAME}/${Date.now()}`,
36
+ * }),
37
+ * detach: { driver: microtaskBatchDriver, mode: 'forget' },
38
+ * });
39
+ * ```
40
+ */
41
+ import type { ObservabilityStrategy } from '../../strategies/types.js';
42
+ export interface CloudwatchObservabilityOptions {
43
+ /** AWS region. Falls back to AWS_REGION / AWS_DEFAULT_REGION env. */
44
+ readonly region?: string;
45
+ /** CloudWatch Logs log group. **Required.** Must exist or your IAM
46
+ * role must allow `logs:CreateLogGroup`. */
47
+ readonly logGroupName: string;
48
+ /** CloudWatch Logs log stream within the group. Conventionally
49
+ * `<host>/<startTime>` so multi-instance deployments don't
50
+ * collide. Created on first put if it doesn't exist (or your
51
+ * role must allow `logs:CreateLogStream`). Defaults to
52
+ * `agentfootprint`. */
53
+ readonly logStreamName?: string;
54
+ /** Max events buffered before forced flush. Default 100. */
55
+ readonly maxBatchEvents?: number;
56
+ /** Max payload bytes (UTF-8) buffered before forced flush. Default
57
+ * 10240 (10 KB). CloudWatch hard caps at 1 MB / batch but we keep
58
+ * the default low so latency stays bounded. */
59
+ readonly maxBatchBytes?: number;
60
+ /** Forced-flush interval when traffic is sparse. Default 1000ms.
61
+ * `0` disables time-based flush — only size triggers fire. */
62
+ readonly flushIntervalMs?: number;
63
+ /** Test injection — bypasses SDK lazy-require entirely. When set,
64
+ * `region` / IAM are ignored. */
65
+ readonly _client?: CloudWatchLikeClient;
66
+ }
67
+ export interface CloudWatchLikeClient {
68
+ putLogEvents(input: {
69
+ logGroupName: string;
70
+ logStreamName: string;
71
+ logEvents: ReadonlyArray<{
72
+ timestamp: number;
73
+ message: string;
74
+ }>;
75
+ }): Promise<unknown>;
76
+ }
77
+ /**
78
+ * Internal: shared CloudWatch Logs base used by every adapter that
79
+ * ships to CWL. `cloudwatchObservability` is the public generic
80
+ * factory; `agentcoreObservability` calls this with AgentCore-flavored
81
+ * defaults.
82
+ *
83
+ * Exported for adapter authors only — consumers should call
84
+ * `cloudwatchObservability` or `agentcoreObservability` directly.
85
+ *
86
+ * @internal
87
+ */
88
+ export declare function _buildCloudWatchObservability(opts: CloudwatchObservabilityOptions, strategyName: string): ObservabilityStrategy;
89
+ /**
90
+ * Generic CloudWatch Logs observability adapter. See
91
+ * `CloudwatchObservabilityOptions` for the per-option contract.
92
+ *
93
+ * For AgentCore-specific conventions, use `agentcoreObservability`
94
+ * which thin-wraps this with AgentCore-flavored defaults.
95
+ */
96
+ export declare function cloudwatchObservability(opts: CloudwatchObservabilityOptions): ObservabilityStrategy;
97
+ //# sourceMappingURL=cloudwatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudwatch.d.ts","sourceRoot":"","sources":["../../../../src/adapters/observability/cloudwatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAIvE,MAAM,WAAW,8BAA8B;IAC7C,qEAAqE;IACrE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;iDAC6C;IAC7C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;;4BAIwB;IACxB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,4DAA4D;IAC5D,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC;;oDAEgD;IAChD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;mEAC+D;IAC/D,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC;sCACkC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC;CACzC;AAID,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,KAAK,EAAE;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;QACtB,SAAS,EAAE,aAAa,CAAC;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAClE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtB;AAUD;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,8BAA8B,EACpC,YAAY,EAAE,MAAM,GACnB,qBAAqB,CA8GvB;AAID;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,8BAA8B,GACnC,qBAAqB,CAEvB"}
@@ -27,11 +27,12 @@
27
27
  * ```
28
28
  *
29
29
  * Roadmap:
30
- * - agentcoreObservability ← v2.8.1 (this release)
31
- * - cloudwatchObservability ← v2.8.2
30
+ * - agentcoreObservability ← v2.8.1
31
+ * - cloudwatchObservability ← v2.8.2 (this release)
32
32
  * - xrayObservability ← v2.8.3
33
33
  * - otelObservability ← v2.9.x
34
34
  * - datadogObservability ← v2.9.x
35
35
  */
36
36
  export { agentcoreObservability, type AgentcoreObservabilityOptions, } from './adapters/observability/agentcore.js';
37
+ export { cloudwatchObservability, type CloudwatchObservabilityOptions, } from './adapters/observability/cloudwatch.js';
37
38
  //# sourceMappingURL=observability-providers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"observability-providers.d.ts","sourceRoot":"","sources":["../../src/observability-providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EACL,sBAAsB,EACtB,KAAK,6BAA6B,GACnC,MAAM,uCAAuC,CAAC"}
1
+ {"version":3,"file":"observability-providers.d.ts","sourceRoot":"","sources":["../../src/observability-providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EACL,sBAAsB,EACtB,KAAK,6BAA6B,GACnC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,uBAAuB,EACvB,KAAK,8BAA8B,GACpC,MAAM,wCAAwC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentfootprint",
3
- "version": "2.8.1",
3
+ "version": "2.8.2",
4
4
  "description": "The explainable agent framework — build AI agents you can explain, audit, and trust. Built on footprintjs.",
5
5
  "license": "MIT",
6
6
  "author": "Sanjay Krishna Anbalagan",