Bedrock Agent Instrumentation
An OpenTelemetry instrumentation framework for AWS Bedrock Agents using OpenInference semantic convention.
Content
Bedrock Agent Instrumentation
An OpenTelemetry instrumentation framework for AWS Bedrock Agents using OpenInference semantic convention.
Files
main.py: Core instrumentation wrapper for Bedrock Agent invocations using python fileexample-notebook.ipynb: Core instrumentation wrapper for Bedrock Agent invocations using a jupyter notebookconfig.py: Configuration for different tracing backends (Arize, Langfuse). Please configure your API keys hereprocessors.py: Processes traces (preprocessing, orchestration, etc.)handlers.py: Handles trace events (LLM calls, tools, etc.)utils.py: Utilities for timing and trace management
Setup
- Install dependencies:
pip install -r requirements.txt
- Decorate your invoke_agent api call:
@instrument_agent_invocation
def invoke_bedrock_agent(inputText: str, agentId: str, agentAliasId: str, sessionId: str):
bedrock_rt_client = boto3.client('bedrock-agent-runtime')
response = bedrock_rt_client.invoke_agent(
inputText=inputText,
agentId=agentId,
agentAliasId=agentAliasId,
sessionId=sessionId,
enableTrace=True
)
return response
- Modify main.py:
if __name__ == "__main__":
try:
agentId='agent-id',
agentAliasId='agent-alias-is'
sessionId='define-session-id'
trace_collector="arize_cloud" # langfuse, and arize_local are other options
userId = "Somename"
questions = "your prompt goes here"
invoke_bedrock_agent(
inputText=question,
agentId=agentId,
agentAliasId=agentAliasId,
sessionId=sessionId,
userId=userId,
provider=trace_collector,
show_traces=True
)
except Exception as e:
logger.error(f"Error invoking agent: {str(e)}")Source and license
- Source
- Amazon Bedrock Samples
- Original
- aws-samples/amazon-bedrock-samples/evaluation-observe/agent-observability
- License
- MIT