Skip to content
This repository was archived by the owner on Nov 12, 2026. It is now read-only.

🌱 Otel auto instrumentation extensions - #105

Closed
Ladas wants to merge 10 commits into
rossoctl:mainfrom
Ladas:phoenix-autoinstrumentation
Closed

Ladas wants to merge 10 commits into
rossoctl:mainfrom
Ladas:phoenix-autoinstrumentation

Conversation

@Ladas

@Ladas Ladas commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

Summary

WIP: experiment with otel auto instrumentation for weather agent

Related issue(s)

Relates to rossoctl/rossoctl#436

Ladas and others added 10 commits November 27, 2025 15:43
Implements comprehensive OTEL observability for weather service agent with
Phoenix integration, baggage propagation, and GenAI semantic conventions.

## Changes

### New Module: observability.py
- ObservabilityConfig: Reads OTEL config from environment variables
- setup_observability(): Configures OTEL tracer with proper resource attributes
- Baggage propagation functions for context tracking (user_id, request_id, etc.)
- Extract baggage from HTTP headers
- Phoenix project routing via resource attributes

### Updated Dependencies (pyproject.toml)
- opentelemetry-api>=1.20.0
- opentelemetry-sdk>=1.20.0
- opentelemetry-exporter-otlp>=1.20.0
- opentelemetry-exporter-otlp-proto-grpc>=1.20.0
- opentelemetry-instrumentation>=0.41b0
- openinference-semantic-conventions>=0.1.0

### Updated __init__.py
- Replace basic tracer setup with comprehensive setup_observability()
- Ensures OpenInference instrumentation loads before agent code

### Updated agent.py
- Remove duplicate LangChainInstrumentor() call (now in observability.py)
- Extract baggage context from request headers
- Set baggage for each request (user_id, request_id, task_id, etc.)
- Log trace info for debugging

## Features

✅ Auto-instrumentation with OpenInference (LangChain LLM, Tool, Chain spans)
✅ OTEL baggage propagation across all services
✅ Phoenix project routing (team1-agents, etc.)
✅ GenAI semantic conventions compliance
✅ K8s metadata via resource attributes
✅ Comprehensive logging for observability debugging

## Resource Attributes

All traces include:
- service.name: weather-service
- service.namespace: {namespace}
- k8s.namespace.name: {namespace}
- phoenix.project.name: {namespace}-agents
- deployment.environment: kind-local

## Baggage Context

Baggage propagates across all spans:
- user_id: User identifier
- request_id: Unique request ID
- task_id: A2A task ID
- context_id: A2A context ID

## Testing

To test locally:
1. Deploy with OTEL environment variables set
2. Send request with user-id and request-id headers
3. Check Phoenix UI for traces with baggage attributes

## Related

- Part of Phoenix Integration (TODO_PHOENIX_INTEGRATION.md)
- Phase 1: Agent Instrumentation
- Prepares for E2E tests in Phase 2

Signed-off-by: Claude Code AI Assistant <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
- Replace baggage.get_current() with context.get_current() (API fix)
- Add configurable OTLP exporter supporting both gRPC and HTTP protocols
- Default to HTTP/protobuf for wider compatibility
- Update default endpoint to use correct kagenti-system namespace and port 4318

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
The OTEL Collector in kagenti-system is configured to listen on port
8335 (via --set override), not the standard 4318. Updated the default
endpoint in observability.py to match.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
- Add create_agent_span() for root AGENT span with OI attributes
- Wrap graph execution with using_attributes for session/user tracking
- Add a2a.task_id, a2a.context_id, user.id to spans for filtering
- Set input.value and output.value on agent spans

This ensures all LangChain auto-instrumented spans are properly
nested under an AGENT span and have session/user context.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
The previous commit removed these imports but they're still used by
set_baggage_context function.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Use OpenInference-compatible tracer name "openinference.instrumentation.agent"
so that root AGENT spans pass through the OTEL Collector's filter/phoenix
processor which only allows spans from "openinference.instrumentation.*".

Previously used "weather_service.observability" which was filtered out.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add as_root=True parameter to create_agent_span()
- Use empty Context() to break parent inheritance from A2A SDK telemetry
- Ensures weather_agent_task appears as root span in Phoenix UI

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Instead of breaking parent context in create_agent_span(), we'll allow
a2a.utils.telemetry spans through the OTEL Collector filter. This
preserves the complete trace hierarchy.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Phase 1 of trace propagation implementation:

1. observability.py:
   - Configure W3C Trace Context and Baggage propagators
   - Add extract_trace_context() for incoming HTTP headers
   - Add inject_trace_context() for outgoing HTTP calls
   - Add trace_context_from_headers() context manager

2. agent.py:
   - Wrap entire execute method with trace_context_from_headers()
   - All spans now become children of incoming traceparent
   - Enables proper parent-child relationships across A2A calls

This enables:
- Single connected trace from HTTP request through LLM calls
- Multi-agent call flows with proper trace hierarchy
- Phoenix visibility into complete request flow

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@Ladas
Ladas marked this pull request as draft December 3, 2025 09:23
Ladas added a commit to Ladas/agent-examples that referenced this pull request Feb 4, 2026
Port observability.py from PR rossoctl#105 to provide clean abstraction for:
- setup_observability() for one-time tracer initialization
- create_agent_span() context manager for AGENT spans
- W3C Trace Context propagation for distributed tracing

Added OpenInference dependencies (semantic-conventions and
instrumentation-langchain) to enable LangChain auto-instrumentation
with AGENT span semantics for MLflow compatibility.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
@Ladas

Ladas commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

replaced by #114

@Ladas Ladas closed this Feb 6, 2026
Ladas added a commit to Ladas/agent-examples that referenced this pull request Feb 6, 2026
Port observability.py from PR rossoctl#105 to provide clean abstraction for:
- setup_observability() for one-time tracer initialization
- create_agent_span() context manager for AGENT spans
- W3C Trace Context propagation for distributed tracing

Added OpenInference dependencies (semantic-conventions and
instrumentation-langchain) to enable LangChain auto-instrumentation
with AGENT span semantics for MLflow compatibility.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
Ladas added a commit to Ladas/agent-examples that referenced this pull request Feb 12, 2026
Port observability.py from PR rossoctl#105 to provide clean abstraction for:
- setup_observability() for one-time tracer initialization
- create_agent_span() context manager for AGENT spans
- W3C Trace Context propagation for distributed tracing

Added OpenInference dependencies (semantic-conventions and
instrumentation-langchain) to enable LangChain auto-instrumentation
with AGENT span semantics for MLflow compatibility.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant