Skip to content

Add OpenTelemetry Tracing Support for BYO LangGraph Agents - #917

Closed
rishabh998186 wants to merge 3 commits into
kagent-dev:mainfrom
rishabh998186:feat/langgraph-otel-tracing
Closed

rishabh998186 wants to merge 3 commits into
kagent-dev:mainfrom
rishabh998186:feat/langgraph-otel-tracing

Conversation

@rishabh998186

Copy link
Copy Markdown
Contributor

Problem

BYO LangGraph agents were not emitting traces because tracing wasn't initialized for their FastAPI app. Declarative/ADK agents did emit traces since their CLI initialized tracing.

Solution

Initialize OTEL tracing/logging inside KAgentApp.build() by calling configure_tracing from kagent.core. This instruments FastAPI, httpx, and GenAI SDKs when environment variables are set.

Changes

  • kagent-langgraph: Initialize tracing in KAgentApp.build()
  • Sample CLI: Remove explicit configure_tracing call to avoid double-instrumentation warnings
  • Docs: Add tracing section to README with required env vars

Configuration

Required:

  • OTEL_TRACING_ENABLED=true
  • OTEL_EXPORTER_OTLP_ENDPOINT=(collector endpoint)

Optional:

  • OTEL_LOGGING_ENABLED=true
  • OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=(logs endpoint)

Testing

  1. Start Jaeger with make otel-local
  2. Set environment variables
  3. Run BYO LangGraph agent
  4. Test with curl health endpoint
  5. Verify spans in Jaeger UI

Files Modified

  • python/packages/kagent-langgraph/src/kagent/langgraph/_a2a.py
  • python/samples/langgraph/currency/currency/cli.py
  • python/packages/kagent-langgraph/README.md

Risk Assessment

Low risk - tracing remains disabled unless explicitly enabled via environment variables.

…to avoid double instrumentation; add README tracing docs

Signed-off-by: rishabh998186 <rishabh998186@gmail.com>

@krisztianfekete krisztianfekete left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for opening this PR! I added some questions.

Comment thread python/packages/kagent-langgraph/README.md
Comment thread python/packages/kagent-langgraph/README.md
@EItanya

EItanya commented Sep 23, 2025

Copy link
Copy Markdown
Contributor

Hey there @rishabh998186. I Have been discussing with my colleague @krisztianfekete and he said that even after a few rounds of iteration this PR is not working as expected, so we will be moving forward with #927 instead of this PR. Please take a look at #928 to better understand our updated AI usage guidelines for PRs and issues.

@EItanya EItanya closed this Sep 23, 2025
@rishabh998186
rishabh998186 deleted the feat/langgraph-otel-tracing branch September 24, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants