-
Notifications
You must be signed in to change notification settings - Fork 113
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
base: main
Are you sure you want to change the base?
feat(js-bedrock-agent-runtime): AWS Bedrock Agent Instumentaion for JS #1874
Conversation
@arizeai/openinference-core
@arizeai/openinference-instrumentation-bedrock-agent-runtime
@arizeai/openinference-instrumentation-beeai
@arizeai/openinference-instrumentation-langchain
@arizeai/openinference-instrumentation-mcp
@arizeai/openinference-instrumentation-openai
@arizeai/openinference-mastra
@arizeai/openinference-semantic-conventions
@arizeai/openinference-vercel
commit: |
782b53b
to
312e7af
Compare
bf034ec
to
6f20bf8
Compare
6f20bf8
to
628fb30
Compare
There was a problem hiding this 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
openinference/js/packages/openinference-instrumentation-bedrock-agent-runtime/src/instrumentation.ts
Lines 99 to 106 in 628fb30
) => { | |
/* 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") { |
Was this report helpful? Give feedback by reacting with 👍 or 👎
js/packages/openinference-instrumentation-bedrock-agent-runtime/package.json
Outdated
Show resolved
Hide resolved
js/packages/openinference-instrumentation-bedrock-agent-runtime/src/instrumentation.ts
Outdated
Show resolved
Hide resolved
...ackages/openinference-instrumentation-bedrock-agent-runtime/scripts/validate-invoke-agent.ts
Outdated
Show resolved
Hide resolved
...ackages/openinference-instrumentation-bedrock-agent-runtime/scripts/validate-invoke-agent.ts
Outdated
Show resolved
Hide resolved
...ackages/openinference-instrumentation-bedrock-agent-runtime/scripts/validate-invoke-agent.ts
Outdated
Show resolved
Hide resolved
js/packages/openinference-instrumentation-bedrock-agent-runtime/src/response-handler.ts
Outdated
Show resolved
Hide resolved
js/packages/openinference-instrumentation-bedrock-agent-runtime/src/stream-utils.ts
Outdated
Show resolved
Hide resolved
js/packages/openinference-instrumentation-bedrock-agent-runtime/src/instrumentation.ts
Show resolved
Hide resolved
js/packages/openinference-instrumentation-bedrock-agent-runtime/src/instrumentation.ts
Outdated
Show resolved
Hide resolved
js/packages/openinference-instrumentation-bedrock-agent-runtime/src/response-handler.ts
Outdated
Show resolved
Hide resolved
2a16d3a
to
fccc66c
Compare
fccc66c
to
d9527b2
Compare
const agentId = "<AgentId>"; // Replace with your actual agent ID | ||
const agentAliasId = "<AgentAliasId>"; // Replace with your actual agent alias ID |
There was a problem hiding this comment.
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
if (requestBody.agentId) { | ||
invocationParams.agentId = requestBody.agentId; | ||
} | ||
if (requestBody.agentAliasId) { | ||
invocationParams.agentAliasId = requestBody.agentAliasId; | ||
} | ||
if (requestBody.sessionId) { | ||
invocationParams.sessionId = requestBody.sessionId; | ||
} |
There was a problem hiding this comment.
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> = { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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>[] { |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
No description provided.