Skip to content

Conversation

@dhaifley
Copy link
Contributor

@dhaifley dhaifley commented Nov 13, 2025

  • Fix custom tracing span attributes for the kagent-adk, kagent-langgraph, kagent-crewai packages.
  • Add a custom span processor which can be used to include custom kagent span metrics for all spans created within a particular OTel trace context.
  • Use the custom span processor, and update the execute method of each agent framework package to set the custom span attributes in context.

Copilot AI review requested due to automatic review settings November 13, 2025 21:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a custom span processor to propagate kagent-specific attributes to all tracing spans, including those created by auto-instrumentation libraries. The change ensures that user_id, task_id, and session_id attributes are automatically added to all spans in a request context.

  • Introduces KagentAttributesSpanProcessor that reads attributes from OpenTelemetry context and applies them to spans
  • Registers the new span processor alongside the existing OTLP processor in the tracing configuration
  • Refactors attribute setting in _agent_executor.py to use context variables instead of manually setting attributes on individual spans, and fixes a typo in the conversation ID attribute name

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
python/packages/kagent-core/src/kagent/core/tracing/_span_processor.py Implements the new KagentAttributesSpanProcessor class and helper functions for managing kagent span attributes in the OpenTelemetry context
python/packages/kagent-core/src/kagent/core/tracing/_utils.py Integrates the new span processor by registering it alongside the OTLP processor in both the existing and new TracerProvider code paths
python/packages/kagent-adk/src/kagent/adk/_agent_executor.py Refactors to set attributes via context variables at the start of request handling instead of manually setting them on individual spans, and fixes the "gen_ai.converstation.id" typo to "gen_ai.conversation.id"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dhaifley dhaifley force-pushed the main branch 2 times, most recently from f732faa to 69ab337 Compare November 13, 2025 21:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@dhaifley dhaifley force-pushed the main branch 2 times, most recently from 06d0ce4 to bab2750 Compare November 14, 2025 02:06
@dhaifley dhaifley force-pushed the main branch 3 times, most recently from 80e3107 to d8fb212 Compare November 14, 2025 19:37
@dhaifley dhaifley changed the title fix(kagent-adk): use span processor for custom span attributes fix(kagent-adk): create kagent_a2a_request span for kagent-adk requests Nov 14, 2025
@dhaifley dhaifley changed the title fix(kagent-adk): create kagent_a2a_request span for kagent-adk requests fix(kagent-adk): create execute span for kagent-adk requests Nov 14, 2025
@dhaifley dhaifley force-pushed the main branch 4 times, most recently from ab682ed to 96da0f4 Compare November 14, 2025 22:34
@dhaifley dhaifley changed the title fix(kagent-adk): create execute span for kagent-adk requests fix(tracing): create parent execute span for kagent requests Nov 14, 2025
@dhaifley dhaifley changed the title fix(tracing): create parent execute span for kagent requests fix(tracing): use a span processor to add custom span attributes Nov 17, 2025
@dhaifley dhaifley force-pushed the main branch 4 times, most recently from ee06296 to 76fc396 Compare November 17, 2025 21:02
@dhaifley dhaifley force-pushed the main branch 3 times, most recently from 046cd7d to 60fb794 Compare November 17, 2025 23:59
@dhaifley dhaifley requested a review from ilackarms as a code owner November 18, 2025 00:40
@dhaifley dhaifley force-pushed the main branch 8 times, most recently from d1893a9 to e926981 Compare November 18, 2025 06:30
Signed-off-by: David Haifley <david.haifley@solo.io>
@dhaifley dhaifley force-pushed the main branch 2 times, most recently from 21fd721 to f304951 Compare November 19, 2025 20:51
@peterj peterj merged commit 86432d6 into kagent-dev:main Nov 20, 2025
16 checks passed
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