Skip to content

Commit 0cf365f

Browse files
committed
fix: use aws-opentelemetry-distro and add input/output logging for LangGraph agent
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
1 parent 30e6a74 commit 0cf365f

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
@@ -2027,12 +2027,15 @@ async def invoke(payload, context):
20272027
20282028
# Process the user prompt
20292029
prompt = payload.get("prompt", "What can you help me with?")
2030+
log.info(f"Agent input: {prompt}")
20302031
20312032
# Run the agent
20322033
result = await graph.ainvoke({"messages": [HumanMessage(content=prompt)]})
20332034
20342035
# Return result
2035-
return {"result": result["messages"][-1].content}
2036+
output = result["messages"][-1].content
2037+
log.info(f"Agent output: {output}")
2038+
return {"result": output}
20362039
20372040
20382041
if __name__ == "__main__":
@@ -2261,8 +2264,7 @@ description = "AgentCore Runtime Application using LangChain/LangGraph"
22612264
readme = "README.md"
22622265
requires-python = ">=3.10"
22632266
dependencies = [
2264-
"opentelemetry-distro",
2265-
"opentelemetry-exporter-otlp",
2267+
"aws-opentelemetry-distro",
22662268
"langgraph >= 1.0.2",
22672269
"mcp >= 1.19.0",
22682270
"langchain-mcp-adapters >= 0.1.11",

src/assets/python/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/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)