Skip to content

fix: langwatch traces all api endpoints#11013

Merged
HzaRashid merged 5 commits into
mainfrom
fix/langwatch-trace-api
Dec 15, 2025
Merged

fix: langwatch traces all api endpoints#11013
HzaRashid merged 5 commits into
mainfrom
fix/langwatch-trace-api

Conversation

@HzaRashid
Copy link
Copy Markdown
Collaborator

@HzaRashid HzaRashid commented Dec 14, 2025

skips open telemetry setup to prevent LangWatch from picking up all instrumented traffic (e.g., api calls #9567), and creates a dedicated TracerProvider so that it continues to trace flow execution.

Summary by CodeRabbit

  • New Features
    • Enhanced LangWatch integration with improved tracing and observability capabilities through optimized OpenTelemetry support.
    • Implemented lazy-initialized tracer provider for efficient resource management and flexible observability configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions Bot added the bug Something isn't working label Dec 14, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 14, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A single file modification to add lazy-initialized OpenTelemetry tracer provider support to LangWatchTracer, including class attribute addition, trace call enhancement, and setup method modification with OTL provider configuration.

Changes

Cohort / File(s) Summary
LangWatch OpenTelemetry Tracer Provider
src/backend/base/langflow/services/tracing/langwatch.py
Added tracer_provider class attribute to LangWatchTracer. Modified trace creation to pass tracer_provider=self.tracer_provider. Enhanced setup_langwatch with lazy-initialized shared OpenTelemetry tracer provider: imports OTLPSpanExporter, Resource, TracerProvider, BatchSpanProcessor; conditionally creates Resource and tracer provider from environment variables; attaches BatchSpanProcessor; initializes LangWatch client with skip_open_telemetry_setup=True.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the lazy-initialization logic and thread-safety considerations for the shared tracer_provider attribute
  • Verify correct handling of environment variables (LANGWATCH_API_KEY, LANGWATCH_ENDPOINT)
  • Confirm OpenTelemetry configuration chain (Resource → OTLPSpanExporter → TracerProvider → BatchSpanProcessor)
  • Ensure skip_open_telemetry_setup=True prevents duplicate initialization and doesn't cause conflicts with existing tracing setup

Pre-merge checks and finishing touches

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 4 warnings)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error The PR introduces LangWatchTracer class with tracer_provider initialization and OTLP configuration, but no tests exist for the new LangWatchTracer implementation. Add test_langwatch_tracer.py with tests for lazy initialization, OTLP configuration, skip_open_telemetry_setup parameter, shared provider behavior, and regression tests.
Title check ⚠️ Warning The PR title 'fix: langwatch traces all api endpoints' is somewhat misleading. The actual change prevents LangWatch from tracing ALL API endpoints by skipping OpenTelemetry setup and using a dedicated TracerProvider to limit tracing to flow execution only. Revise the title to accurately reflect the fix, such as: 'fix: prevent langwatch from tracing all api endpoints' or 'fix: limit langwatch tracing to flow execution only'
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Test Quality And Coverage ⚠️ Warning No new tests added for LangWatchTracer class modifications including tracer_provider initialization, OpenTelemetry setup, lazy initialization, and LangWatch client integration. Add comprehensive unit tests covering tracer provider initialization, OpenTelemetry component instantiation, lazy initialization behavior, parameter passing to LangWatch client, missing API key handling, and ImportError handling for langwatch module.
Test File Naming And Structure ⚠️ Warning The PR modifies langwatch.py with new OpenTelemetry setup logic but lacks corresponding unit tests for tracer provider initialization, lazy-loading, and edge cases. Add unit tests in test_langwatch_tracer.py covering tracer provider initialization, lazy-loading, environment variable handling, OpenTelemetry configuration, and error scenarios.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Excessive Mock Usage Warning ✅ Passed The custom check for excessive mock usage applies only to test files. This PR modifies only production code and metadata files, with no test file changes.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Dec 14, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 14, 2025

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 17%
16.65% (4686/28138) 10.02% (2179/21743) 10.93% (676/6180)

Unit Test Results

Tests Skipped Failures Errors Time
1829 0 💤 0 ❌ 0 🔥 24.571s ⏱️

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 14, 2025

Codecov Report

❌ Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 33.09%. Comparing base (056a76a) to head (07f8bdc).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ackend/base/langflow/services/tracing/langwatch.py 0.00% 17 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (40.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (39.21%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11013      +/-   ##
==========================================
- Coverage   33.11%   33.09%   -0.02%     
==========================================
  Files        1389     1389              
  Lines       65685    65699      +14     
  Branches     9720     9720              
==========================================
- Hits        21750    21742       -8     
- Misses      42821    42843      +22     
  Partials     1114     1114              
Flag Coverage Δ
backend 52.37% <0.00%> (-0.09%) ⬇️
frontend 15.35% <ø> (ø)
lfx 39.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ackend/base/langflow/services/tracing/langwatch.py 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Dec 14, 2025
@HzaRashid HzaRashid force-pushed the fix/langwatch-trace-api branch from 53b538c to fb8f9e2 Compare December 15, 2025 14:30
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Dec 15, 2025
Comment thread src/backend/base/langflow/services/tracing/langwatch.py
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Dec 15, 2025
)
provider = TracerProvider(resource=resource)
provider.add_span_processor(BatchSpanProcessor(exporter))
LangWatchTracer.tracer_provider = provider
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.

why not add this to the instance?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

my understanding is (bear with me i'm still unravelling how our tracing works haha), it is expensive to create the tracer_provider each time this class is instantiated, so by tying it to a class variable, subsequent (flow) runs after the first one will have faster tracing setup time for langwatch

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.

The tracing service SHOULD be doing that only once, if it isn't that's another bug to fix.

I guess it makes sense to make a class attribute as it gives the best of both worlds.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

i think the tracers get lazily initialized on each graph run, will look into it more deeply, this could be a nice performance improvement

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Dec 15, 2025
@HzaRashid HzaRashid enabled auto-merge December 15, 2025 19:00
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Dec 15, 2025
@HzaRashid HzaRashid added this pull request to the merge queue Dec 15, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Dec 15, 2025
@HzaRashid HzaRashid force-pushed the fix/langwatch-trace-api branch from 31a20ed to 153cd8b Compare December 15, 2025 20:24
@HzaRashid HzaRashid enabled auto-merge December 15, 2025 20:25
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Dec 15, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Dec 15, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Dec 15, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Dec 15, 2025
@HzaRashid HzaRashid added this pull request to the merge queue Dec 15, 2025
Merged via the queue into main with commit c1c930b Dec 15, 2025
88 of 91 checks passed
@HzaRashid HzaRashid deleted the fix/langwatch-trace-api branch December 15, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants