Skip to content

feat: Add exception telemetry#9194

Merged
ogabrielluiz merged 38 commits into
mainfrom
add-telemetry
Aug 18, 2025
Merged

feat: Add exception telemetry#9194
ogabrielluiz merged 38 commits into
mainfrom
add-telemetry

Conversation

@Yukiyukiyeah
Copy link
Copy Markdown
Contributor

@Yukiyukiyeah Yukiyukiyeah commented Jul 25, 2025

This pull request introduces exception telemetry logging to the langflow backend, enabling better tracking and analysis of unhandled exceptions. Key changes include adding a new telemetry payload schema for exceptions, implementing a method to log exceptions to the telemetry service, and adding unit and integration tests to validate the functionality.

Telemetry Enhancements:

  • Added ExceptionPayload to the telemetry schema to capture exception details, including type, message, context, and a stack trace hash for grouping similar exceptions (src/backend/base/langflow/services/telemetry/schema.py).
  • Implemented log_exception in the telemetry service to log unhandled exceptions with context and a hashed stack trace for grouping (src/backend/base/langflow/services/telemetry/service.py).

Exception Logging Integration:

  • Integrated exception telemetry logging into the lifespan and exception_handler methods, ensuring exceptions are captured and reported to the telemetry service (src/backend/base/langflow/main.py) [1] [2] [3].

Testing:

  • Added unit tests to validate the ExceptionPayload schema, log_exception method, and telemetry service behavior, including respect for the do_not_track setting (src/backend/tests/unit/test_exception_telemetry.py).
  • Added integration tests to verify end-to-end functionality, including HTTP request formatting and service integration without FastAPI (src/backend/tests/integration/test_exception_telemetry.py).

Yukiyukiyeah and others added 28 commits July 16, 2025 21:50
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Template tests are already run separately in CI via the test-templates job.
This change prevents duplicate execution and eliminates timeout failures
in the unit test suite by excluding slow template execution tests.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Template tests are already run separately in CI via the test-templates job.
This change prevents duplicate execution and eliminates timeout failures
in the unit test suite by excluding slow template execution tests.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Template tests are already run separately in CI via the test-templates job.
This change prevents duplicate execution and eliminates timeout failures
in the unit test suite by excluding slow template execution tests.

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

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed 4 failing tests in test_validate.py:
- test_code_with_syntax_error: Better error message handling for syntax errors
- test_raises_error_for_missing_function: Handle StopIteration along with ValueError
- test_creates_simple_class: Use optional constructor parameter to avoid TypeError
- test_handles_validation_error: Use proper ValidationError constructor from pydantic_core
- test_creates_context_with_langflow_imports: Remove invalid module patching
- test_creates_mock_classes_on_import_failure: Use proper import mocking

All 50 validate tests now pass consistently, improving CI stability.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Added 6 additional test cases to improve coverage of template_validation.py:
- test_validate_stream_exception: Tests Graph.validate_stream() exception handling
- test_code_validation_other_exceptions: Tests TypeError/KeyError/AttributeError handling
- test_vertices_sorted_without_end_vertex_events: Tests variable usage tracking
- test_vertex_count_tracking: Tests vertex_count increment paths
- test_empty_lines_in_stream: Tests empty line handling in event streams
- test_event_stream_validation_exception: Tests exception handling in _validate_event_stream

These tests target the remaining 7 uncovered lines to maximize coverage percentage.
Total tests: 40 (all passing)

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

Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive exception telemetry to capture and send unhandled
exceptions to Scarf analytics for better error tracking and debugging.

Features:
- ExceptionPayload schema with type, message, context, and stack hash
- TelemetryService.log_exception() method for exception logging
- Integration in FastAPI exception handlers and lifespan events
- Stack trace hashing for grouping similar exceptions
- Respects existing do_not_track privacy settings

Context tracking:
- "handler" - exceptions in HTTP request processing
- "lifespan" - exceptions during app startup/shutdown

Sends data to: https://langflow.gateway.scarf.sh/exception

