Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): New Tracer API #2068

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

feat(server): New Tracer API #2068

wants to merge 6 commits into from

Conversation

EmrysMyrddin
Copy link
Collaborator

@EmrysMyrddin EmrysMyrddin commented Feb 18, 2025

Description

This PR is the continuation of n1ru4l/envelop#2430 which introduces a new core API: The Tracer.

A plugin (and only one) can define a tracer instance that will wrap every phases of a request pipeline.

In the case of wahtwg-node, it only adds the request wrapper.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Summary by CodeRabbit

  • Chores

    • Updated version control settings to ignore additional configuration files.
  • New Features

    • Enhanced server request handling with integrated tracing for improved logging and monitoring.
    • Introduced a new optional tracer property in the server adapter plugin for better observability.
    • Added a new Tracer API for advanced request handling capabilities.

Copy link

coderabbitai bot commented Feb 18, 2025

Walkthrough

The changes update the repository’s ignore rules and integrate tracing into the server adapter. Three new entries were added to the .gitignore to prevent configuration files from being tracked. In the server adapter code, a new Tracer type is imported; the request handler now supports optional tracing, reassigning the handler to wrap it with tracer functionality. Additionally, the plugin interface has been updated to include a tracer property, and the Tracer type is declared. These updates adjust control flow in request handling to accommodate request tracing.

Changes

File(s) Change Summary
.gitignore Added ignore entries for .helix/config.toml, .helix/languages.toml, and .mise.toml.
packages/server/src/createServerAdapter.ts
packages/server/src/plugins/types.ts
Integrated tracing functionality:
- Imported and declared new Tracer type.
- Updated createServerAdapter to wrap the request handler with tracer logic.
- Added tracer property to the ServerAdapterPlugin interface.
.changeset/purple-buses-try.md Introduced a new Tracer API and updated the package version for @whatwg-node/server.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ServerAdapter
    participant Plugin
    participant Tracer
    participant RequestHandler

    Client->>ServerAdapter: Receives request
    ServerAdapter->>Plugin: Check for tracer
    Plugin-->>ServerAdapter: Provides tracer (if available)
    alt Tracer exists
        ServerAdapter->>Tracer: Log request & wrap handler
        Tracer-->>ServerAdapter: Return wrapped handler
    end
    ServerAdapter->>RequestHandler: Process request
    RequestHandler-->>ServerAdapter: Return response
    ServerAdapter-->>Client: Send response
Loading

Suggested reviewers

  • dotansimha
  • enisdenjo

Poem

I'm a rabbit in code, hopping through new trails,
Adding tracers and ignores as my furry story entails.
My whiskers twitch with each line of change,
Leaping over bugs with a joyful range.
In this digital warren, innovation prevails!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link
Contributor

github-actions bot commented Feb 18, 2025

@benchmarks/node-fetch results (noConsumeBody)

   ✓ active_handles.................: avg=140.390868 min=31      med=140     max=175     p(90)=161     p(95)=165    
     data_received..................: 21 MB  694 kB/s
     data_sent......................: 14 MB  450 kB/s
     http_req_blocked...............: avg=3.5µs      min=651ns   med=1.37µs  max=11.86ms p(90)=2.05µs  p(95)=2.38µs 
     http_req_connecting............: avg=1.66µs     min=0s      med=0s      max=5.81ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=21.95ms    min=5.28ms  med=21.28ms max=1.21s   p(90)=27.71ms p(95)=29.61ms
       { expected_response:true }...: avg=21.95ms    min=5.28ms  med=21.28ms max=1.21s   p(90)=27.71ms p(95)=29.61ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 136180
     http_req_receiving.............: avg=35.12µs    min=9.64µs  med=23.74µs max=27.99ms p(90)=38.76µs p(95)=45.56µs
     http_req_sending...............: avg=11.24µs    min=3.45µs  med=6.52µs  max=16.67ms p(90)=10.08µs p(95)=14.13µs
     http_req_tls_handshaking.......: avg=0s         min=0s      med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=21.91ms    min=4.94ms  med=21.24ms max=1.21s   p(90)=27.66ms p(95)=29.54ms
     http_reqs......................: 136180 4538.77367/s
     iteration_duration.............: avg=44.03ms    min=20.45ms med=42.33ms max=1.23s   p(90)=47.35ms p(95)=54.77ms
     iterations.....................: 68069  2268.686921/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented Feb 18, 2025

