fix: [#90] Add OpenTelemetry tracing support as optional backend#389
Open
nandanosql wants to merge 1 commit into
Open
fix: [#90] Add OpenTelemetry tracing support as optional backend#389nandanosql wants to merge 1 commit into
nandanosql wants to merge 1 commit into
Conversation
…kend
Add OpenTelemetry-based tracing alongside the existing JSON file
recorder. Key changes:
- New trae_agent/utils/otel_recorder.py module with:
- setup_otel_tracing() for configuring OTLP exporter
- OTelTrajectoryRecorder that creates spans for agent runs,
LLM calls, and agent steps
- Graceful fallback when opentelemetry packages are not installed
- Modified Agent.__init__() to detect OTEL_EXPORTER_OTLP_ENDPOINT
env var and initialize OTel tracing when available
- Modified Agent.run() to start/finalize OTel traces around
agent execution
- Added 'otel' optional dependency group in pyproject.toml:
uv sync --extra otel
Usage:
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 trae-cli run "..."
The JSON file recorder continues to work unchanged - OTel is purely
additive and requires explicit opt-in via env var + installed packages.
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #90
Problem
The current trajectory recording writes JSON files to disk. While useful for debugging, this approach cannot integrate with standard observability toolchains (Jaeger, Zipkin, Grafana Tempo, Datadog, etc.) that rely on distributed tracing.
Solution
Added OpenTelemetry (OTel) tracing as an optional parallel backend that runs alongside the existing JSON recorder. This is non-breaking — the JSON recorder continues to work exactly as before.
New module:
trae_agent/utils/otel_recorder.pysetup_otel_tracing()— initializes OTLP gRPC exporter fromOTEL_EXPORTER_OTLP_ENDPOINTenv varOTelTrajectoryRecorder— emits spans for:opentelemetrypackages are not installedIntegration in
Agent__init__detectsOTEL_EXPORTER_OTLP_ENDPOINTand initializes OTel if availablerun()wraps execution withstart_recording/finalize_recordingDependencies
Added optional
[otel]extra:Usage
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 trae-cli run "Fix the bug"Spans will appear in any OTLP-compatible backend. The JSON trajectory file is still written alongside.