Includes comprehensive unit and integration tests covering all
functionality and edge cases.

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace MD5 with SHA256 for better security practices
- Use contextlib.suppress instead of try-except-pass patterns
- Fix telemetry_service scope issue in lifespan function
- Improve test exception handling to follow best practices
- All linting checks now pass with proper code style

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

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 25, 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

This update introduces comprehensive validation and testing infrastructure for Langflow starter project templates. It adds new validation utilities, extensive unit and integration tests, a dedicated GitHub Actions workflow, pre-commit hook, and Makefile targets for template testing. Additionally, it implements telemetry exception logging throughout the FastAPI app and enhances the telemetry service and schema.

Changes

Cohort / File(s) Change Summary
CI/CD and Pre-commit Integration
.github/workflows/ci.yml, .github/workflows/template-tests.yml, .pre-commit-config.yaml, Makefile
Adds a new GitHub Actions workflow and CI job for template tests, a pre-commit hook for starter project validation, and Makefile targets to run and exclude template tests.
Telemetry Exception Logging
src/backend/base/langflow/main.py, src/backend/base/langflow/services/telemetry/service.py, src/backend/base/langflow/services/telemetry/schema.py
Implements structured exception telemetry logging in the FastAPI app, adds a new telemetry schema for exceptions, and a method in the telemetry service to log exceptions with stack trace hashing.
Template Validation Utilities
src/backend/base/langflow/utils/template_validation.py, src/backend/base/langflow/utils/validate.py
Introduces a new module for validating template structure, build, code, and execution; enhances code validation to use a custom Langflow execution context.
Template and Telemetry Unit/Integration Tests
src/backend/tests/unit/template/__init__.py, src/backend/tests/unit/template/test_starter_projects.py, src/backend/tests/unit/test_exception_telemetry.py, src/backend/tests/integration/test_exception_telemetry.py, src/backend/tests/unit/utils/test_template_validation.py, src/backend/tests/unit/utils/test_validate.py
Adds comprehensive unit and integration tests for starter project templates, template validation utilities, telemetry exception logging, and code validation utilities.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GitHub Actions
    participant Pre-commit
    participant Makefile
    participant TestRunner
    participant TemplateValidation
    participant TelemetryService
    participant FastAPI

    User->>GitHub Actions: Push/PR triggers workflow
    GitHub Actions->>TestRunner: Run test_starter_projects.py
    TestRunner->>TemplateValidation: Validate templates (structure, build, code, execution)
    TemplateValidation-->>TestRunner: Validation results

    User->>Pre-commit: Commit starter project JSON
    Pre-commit->>TestRunner: Run template validation with security check

    User->>Makefile: make template_tests
    Makefile->>TestRunner: Run pytest on test_starter_projects.py

    FastAPI->>TelemetryService: On exception, call log_exception
    TelemetryService->>TelemetryService: Hash stack trace, build ExceptionPayload
    TelemetryService->>Telemetry Backend: Send telemetry data
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • feat: Add template tests #9083: Adds and enhances testing infrastructure for starter project templates, targeting the same test file and workflows—directly related to these changes.

Suggested labels

lgtm, size:XL

Suggested reviewers

  • deon-sanchez
  • erichare
  • mendonk
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-telemetry

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 29, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 13, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 18, 2025
@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Aug 18, 2025
@ogabrielluiz ogabrielluiz added this pull request to the merge queue Aug 18, 2025
@ogabrielluiz ogabrielluiz removed the DO NOT MERGE Don't Merge this PR label Aug 18, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 18, 2025
@ogabrielluiz ogabrielluiz enabled auto-merge August 18, 2025 17:07
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 18, 2025
@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 18, 2025

Codecov Report

❌ Patch coverage is 76.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.88%. Comparing base (020d1d1) to head (8317efb).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/backend/base/langflow/main.py 50.00% 6 Missing ⚠️