@benchmarks/node-fetch results (consumeBody)

   ✓ active_handles.................: avg=140.43292 min=34      med=141     max=185     p(90)=161     p(95)=165    
     data_received..................: 20 MB  673 kB/s
     data_sent......................: 13 MB  431 kB/s
     http_req_blocked...............: avg=3.86µs    min=631ns   med=1.2µs   max=6.18ms  p(90)=1.99µs  p(95)=2.22µs 
     http_req_connecting............: avg=1.97µs    min=0s      med=0s      max=5.94ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=22.66ms   min=3.38ms  med=22.02ms max=1.12s   p(90)=28.44ms p(95)=30.4ms 
       { expected_response:true }...: avg=22.66ms   min=3.38ms  med=22.02ms max=1.12s   p(90)=28.44ms p(95)=30.4ms 
     http_req_failed................: 0.00%  ✓ 0           ✗ 131971
     http_req_receiving.............: avg=33.42µs   min=9.27µs  med=23.54µs max=16.94ms p(90)=37.46µs p(95)=43.98µs
     http_req_sending...............: avg=10.42µs   min=3.25µs  med=5.8µs   max=13.26ms p(90)=9.59µs  p(95)=13.22µs
     http_req_tls_handshaking.......: avg=0s        min=0s      med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=22.62ms   min=3.34ms  med=21.98ms max=1.12s   p(90)=28.39ms p(95)=30.34ms
     http_reqs......................: 131971 4398.63678/s
     iteration_duration.............: avg=45.43ms   min=11.66ms med=43.81ms max=1.14s   p(90)=49.58ms p(95)=55.33ms
     iterations.....................: 65966  2198.668448/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

Copy link

@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 (5)
packages/server/src/createServerAdapter.ts (3)

104-104: Optional doc comment for tracer
Consider adding a brief explanation of the tracer property to clarify its optional usage and purpose.


148-155: Improve error details when multiple tracers are found
This block properly enforces the single-tracer constraint, but it might be helpful to include the plugin's identifier or name in the error message to aid in debugging.

-          throw new Error(
-            'Multiple tracers have been declared. Only one plugin with a tracer is allowed.',
-          );
+          throw new Error(
+            `Multiple tracers have been declared. Only one plugin with a tracer is allowed. Plugin: ${plugin.name || 'unknown'}`
+          );

252-262: Handle potential undefined response
If tracer.request never invokes the wrapped function, response may remain undefined. Consider providing a fallback response or throwing an error, rather than relying on the non-null assertion.

-      return isPromise(tracerPromise) ? tracerPromise.then(() => response) : response!;
+      return isPromise(tracerPromise)
+        ? tracerPromise.then(() => response ?? new Response('No response returned by tracer', { status: 500 }))
+        : (response ?? new Response('No response returned by tracer', { status: 500 }));
packages/server/src/plugins/types.ts (2)

1-1: Remove unused import or adjust usage
The imported MaybePromise is currently unused. If you plan to unify your promise signatures with MaybePromise, consider applying it to your tracer definition. Otherwise, remove the import.


53-58: Unify signature with MaybePromise
You already import MaybePromise; consider using it here for consistency, for instance:
request: (payload: { request: Request }, wrapped: () => MaybePromise<void>) => MaybePromise<void>;

