Skip to content

feat: add auto-instrumentation to langchain agent template#835

Merged
jesseturner21 merged 1 commit intoaws:mainfrom
avi-alpert:aalpert/langchain-instrumentation
Apr 14, 2026
Merged

feat: add auto-instrumentation to langchain agent template#835
jesseturner21 merged 1 commit intoaws:mainfrom
avi-alpert:aalpert/langchain-instrumentation

Conversation

@avi-alpert
Copy link
Copy Markdown
Contributor

@avi-alpert avi-alpert commented Apr 14, 2026

Description

Adds auto-instrumentation to the LangChain/LangGraph agent templates so that traces emitted by LangChain agents are compatible with AgentCore's observability and evaluation features out of the box.

Changes:

  • Import and call LangchainInstrumentor().instrument() at module level in both A2A and HTTP LangChain template main.py files
  • Add opentelemetry-instrumentation-langchain to the template pyproject.toml dependencies for both A2A and HTTP variants
  • Update asset snapshots

Why: Without the LangChain OpenTelemetry instrumentor, traces from LangChain agents are emitted under a generic scope that the Evaluate API does not recognize. Running agentcore run eval against a LangChain agent would fail with:

Error: Provided input has no spans with supported scope. Currently supported scopes are ['strands.telemetry.tracer', 'opentelemetry.instrumentation.langchain', 'openinference.instrumentation.langchain']. Please verify that you are using the supported agentic-framework and instrumentation-library

With this change, LangChain agent traces are emitted under the opentelemetry.instrumentation.langchain scope, and agentcore run eval succeeds.

Reference: Configuring custom observability in AgentCore

Type of Change

  • New feature

Testing

Verified by running agentcore run eval against a LangChain agent — evaluation completes successfully instead of returning the unsupported-scope error.

  • I ran npm run test:unit and npm run test:integ
  • I ran npm run typecheck
  • I ran npm run lint
  • If I modified src/assets/, I ran npm run test:update-snapshots and committed the updated snapshots

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.

@avi-alpert avi-alpert requested a review from a team April 14, 2026 15:58
@github-actions github-actions bot added the size/xs PR size: XS label Apr 14, 2026
@jesseturner21 jesseturner21 merged commit 31fb7d1 into aws:main Apr 14, 2026
23 checks passed
{{/if}}{{#if (eq modelProvider "Gemini")}}"langchain-google-genai >= 2.0.0",
{{/if}}{{#if (eq modelProvider "OpenAI")}}"langchain-openai >= 0.2.0",
{{/if}}"aws-opentelemetry-distro",
"opentelemetry-instrumentation-langchain",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Every other third-party dep in this file uses a >= X.Y.Z minimum pin (langgraph >= 0.2.0, bedrock-agentcore >= 1.0.3, etc.). This package is from the Traceloop/OpenLLMetry project (not AWS-controlled) and has a very active release cadence in the 0.x series. An unpinned dep could pull a breaking version for users. Same applies to the HTTP variant.

Suggested change
"opentelemetry-instrumentation-langchain",
"opentelemetry-instrumentation-langchain >= 0.38.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/xs PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants