Skip to content

Commit f24609f

Browse files
fix: use aws-opentelemetry-distro and add input/output logging for LangGraph agent (#552)
The LangGraph template was using the generic opentelemetry-distro which doesn't integrate properly with AWS X-Ray and CloudWatch. This resulted in only 1 span and no input/output logs in the runtime log group. Switch to aws-opentelemetry-distro (matching the Strands template) to enable proper AWS-native telemetry with botocore instrumentation that captures Bedrock model calls, tool usage, and trace context. Also add input/output logging to the agent entrypoint. Fixes #551 Co-authored-by: Jesse Turner <ajesstur@amazon.com>
1 parent 49e3d7c commit f24609f

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,12 +2904,15 @@ async def invoke(payload, context):
29042904
29052905
# Process the user prompt
29062906
prompt = payload.get("prompt", "What can you help me with?")
2907+
log.info(f"Agent input: {prompt}")
29072908
29082909
# Run the agent
29092910
result = await graph.ainvoke({"messages": [HumanMessage(content=prompt)]})
29102911
29112912
# Return result
2912-
return {"result": result["messages"][-1].content}
2913+
output = result["messages"][-1].content
2914+
log.info(f"Agent output: {output}")
2915+
return {"result": output}
29132916
29142917
29152918
if __name__ == "__main__":
@@ -3147,8 +3150,7 @@ description = "AgentCore Runtime Application using LangChain/LangGraph"
31473150
readme = "README.md"
31483151
requires-python = ">=3.10"
31493152
dependencies = [
3150-
"opentelemetry-distro",
3151-
"opentelemetry-exporter-otlp",
3153+
"aws-opentelemetry-distro",
31523154
"langgraph >= 1.0.2",
31533155
"mcp >= 1.19.0",
31543156
"langchain-mcp-adapters >= 0.1.11",

src/assets/python/http/langchain_langgraph/base/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ async def invoke(payload, context):
5454

5555
# Process the user prompt
5656
prompt = payload.get("prompt", "What can you help me with?")
57+
log.info(f"Agent input: {prompt}")
5758

5859
# Run the agent
5960
result = await graph.ainvoke({"messages": [HumanMessage(content=prompt)]})
6061

6162
# Return result
62-
return {"result": result["messages"][-1].content}
63+
output = result["messages"][-1].content
64+
log.info(f"Agent output: {output}")
65+
return {"result": output}
6366

6467

6568
if __name__ == "__main__":

src/assets/python/http/langchain_langgraph/base/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ description = "AgentCore Runtime Application using LangChain/LangGraph"
99
readme = "README.md"
1010
requires-python = ">=3.10"
1111
dependencies = [
12-
"opentelemetry-distro",
13-
"opentelemetry-exporter-otlp",
12+
"aws-opentelemetry-distro",
1413
"langgraph >= 1.0.2",
1514
"mcp >= 1.19.0",
1615
"langchain-mcp-adapters >= 0.1.11",

0 commit comments

Comments
 (0)