-export type Tracer = {
-  request: (
-    payload: { request: Request },
-    wrapped: () => Promise<void> | void,
-  ) => Promise<void> | void;
-};
+export type Tracer = {
+  request: (
+    payload: { request: Request },
+    wrapped: () => MaybePromise<void>,
+  ) => MaybePromise<void>;
+};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 005485d and 214e981.

📒 Files selected for processing (3)
  • .gitignore (1 hunks)
  • packages/server/src/createServerAdapter.ts (5 hunks)
  • packages/server/src/plugins/types.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore
🧰 Additional context used
🪛 Biome (1.9.4)
packages/server/src/plugins/types.ts

[error] 8-8: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: unit / node 23
  • GitHub Check: unit / node 22
  • GitHub Check: unit / deno
  • GitHub Check: unit / node 20
  • GitHub Check: unit / bun
  • GitHub Check: esm
  • GitHub Check: server (undici)
  • GitHub Check: e2e / cloudflare-modules
  • GitHub Check: server (ponyfill)
  • GitHub Check: e2e / cloudflare-workers
  • GitHub Check: unit / node 18
  • GitHub Check: lint
  • GitHub Check: e2e / azure-function
  • GitHub Check: node-fetch (consumeBody)
  • GitHub Check: prettier
  • GitHub Check: server (native)
  • GitHub Check: e2e / aws-lambda
  • GitHub Check: node-fetch (noConsumeBody)
  • GitHub Check: type check
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
packages/server/src/createServerAdapter.ts (2)

3-3: Looking good for the new import of Tracer
No issues spotted with the added import statement.


176-176: Allowing re-assignment of handleRequest
Switching from const to let is correct to accommodate wrapping the request handler with tracer logic.

packages/server/src/plugins/types.ts (1)

9-13: Typo in documentation and consider making property optional

  1. "insance" should be "instance".
  2. The usage in createServerAdapter checks if plugin.tracer exists, so consider marking tracer as optional (tracer?: Tracer;).
    [nitpick, refactor_suggestion_good_to_have]
-   * A tracer insance. It can be used to wrap...
+   * A tracer instance. It can be used to wrap...

Copy link
Contributor

github-actions bot commented Feb 18, 2025

@benchmarks/server results (native)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 223174      ✗ 0     
     data_received..................: 22 MB   748 kB/s
     data_sent......................: 8.9 MB  298 kB/s
     http_req_blocked...............: avg=1.56µs   min=922ns    med=1.33µs   max=295.34µs p(90)=2.05µs   p(95)=2.29µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=119.85µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=201.31µs min=146.51µs med=190.22µs max=10.63ms  p(90)=215.6µs  p(95)=225.89µs
       { expected_response:true }...: avg=201.31µs min=146.51µs med=190.22µs max=10.63ms  p(90)=215.6µs  p(95)=225.89µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 111587
     http_req_receiving.............: avg=26.62µs  min=13.61µs  med=25.04µs  max=3.15ms   p(90)=32.48µs  p(95)=35.25µs 
     http_req_sending...............: avg=7.11µs   min=4.19µs   med=6.77µs   max=920.61µs p(90)=8.78µs   p(95)=10.26µs 
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=167.56µs min=117.55µs med=156.97µs max=10.54ms  p(90)=179.55µs p(95)=188.98µs
     http_reqs......................: 111587  3719.423118/s
     iteration_duration.............: avg=263.92µs min=195.77µs med=251.79µs max=10.8ms   p(90)=280.89µs p(95)=293.8µs 
     iterations.....................: 111587  3719.423118/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Feb 18, 2025

