Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion typescript/packages/traceai_auto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The table below is generated from [`src/integrations.json`](https://github.com/f
| Configuration name | Target library | Instrumentation package | Setup |
| --- | --- | --- | --- |
| `anthropic` | `@anthropic-ai/sdk` | `@traceai/anthropic` | Import hook |
| `bedrock` | `@aws-sdk/client-bedrock-runtime` | `@traceai/bedrock` | Import hook |
| `bedrock` | `@aws-sdk/client-bedrock-runtime`, `@aws-sdk/client-bedrock-agent-runtime` | `@traceai/bedrock` | Import hook |
| `beeai` | `beeai-framework` | `@traceai/beeai` | Import hook |
| `cerebras` | `@cerebras/cerebras_cloud_sdk` | `@traceai/cerebras` | Import hook |
| `chromadb` | `chromadb` | `@traceai/chromadb` | Import hook |
Expand Down
4 changes: 3 additions & 1 deletion typescript/packages/traceai_auto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
"@openai/agents": "0.21.0",
"zod": "4.3.6",
"@cursor/sdk": "1.0.38",
"undici": "7.30.1"
"undici": "7.30.1",
"@traceai/bedrock": "workspace:^",
"@aws-sdk/client-bedrock-agent-runtime": "3.1127.0"
},
"repository": {
"type": "git",
Expand Down
6 changes: 4 additions & 2 deletions typescript/packages/traceai_auto/src/integrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"name": "bedrock",
"package": "@traceai/bedrock",
"targets": [
"@aws-sdk/client-bedrock-runtime"
"@aws-sdk/client-bedrock-runtime",
"@aws-sdk/client-bedrock-agent-runtime"
],
"className": "BedrockInstrumentation",
"modules": [
"@aws-sdk/client-bedrock-runtime"
"@aws-sdk/client-bedrock-runtime",
"@aws-sdk/client-bedrock-agent-runtime"
]
},
{
Expand Down
33 changes: 33 additions & 0 deletions typescript/packages/traceai_auto/test/apps/bedrock-agent.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Zero-code Bedrock Agents: the application only requires the agent-runtime SDK after the
// agent started; no instrumentation package is imported or constructed by the application.
const assert = require('node:assert/strict');
const auto = require('@traceai/auto');
const spans = [];
const exporter = { export(batch, done) { spans.push(...batch); done({ code: 0 }); }, async shutdown() {} };
(async () => {
try {
auto.init({ exporter, configFile: '/does-not-exist/traceai-fi-config', instrumentations: ['bedrock'] });
const { BedrockAgentRuntimeClient, InvokeAgentCommand } = require('@aws-sdk/client-bedrock-agent-runtime');
const bytes = text => new TextEncoder().encode(text);
async function* completion() {
yield { trace: { agentId: 'AGENT1', agentAliasId: 'ALIAS1', sessionId: 's-1', trace: { orchestrationTrace: { modelInvocationInput: { traceId: 't-1', foundationModel: 'anthropic.claude-3-haiku', text: JSON.stringify({ messages: [{ role: 'user', content: 'hi' }] }) } } } } };
yield { trace: { agentId: 'AGENT1', agentAliasId: 'ALIAS1', sessionId: 's-1', trace: { orchestrationTrace: { modelInvocationOutput: { traceId: 't-1', parsedResponse: { text: 'hello' }, metadata: { usage: { inputTokens: 3, outputTokens: 2 } } } } } } };
yield { chunk: { bytes: bytes('hello ') } };
yield { chunk: { bytes: bytes('world') } };
}
const client = new BedrockAgentRuntimeClient({ region: 'us-east-1', credentials: { accessKeyId: 'a', secretAccessKey: 'b' } });
client.middlewareStack.add(() => async () => ({ output: { completion: completion(), sessionId: 's-1' }, response: {} }), { step: 'initialize', name: 'recorded', priority: 'low' });
const response = await client.send(new InvokeAgentCommand({ agentId: 'AGENT1', agentAliasId: 'ALIAS1', sessionId: 's-1', inputText: 'hi', enableTrace: true }));
let text = '';
for await (const event of response.completion) if (event.chunk) text += new TextDecoder().decode(event.chunk.bytes);
assert.equal(text, 'hello world');
await auto.forceFlush();
const status = auto.report().integrations.find(s => s.name === 'bedrock');
assert.equal(status.status, 'instrumented', JSON.stringify(status));
const agent = spans.find(s => s.name === 'invoke_agent AGENT1/ALIAS1');
assert(agent, JSON.stringify(spans.map(s => s.name)));
const llm = spans.find(s => (s.attributes['fi.span.kind'] ?? s.attributes['gen_ai.span.kind']) === 'LLM' && s.name !== agent.name);
assert(llm, JSON.stringify(spans.map(s => [s.name, s.attributes])));
console.log(JSON.stringify({ status: status.status, agentKind: agent.attributes['fi.span.kind'] ?? agent.attributes['gen_ai.span.kind'], output: agent.attributes['output.value'], childOfAgent: (llm.parentSpanContext ?? { spanId: llm.parentSpanId }).spanId === agent.spanContext().spanId, tokens: llm.attributes['gen_ai.usage.input_tokens'] }));
} finally { await auto.shutdown(); }
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { spawnSync } from "node:child_process";
import { resolve } from "node:path";
import { integrations } from "../src/libraries";

function run(env: Record<string, string | undefined> = {}) {
const base: NodeJS.ProcessEnv = { ...process.env };
for (const key of Object.keys(base)) if (/^(?:FI_|OTEL_)/.test(key) || key === "NODE_OPTIONS") delete base[key];
const result = spawnSync(process.execPath, [resolve(__dirname, "apps/bedrock-agent.cjs")], { cwd: resolve(__dirname, ".."), env: { ...base, ...env }, encoding: "utf8", timeout: 25000 });
if (result.status !== 0) throw new Error(`${result.error ?? ""}\n${result.stderr}\n${result.stdout}`);
return JSON.parse(result.stdout.trim().split("\n").at(-1)!);
}

test("an application with only @aws-sdk/client-bedrock-agent-runtime gets Bedrock Agent spans with no code changes", () => {
expect(run()).toEqual({ status: "instrumented", agentKind: "AGENT", output: "hello world", childOfAgent: true, tokens: 3 });
});

test("the bedrock catalog entry covers the agent-runtime SDK, so it activates when only that SDK is installed", () => {
const entry = integrations.find(i => i.name === "bedrock")!;
for (const field of [entry.targets, entry.modules]) expect(field).toContain("@aws-sdk/client-bedrock-agent-runtime");
});
4 changes: 4 additions & 0 deletions typescript/packages/traceai_bedrock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [0.1.4] - 2026-11-12

### Added
- Amazon Bedrock Agents: `InvokeAgentCommand` and `InvokeInlineAgentCommand` sent through `@aws-sdk/client-bedrock-agent-runtime` are traced. One AGENT span `invoke_agent <agentId>/<aliasId>` (`invoke_agent inline` for inline agents) covers the call and the whole `completion` stream and ends when the stream is consumed, fails or is abandoned. With `enableTrace`, the stream's trace events become child spans: model invocations as LLM spans (model, prompt, output, token usage), action group calls as TOOL spans `execute_tool <name>`, and knowledge base lookups as RETRIEVER spans (documents, count). Output text is assembled from the chunk events and follows the hide settings. `@traceai/auto` activates it when only `@aws-sdk/client-bedrock-agent-runtime` is installed.
- `@aws-sdk/client-bedrock-agent-runtime` `^3.693.0` is an optional peer dependency; `@aws-sdk/client-bedrock-runtime` is now optional too, so an application using only one of the two SDKs loads this package.

### Fixed
- Traced send() keeps its options and callbacks, response streams are read only as your code reads them, the requested model id is recorded in full, and streamed tool arguments from Anthropic models are recorded, with a placeholder when the argument JSON is incomplete or malformed.

Expand Down
16 changes: 16 additions & 0 deletions typescript/packages/traceai_bedrock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ OpenTelemetry instrumentation for AWS Bedrock. Part of traceAI, Future AGI's Ope
```sh
npm install @traceai/bedrock @traceai/fi-core @opentelemetry/instrumentation @opentelemetry/api@^1.9.0 @opentelemetry/context-async-hooks@^2.0.1
npm install @aws-sdk/client-bedrock-runtime@"^3.0.0"
# Bedrock Agents (optional)
npm install @aws-sdk/client-bedrock-agent-runtime@"^3.0.0"
```

Install the AWS SDK in the application that makes Bedrock requests. Configure
Expand Down Expand Up @@ -45,6 +47,20 @@ Run your application's SDK calls after this setup. Call
spans. For ESM, follow the documentation for your OpenTelemetry loader and SDK
instead of assuming import order alone enables automatic patching.

## Bedrock Agents

`InvokeAgentCommand` and `InvokeInlineAgentCommand` sent with
`BedrockAgentRuntimeClient` are traced when `@aws-sdk/client-bedrock-agent-runtime` is
installed. Each call produces one AGENT span (`invoke_agent <agentId>/<aliasId>`) that
covers the whole streamed `completion`. It ends when your code has read the stream to the
end, the stream fails, or you stop reading. Your code receives the original events.

Set `enableTrace: true` on the command to also get child spans built from the stream's trace
events: model invocations (LLM spans with model, prompt, output and token usage), action
group calls (TOOL spans `execute_tool <name>`) and knowledge base lookups (RETRIEVER spans
with the retrieved documents). Prompts, answers, tool arguments and document text follow the
same hide settings as the other Bedrock spans. With `@traceai/auto`, this needs no code.

## Compatibility and privacy

This instruments the SDK hooks implemented by this package, not every API offered
Expand Down
16 changes: 13 additions & 3 deletions typescript/packages/traceai_bedrock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"@traceai/fi-semantic-conventions": "workspace:^"
},
"peerDependencies": {
"@aws-sdk/client-bedrock-runtime": "^3.693.0"
"@aws-sdk/client-bedrock-runtime": "^3.693.0",
"@aws-sdk/client-bedrock-agent-runtime": "^3.693.0"
},
"devDependencies": {
"@aws-sdk/client-bedrock-runtime": "^3.693.0",
Expand All @@ -56,7 +57,8 @@
"jest": "^29.7.0",
"ts-jest": "^29.1.4",
"rimraf": "^6.0.1",
"tsc-alias": "^1.8.16"
"tsc-alias": "^1.8.16",
"@aws-sdk/client-bedrock-agent-runtime": "3.1127.0"
},
"keywords": [
"opentelemetry",
Expand All @@ -73,5 +75,13 @@
"publishConfig": {
"access": "public"
},
"license": "Apache-2.0"
"license": "Apache-2.0",
"peerDependenciesMeta": {
"@aws-sdk/client-bedrock-agent-runtime": {
"optional": true
},
"@aws-sdk/client-bedrock-runtime": {
"optional": true
}
}
}
Loading
Loading