Skip to content

feat(js-bedrock-agent-runtime): AWS Bedrock Agent Instumentaion for JS #1874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

satyadevai
Copy link
Collaborator

No description provided.

@satyadevai satyadevai changed the title (feat: js/bedrock-agent-runtime): Initial Commit of bedrock agent instrumentation feat(js-bedrock-agent-runtime): Initial Commit of bedrock agent instrumentation Jul 16, 2025
@satyadevai satyadevai marked this pull request as ready for review July 20, 2025 09:45
@satyadevai satyadevai requested a review from a team as a code owner July 20, 2025 09:45
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jul 20, 2025
cursor[bot]

This comment was marked as outdated.

Copy link

pkg-pr-new bot commented Jul 20, 2025

Open in StackBlitz

@arizeai/openinference-core

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-core@1874

@arizeai/openinference-instrumentation-bedrock-agent-runtime

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-instrumentation-bedrock-agent-runtime@1874

@arizeai/openinference-instrumentation-beeai

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-instrumentation-beeai@1874

@arizeai/openinference-instrumentation-langchain

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-instrumentation-langchain@1874

@arizeai/openinference-instrumentation-mcp

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-instrumentation-mcp@1874

@arizeai/openinference-instrumentation-openai

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-instrumentation-openai@1874

@arizeai/openinference-mastra

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-mastra@1874

@arizeai/openinference-semantic-conventions

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-semantic-conventions@1874

@arizeai/openinference-vercel

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-vercel@1874

commit: d9527b2

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@satyadevai satyadevai force-pushed the js-bedrock-agent-instrumentation branch from 782b53b to 312e7af Compare July 20, 2025 11:32
cursor[bot]

This comment was marked as outdated.

@satyadevai satyadevai force-pushed the js-bedrock-agent-instrumentation branch 3 times, most recently from bf034ec to 6f20bf8 Compare July 21, 2025 05:17
@satyadevai satyadevai changed the title feat(js-bedrock-agent-runtime): Initial Commit of bedrock agent instrumentation feat(js-bedrock-agent-runtime): AWS Bedrock Agent Instumentaion for JS Jul 21, 2025
@satyadevai satyadevai requested review from mikeldking and removed request for mikeldking July 21, 2025 16:30
@satyadevai satyadevai marked this pull request as draft July 21, 2025 17:00
@satyadevai satyadevai force-pushed the js-bedrock-agent-instrumentation branch from 6f20bf8 to 628fb30 Compare July 21, 2025 18:20
@satyadevai satyadevai marked this pull request as ready for review July 21, 2025 18:51
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Instrumentation Reliability and Linting Cleanup

The instrumentation uses a fragile command.constructor.name check to identify InvokeAgentCommand instances, which is unreliable due to minification or library changes and could lead to instrumentation failures. This should be replaced with instanceof or duck typing. Additionally, an unnecessary /* eslint-disable @typescript-eslint/no-this-alias */ comment is present after the this alias is no longer in scope and should be removed.

js/packages/openinference-instrumentation-bedrock-agent-runtime/src/instrumentation.ts#L99-L106

) => {
/* eslint-disable @typescript-eslint/no-this-alias */
const instrumentationInstance = this;
return function patchedSend(
this: typeof bedrockModule.BedrockAgentRuntimeClient.prototype,
command: InvokeAgentCommand,
) {
if (command?.constructor?.name === "InvokeAgentCommand") {

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@caroger caroger requested a review from Parker-Stafford July 22, 2025 16:41
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jul 24, 2025
@satyadevai satyadevai force-pushed the js-bedrock-agent-instrumentation branch from 2a16d3a to fccc66c Compare July 24, 2025 07:14
@satyadevai satyadevai force-pushed the js-bedrock-agent-instrumentation branch from fccc66c to d9527b2 Compare July 24, 2025 07:17
Comment on lines +10 to +11
const agentId = "<AgentId>"; // Replace with your actual agent ID
const agentAliasId = "<AgentAliasId>"; // Replace with your actual agent alias ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could move to env variables and have an env.example or something, don't have to but might be more consistent with other instrumentation examples

Comment on lines +17 to +25
if (requestBody.agentId) {
invocationParams.agentId = requestBody.agentId;
}
if (requestBody.agentAliasId) {
invocationParams.agentAliasId = requestBody.agentAliasId;
}
if (requestBody.sessionId) {
invocationParams.sessionId = requestBody.sessionId;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious what makes these three invocation params important here? like should we just spread the command.input into invocation params? what are we missing if we just take these three?

export function extractBaseRequestAttributes(
command: InvokeAgentCommand,
): Record<string, string> {
const attributes: Record<string, string> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is an attributes type from open inference would use it

const attributes: Record<string, string> = {
[SemanticConventions.OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.LLM,
[SemanticConventions.LLM_SYSTEM]: "bedrock",
[SemanticConventions.INPUT_MIME_TYPE]: MimeType.JSON,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the case? looks like down below you are just adding text as the input, which would make this mimeType.text

command: InvokeAgentCommand,
): Record<string, string> {
const attributes: Record<string, string> = {
[SemanticConventions.OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.LLM,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't know enough about this package, is this not span kind of agent?

});
}

protected init(): InstrumentationModuleDefinition<unknown>[] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think if we type these things with the type of the BedrockModule not unknown we can simplify some of the checks and stuff dodwn below liek the getBedrockAgentModule and also provide type saftey for clients. If not possible no problem but maybe look at the openai instrumentation for how it handles these types

}
return original.apply(this, [command]);
};
/* eslint-disable @typescript-eslint/no-this-alias */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

this,
);
}
return original.apply(this, [command]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for my own understanding why is this wrapped in an array when the original type does not seem to do so?

});

it("should record agent attributes and API response in span", async () => {
// instrumentation = create_instrumentation(memoryExporter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

"content": {
"encoding": "base64",
"mimeType": "application/vnd.amazon.eventstream",
"size": 480,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the comment above on consuming the stream it doesn't look like any of the recordings have stream chunks is it possible to do so or no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

🗺 [instrumentation] Amazon Bedrock Agents instrumentation (client-agent-bedrock-time)
3 participants