@benchmarks/server results (ponyfill)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 288200      ✗ 0     
     data_received..................: 28 MB   946 kB/s
     data_sent......................: 12 MB   384 kB/s
     http_req_blocked...............: avg=1.42µs   min=891ns    med=1.21µs   max=506.73µs p(90)=1.87µs   p(95)=2.06µs  
     http_req_connecting............: avg=0ns      min=0s       med=0s       max=125.61µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=143.58µs min=92.56µs  med=138.27µs max=6.47ms   p(90)=160.63µs p(95)=168.16µs
       { expected_response:true }...: avg=143.58µs min=92.56µs  med=138.27µs max=6.47ms   p(90)=160.63µs p(95)=168.16µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 144100
     http_req_receiving.............: avg=24.8µs   min=12.48µs  med=23.21µs  max=3.15ms   p(90)=30.65µs  p(95)=33.58µs 
     http_req_sending...............: avg=6.6µs    min=4.04µs   med=5.82µs   max=1.5ms    p(90)=8.36µs   p(95)=9.44µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=112.16µs min=66.83µs  med=106.53µs max=6.29ms   p(90)=125.88µs p(95)=131.92µs
     http_reqs......................: 144100  4803.148474/s
     iteration_duration.............: avg=203.5µs  min=143.95µs med=197.55µs max=7.71ms   p(90)=223.13µs p(95)=233.06µs
     iterations.....................: 144100  4803.148474/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Feb 18, 2025

@benchmarks/server results (undici)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 218690      ✗ 0     
     data_received..................: 22 MB   733 kB/s
     data_sent......................: 8.7 MB  292 kB/s
     http_req_blocked...............: avg=1.43µs   min=892ns    med=1.22µs   max=200.9µs  p(90)=1.92µs   p(95)=2.09µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=110.29µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=212.14µs min=154.76µs med=200.71µs max=45.73ms  p(90)=226.61µs p(95)=235.59µs
       { expected_response:true }...: avg=212.14µs min=154.76µs med=200.71µs max=45.73ms  p(90)=226.61µs p(95)=235.59µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 109345
     http_req_receiving.............: avg=25.65µs  min=13.45µs  med=23.89µs  max=2.85ms   p(90)=31.14µs  p(95)=33.92µs 
     http_req_sending...............: avg=6.35µs   min=3.97µs   med=5.55µs   max=299.76µs p(90)=8.12µs   p(95)=8.84µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=180.13µs min=132.16µs med=169.06µs max=45.65ms  p(90)=191.63µs p(95)=199.98µs
     http_reqs......................: 109345  3644.712243/s
     iteration_duration.............: avg=269.85µs min=198.39µs med=257.58µs max=45.88ms  p(90)=286.83µs p(95)=298.2µs 
     iterations.....................: 109345  3644.712243/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link

@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 (2)
packages/server/src/plugins/types.ts (2)

8-12: Fix typo in JSDoc comment.

There's a typo in the JSDoc comment: "insance" should be "instance".

- * A tracer insance. It can be used to wrap the entire request handling pipeline (including the
+ * A tracer instance. It can be used to wrap the entire request handling pipeline (including the

52-57: Add JSDoc documentation and consider error handling.

The Tracer type would benefit from:

  1. JSDoc documentation explaining its purpose and usage
  2. Explicit error handling guidance for the wrapped function

Add JSDoc documentation and consider error handling:

 export type Tracer = {
+  /**
+   * Wraps a request handling operation for tracing purposes.
+   * @param payload - The payload containing the request to be traced
+   * @param wrapped - The function to be traced
+   * @throws - Document expected errors and how they should be handled
+   * @returns A promise that resolves when the traced operation completes
+   */
   request: (
     payload: { request: Request },
     wrapped: () => Promise<void> | void,
   ) => Promise<void> | void;
 };

Consider adding error handling guidance by documenting:

  1. What happens if the wrapped function throws?
  2. Should the tracer catch and log errors?
  3. Should errors be propagated or transformed?

Would you like me to propose a more detailed error handling implementation?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 214e981 and e124814.

📒 Files selected for processing (1)
  • packages/server/src/plugins/types.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: unit / node 22
  • GitHub Check: unit / node 18

Copy link
Contributor

github-actions bot commented Feb 18, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@whatwg-node/server 0.10.0-alpha-20250218194158-de7e6d1454b125b67766395ce9bc8509d8900f93 npm ↗︎ unpkg ↗︎
@whatwg-node/server-plugin-cookies 2.0.0-alpha-20250218194158-de7e6d1454b125b67766395ce9bc8509d8900f93 npm ↗︎ unpkg ↗︎

Copy link

@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)
.changeset/purple-buses-try.md (1)

5-6: Expand on the Tracer API Description for Better Developer Guidance
The short description "Add new Tracer API" is clear but could benefit from additional details. Consider adding more context about the Tracer API's role (e.g., its purpose for wrapping request phases or performance monitoring) or linking to further documentation. This would help developers understand the impact and usage of the new feature.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e124814 and bb3f75a.

📒 Files selected for processing (1)
  • .changeset/purple-buses-try.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: unit / node 23
  • GitHub Check: unit / node 22
  • GitHub Check: unit / node 20
  • GitHub Check: unit / node 18
  • GitHub Check: type check
  • GitHub Check: server (undici)
  • GitHub Check: node-fetch (consumeBody)
  • GitHub Check: unit / deno
  • GitHub Check: server (ponyfill)
  • GitHub Check: unit / bun
  • GitHub Check: e2e / azure-function
  • GitHub Check: node-fetch (noConsumeBody)
  • GitHub Check: server (native)
🔇 Additional comments (1)
.changeset/purple-buses-try.md (1)

1-3: Ensure Consistent Version Bumping for the New Tracer API
The changeset correctly indicates a minor version update for the package @whatwg-node/server, which aligns with adding a new feature. Ensure that this update is consistent with the release strategy and that related documentation (e.g., changelogs and release notes) is updated accordingly.

@@ -78,3 +78,6 @@ package-lock.json
eslint_report.json

deno.lock
.helix/config.toml
Copy link
Owner

Choose a reason for hiding this comment

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

These are extra 😅 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's because I'm trying to use another editor than VScode ^^'

It's Helix's configuration file :-)

Actually I can commit it if someone else also want to use this editor :-)

Copy link

@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)
packages/server/src/createServerAdapter.ts (1)

176-176: Consider simplifying the tracer implementation.

The tracing implementation is solid but could be more concise.

Consider this simplified version:

-if (tracer?.request) {
+if (tracer) {
   const originalRequestHandler = handleRequest;
   handleRequest = (request, initialContext) => {
     let response: Promise<Response> | Response;
-    const tracerPromise = tracer!.request!({ request }, () => {
+    const tracerPromise = tracer.request?.({ request }, () => {
       response = originalRequestHandler(request, initialContext);
       return isPromise(response) ? response.then(() => undefined) : undefined;
     });
-    return isPromise(tracerPromise) ? tracerPromise.then(() => response) : response!;
+    return tracerPromise ? tracerPromise.then(() => response) : response;
   };
 }

This version:

  1. Removes unnecessary non-null assertions
  2. Uses optional chaining more effectively
  3. Simplifies the return statement

Also applies to: 252-262

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 058be08 and de7e6d1.

📒 Files selected for processing (1)
  • packages/server/src/createServerAdapter.ts (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: unit / node 23
  • GitHub Check: unit / deno
  • GitHub Check: unit / node 22
  • GitHub Check: unit / node 20
  • GitHub Check: unit / bun
  • GitHub Check: server (undici)
  • GitHub Check: unit / node 18
  • GitHub Check: server (ponyfill)
  • GitHub Check: node-fetch (consumeBody)
  • GitHub Check: server (native)
  • GitHub Check: e2e / azure-function
  • GitHub Check: node-fetch (noConsumeBody)
🔇 Additional comments (2)
packages/server/src/createServerAdapter.ts (2)

3-3: LGTM!

Clean import of the Tracer type, maintaining consistency with existing imports.


104-104: LGTM! Robust tracer validation.

The implementation ensures that only one tracer can be declared, with proper error handling and clear error messages.

Also applies to: 148-155

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