Skip to content

fix: improves observability of provider websocket#1751

Merged
stalniy merged 1 commit intomainfrom
fix/provider-proxy-ws
Jul 30, 2025
Merged

fix: improves observability of provider websocket#1751
stalniy merged 1 commit intomainfrom
fix/provider-proxy-ws

Conversation

@stalniy
Copy link
Contributor

@stalniy stalniy commented Jul 29, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced logging for certificate validation, including detailed events for invalid certificates, successful verification, and premature WebSocket closures during validation.
  • Bug Fixes

    • Improved reliability in tracing context propagation during asynchronous WebSocket operations.

@stalniy stalniy requested a review from a team as a code owner July 29, 2025 17:52
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Walkthrough

The changes introduce structured logging for certificate validation outcomes within the WebSocket server, emitting specific log events for valid, invalid, and prematurely closed connections. Additionally, callback functions in asynchronous message proxying are wrapped with tracing context propagation to maintain observability during WebSocket operations.

Changes

Cohort / File(s) Change Summary
WebSocket Observability & Tracing
apps/provider-proxy/src/services/WebsocketServer.ts
Added structured logging for certificate validation results (valid, invalid, closed during validation). Wrapped asynchronous callbacks in proxyMessageToProvider with propagateTracingContext to ensure tracing context propagation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant WebsocketServer
    participant Provider

    Client->>WebsocketServer: Initiate WebSocket connection
    WebsocketServer->>WebsocketServer: Validate provider certificate
    alt Certificate valid
        WebsocketServer->>WebsocketServer: Log "PROVIDER_CERTIFICATE_VERIFIED"
        WebsocketServer->>Provider: Establish connection
    else Certificate invalid
        WebsocketServer->>WebsocketServer: Log "PROVIDER_INVALID_CERTIFICATE"
        WebsocketServer-->>Client: Close connection
    else WebSocket closes during validation
        WebsocketServer->>WebsocketServer: Log "PROVIDER_WEBSOCKET_CLOSED"
    end

    Client->>WebsocketServer: Send message
    WebsocketServer->>Provider: Proxy message (with tracing context)
    Provider-->>WebsocketServer: Response
    WebsocketServer-->>Client: Forward response (with tracing context)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • fix: ensure tracing context is propagated during proxing #1664: Both PRs enhance tracing context propagation by wrapping asynchronous callbacks with propagateTracingContext, but they apply this fix in different modules and for different asynchronous operations, making the changes related in purpose but not directly overlapping in code.

Suggested reviewers

  • baktun14

Poem

In cables and certs, the packets do flow,
With tracing and logs, now we always know.
If a cert goes awry, or a socket says goodbye,
The server will warn, as the bytes flutter by.
🐇✨ Observability hops to new heights—oh my!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/provider-proxy-ws

🪧 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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.

@codecov
Copy link

codecov bot commented Jul 29, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.50%. Comparing base (746028c) to head (e7e3dff).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...pps/provider-proxy/src/services/WebsocketServer.ts 66.66% 2 Missing ⚠️

❌ Your patch status has failed because the patch coverage (66.66%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1751      +/-   ##
==========================================
- Coverage   72.66%   72.50%   -0.16%     
==========================================
  Files         627      622       -5     
  Lines       15022    14849     -173     
  Branches     2645     2631      -14     
==========================================
- Hits        10915    10767     -148     
+ Misses       3767     3744      -23     
+ Partials      340      338       -2     
Flag Coverage Δ *Carryforward flag
api 80.27% <ø> (ø) Carriedforward from 746028c
deploy-web 58.64% <ø> (ø) Carriedforward from 746028c
log-collector ?
notifications 87.25% <ø> (ø) Carriedforward from 746028c
provider-console 80.95% <ø> (ø) Carriedforward from 746028c
provider-proxy 84.75% <66.66%> (-0.25%) ⬇️

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...pps/provider-proxy/src/services/WebsocketServer.ts 85.63% <66.66%> (-0.84%) ⬇️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/provider-proxy/src/services/WebsocketServer.ts (1)

336-343: LGTM! Good observability for premature WebSocket closure.

The structured logging effectively captures the edge case where a WebSocket closes during certificate validation. The warn level is appropriate as this could indicate network issues or race conditions.

Note: The event name "PROVIDER_WEBSOCKET_CLOSED" is also used at line 406 for normal WebSocket closure. Consider using a more specific event name like "PROVIDER_WEBSOCKET_CLOSED_DURING_VALIDATION" to distinguish between normal closure and premature closure during validation for better observability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 746028c and e7e3dff.

📒 Files selected for processing (1)
  • apps/provider-proxy/src/services/WebsocketServer.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/provider-proxy/src/services/WebsocketServer.ts
**/*.{js,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/provider-proxy/src/services/WebsocketServer.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: codecov/project/deploy-web
  • GitHub Check: test-build
🔇 Additional comments (3)
apps/provider-proxy/src/services/WebsocketServer.ts (3)

244-255: LGTM! Proper tracing context propagation implementation.

The callback functions are correctly wrapped with propagateTracingContext to ensure tracing context is maintained during asynchronous WebSocket operations. This aligns with the observability improvements mentioned in the PR objectives.


318-324: LGTM! Well-structured logging for certificate validation failures.

The structured logging provides clear observability into certificate validation failures with appropriate contextual information. The use of warn level and the event name "PROVIDER_INVALID_CERTIFICATE" makes it easy to monitor and alert on certificate issues.


330-335: LGTM! Appropriate logging for successful certificate verification.

The debug-level structured logging for successful certificate verification provides valuable observability without being too verbose. The event name and contextual information are well-chosen for monitoring certificate validation outcomes.

@stalniy stalniy merged commit 54cf2cf into main Jul 30, 2025
61 of 62 checks passed
@stalniy stalniy deleted the fix/provider-proxy-ws branch July 30, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments