feat: Exporting traces to Traceloop and Instana#8209
Conversation
CodSpeed Performance ReportMerging #8209 will degrade performances by 15.75%Comparing Summary
Benchmarks breakdown
|
|
CI is currently skipped because should-run-ci is evaluated as false. Could you please help me look into this? @ogabrielluiz |
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the """ WalkthroughA new tracing integration called "traceloop" was added to the tracing service, including a dedicated tracer implementation using OpenTelemetry. The service and its tests were updated to support this tracer. Four new OpenTelemetry-related dependencies were added to the project configuration to support the new functionality. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TracingService
participant TraceloopTracer
participant OpenTelemetry
User->>TracingService: start_tracers()
TracingService->>TraceloopTracer: _initialize_traceloop_tracer()
TraceloopTracer->>OpenTelemetry: setup_traceloop()
TracingService->>TracingService: Register traceloop tracer in context
User->>TracingService: Trace events (add_trace, end_trace, end)
TracingService->>TraceloopTracer: add_trace / end_trace / end
TraceloopTracer->>OpenTelemetry: Create/finish spans, record attributes
Poem
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
|
@coderabbitai Please look into why the PR is effecting the language model component execution. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@edwinjosechittilappilly, I'll investigate the performance impact of the TraceLoop integration on language model component execution. Let me analyze the failing tests and the tracing implementation. 🏁 Script executed: Length of output: 14439 🏁 Script executed: Length of output: 1665 🏁 Script executed: Length of output: 111 🏁 Script executed: Length of output: 120 🏁 Script executed: Length of output: 3795 🏁 Script executed: Length of output: 14433 🏁 Script executed: Length of output: 120 🏁 Script executed: Length of output: 1183 🏁 Script executed: Length of output: 2432 Based on my investigation of the performance degradation, I can identify several key reasons why this PR is affecting language model component execution: Root Cause Analysis1. Automatic LangChain InstrumentationThe primary culprit is in the from opentelemetry.instrumentation.langchain import LangchainInstrumentor
LangchainInstrumentor().instrument(tracer_provider=self.tracer_provider, skip_dep_check=True)This automatically instruments ALL LangChain operations, adding tracing overhead to every language model call, embedding, retriever, or any LangChain component execution. 2. Tracer Initialization OverheadThe TraceLoop tracer initializes on every flow build, which includes:
3. Per-Component Tracing OverheadEach component execution now triggers:
4. Always-On TracingThe tracing appears to be enabled by default unless explicitly deactivated via settings, affecting all flow builds. Performance Impact BreakdownFrom the CodSpeed report:
The language model components are particularly affected because they're being traced at multiple levels - both the LangFlow component level and the underlying LangChain operation level. Recommended Solutions
The automatic LangChain instrumentation is the most significant contributor to the performance degradation, as it wraps every LangChain operation with tracing logic that wasn't present before this PR. 🧠 Learnings used |
|
@coderabbitai can you please compare the "traceloop.py" file with "arizephoenix.py" and re-analyse why this PR is affecting language model component execution? I've tried to follow the same approach as "arizephoenix.py" to implement "traceloop.py". |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@2getsandesh, let me compare both implementations to understand the differences that might be causing the performance impact. 🏁 Script executed: Length of output: 14756 🏁 Script executed: Length of output: 20233 🏁 Script executed: Length of output: 15331 @2getsandesh, excellent point! After comparing both implementations, I found the critical difference that explains the performance degradation. You're right that both implementations follow similar patterns, but there's one key difference in the setup logic: Root Cause: Conditional vs Always-On LangChain InstrumentationArize Phoenix (No Performance Impact)def setup_arize_phoenix(self) -> bool:
# Check if tracing is actually enabled
if not (enable_arize_tracing or enable_phoenix_tracing):
return False # ✅ EARLY EXIT - No instrumentation happens
# Only proceed with setup and instrumentation if tracing is enabled
try:
# ... setup tracer provider ...
LangChainInstrumentor().instrument(tracer_provider=self.tracer_provider, skip_dep_check=True)TraceLoop (Causes Performance Impact)def setup_traceloop(self) -> bool:
try:
# ❌ ALWAYS sets up tracer provider and resource
# ❌ ALWAYS instruments LangChain regardless of env vars
LangchainInstrumentor().instrument(tracer_provider=self.tracer_provider, skip_dep_check=True)
except ImportError:
return False
return True # ❌ Always returns True even if no exporters configuredThe ProblemTraceLoop always instruments LangChain even when no
Phoenix only instruments when tracing is actually enabled, so in test environments with no environment variables, there's zero tracing overhead. The FixYou need to add the same conditional logic as Phoenix: def setup_traceloop(self) -> bool:
# Add this early exit logic like Phoenix
traceloop_api_key = os.getenv("TRACELOOP_API_KEY")
instana_baseurl = os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT")
if not (traceloop_api_key or instana_baseurl):
return False # Early exit - no instrumentation
try:
# Only proceed with setup if tracing is actually configured
# ... rest of setup ...This simple change should eliminate the 11-15% performance degradation in environments without tracing configuration, making TraceLoop behave exactly like Phoenix. The performance impact you're seeing is entirely due to unnecessary LangChain instrumentation in test/development environments where no tracing backends are configured. 🧠 Learnings used |
|
@mfortman11 Hi, Could you please re-review this PR? |
|
@2getsandesh Please fix the backend tests in this PR. |
|
|
Closing this PR as it is outdated. The same functionality, along with extended metrics support, has been implemented in PR #9317 |


This PR introduces support for exporting traces to TraceLoop by:
Adding a new module "traceloop.py" for TraceLoop-specific tracing configuration and instrumentation which also supports IBM Instana.
Initializing TraceLoop tracing from "service.py" to ensure it's active when LangFlow starts.
Including necessary dependencies for TraceLoop and OpenTelemetry in "pyproject.toml".
Adding comprehensive tests for TraceLoop integration.
📁 Changes Made
➕ langflow/src/backend/base/langflow/services/tracing/traceloop.py:
Contains the TraceLoop tracer setup using OpenTelemetry.
🔁 Modified service.py:
Initialized TraceLoop tracer via import and setup during tracing service startup.
🧩 Updated pyproject.toml:
Added dependencies required for TraceLoop integration (e.g., opentelemetry-sdk, opentelemetry-exporter-otlp, etc.).
🧪 Enhanced test_tracing_service.py:
Added unit tests for TraceLoop tracer initialization, configuration validation, and integration with the tracing service.
🎯 Purpose
This update enables LangFlow to export telemetry data (spans, traces) to TraceLoop and Instana for improved observability and debugging, laying the foundation for robust distributed tracing.
Screenshots of the Traceloop and Instana Dashboards:


Future Scope
For provider specific instrumentation, is it accepted to include Traceloop SDK?
Summary by CodeRabbit