❌ Your project status has failed because the head coverage (2.71%) is below the target coverage (10.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #9194      +/-   ##
==========================================
+ Coverage   32.45%   32.88%   +0.42%     
==========================================
  Files        1217     1198      -19     
  Lines       57572    56989     -583     
  Branches     5373     5232     -141     
==========================================
+ Hits        18687    18738      +51     
+ Misses      38825    38191     -634     
  Partials       60       60              
Flag Coverage Δ
backend 53.98% <76.00%> (+0.12%) ⬆️

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

Files with missing lines Coverage Δ
...backend/base/langflow/services/telemetry/schema.py 100.00% <100.00%> (ø)
...ackend/base/langflow/services/telemetry/service.py 84.00% <100.00%> (+2.80%) ⬆️
src/backend/base/langflow/main.py 65.03% <50.00%> (-1.52%) ⬇️

... and 125 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.

@ogabrielluiz ogabrielluiz added this pull request to the merge queue Aug 18, 2025
Merged via the queue into main with commit ec7579d Aug 18, 2025
50 of 51 checks passed
@ogabrielluiz ogabrielluiz deleted the add-telemetry branch August 18, 2025 17:45
lucaseduoli pushed a commit that referenced this pull request Aug 22, 2025
* add template tests

* remove files

* adding validate flow build

* add validate endpoint and flow execution

* Update .github/workflows/template-tests.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update src/backend/base/langflow/utils/template_validation.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* [autofix.ci] apply automated fixes

* change workflow running

* add ci

* fix test

* fix test

* delete when push

* fix: Exclude template tests from unit test bundle

Template tests are already run separately in CI via the test-templates job.
This change prevents duplicate execution and eliminates timeout failures
in the unit test suite by excluding slow template execution tests.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Exclude template tests from unit test bundle

Template tests are already run separately in CI via the test-templates job.
This change prevents duplicate execution and eliminates timeout failures
in the unit test suite by excluding slow template execution tests.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Exclude template tests from unit test bundle

Template tests are already run separately in CI via the test-templates job.
This change prevents duplicate execution and eliminates timeout failures
in the unit test suite by excluding slow template execution tests.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Remove remaining merge conflict markers

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Improve validate.py unit tests to eliminate CI failures

Fixed 4 failing tests in test_validate.py:
- test_code_with_syntax_error: Better error message handling for syntax errors
- test_raises_error_for_missing_function: Handle StopIteration along with ValueError
- test_creates_simple_class: Use optional constructor parameter to avoid TypeError
- test_handles_validation_error: Use proper ValidationError constructor from pydantic_core
- test_creates_context_with_langflow_imports: Remove invalid module patching
- test_creates_mock_classes_on_import_failure: Use proper import mocking

All 50 validate tests now pass consistently, improving CI stability.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* enhance: Add comprehensive edge case tests for template_validation.py

Added 6 additional test cases to improve coverage of template_validation.py:
- test_validate_stream_exception: Tests Graph.validate_stream() exception handling
- test_code_validation_other_exceptions: Tests TypeError/KeyError/AttributeError handling
- test_vertices_sorted_without_end_vertex_events: Tests variable usage tracking
- test_vertex_count_tracking: Tests vertex_count increment paths
- test_empty_lines_in_stream: Tests empty line handling in event streams
- test_event_stream_validation_exception: Tests exception handling in _validate_event_stream

These tests target the remaining 7 uncovered lines to maximize coverage percentage.
Total tests: 40 (all passing)

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

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: Add telemetry for unhandled exceptions

Add comprehensive exception telemetry to capture and send unhandled
exceptions to Scarf analytics for better error tracking and debugging.

Features:
- ExceptionPayload schema with type, message, context, and stack hash
- TelemetryService.log_exception() method for exception logging
- Integration in FastAPI exception handlers and lifespan events
- Stack trace hashing for grouping similar exceptions
- Respects existing do_not_track privacy settings

Context tracking:
- "handler" - exceptions in HTTP request processing
- "lifespan" - exceptions during app startup/shutdown

Sends data to: https://langflow.gateway.scarf.sh/exception

Includes comprehensive unit and integration tests covering all
functionality and edge cases.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Improve exception telemetry implementation

- Replace MD5 with SHA256 for better security practices
- Use contextlib.suppress instead of try-except-pass patterns
- Fix telemetry_service scope issue in lifespan function
- Improve test exception handling to follow best practices
- All linting checks now pass with proper code style

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

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor the exception logging

* [autofix.ci] apply automated fixes

* update comment

* use mock url

* fix: remove telemetry logging for lifespan cancellation during shutdown

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
lucaseduoli pushed a commit that referenced this pull request Aug 25, 2025
* add template tests

* remove files

* adding validate flow build

* add validate endpoint and flow execution

* Update .github/workflows/template-tests.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update src/backend/base/langflow/utils/template_validation.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* [autofix.ci] apply automated fixes

* change workflow running

* add ci

* fix test

* fix test

* delete when push

* fix: Exclude template tests from unit test bundle

Template tests are already run separately in CI via the test-templates job.
This change prevents duplicate execution and eliminates timeout failures
in the unit test suite by excluding slow template execution tests.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Exclude template tests from unit test bundle

Template tests are already run separately in CI via the test-templates job.
This change prevents duplicate execution and eliminates timeout failures
in the unit test suite by excluding slow template execution tests.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Exclude template tests from unit test bundle

Template tests are already run separately in CI via the test-templates job.
This change prevents duplicate execution and eliminates timeout failures
in the unit test suite by excluding slow template execution tests.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Remove remaining merge conflict markers

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Improve validate.py unit tests to eliminate CI failures

Fixed 4 failing tests in test_validate.py:
- test_code_with_syntax_error: Better error message handling for syntax errors
- test_raises_error_for_missing_function: Handle StopIteration along with ValueError
- test_creates_simple_class: Use optional constructor parameter to avoid TypeError
- test_handles_validation_error: Use proper ValidationError constructor from pydantic_core
- test_creates_context_with_langflow_imports: Remove invalid module patching
- test_creates_mock_classes_on_import_failure: Use proper import mocking

All 50 validate tests now pass consistently, improving CI stability.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* enhance: Add comprehensive edge case tests for template_validation.py

Added 6 additional test cases to improve coverage of template_validation.py:
- test_validate_stream_exception: Tests Graph.validate_stream() exception handling
- test_code_validation_other_exceptions: Tests TypeError/KeyError/AttributeError handling
- test_vertices_sorted_without_end_vertex_events: Tests variable usage tracking
- test_vertex_count_tracking: Tests vertex_count increment paths
- test_empty_lines_in_stream: Tests empty line handling in event streams
- test_event_stream_validation_exception: Tests exception handling in _validate_event_stream

These tests target the remaining 7 uncovered lines to maximize coverage percentage.
Total tests: 40 (all passing)

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

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: Add telemetry for unhandled exceptions

Add comprehensive exception telemetry to capture and send unhandled
exceptions to Scarf analytics for better error tracking and debugging.

Features:
- ExceptionPayload schema with type, message, context, and stack hash
- TelemetryService.log_exception() method for exception logging
- Integration in FastAPI exception handlers and lifespan events
- Stack trace hashing for grouping similar exceptions
- Respects existing do_not_track privacy settings

Context tracking:
- "handler" - exceptions in HTTP request processing
- "lifespan" - exceptions during app startup/shutdown

Sends data to: https://langflow.gateway.scarf.sh/exception

Includes comprehensive unit and integration tests covering all
functionality and edge cases.

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Improve exception telemetry implementation

- Replace MD5 with SHA256 for better security practices
- Use contextlib.suppress instead of try-except-pass patterns
- Fix telemetry_service scope issue in lifespan function
- Improve test exception handling to follow best practices
- All linting checks now pass with proper code style

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

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor the exception logging

* [autofix.ci] apply automated fixes

* update comment

* use mock url

* fix: remove telemetry logging for lifespan cancellation during shutdown

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants