Skip to content

Conversation

@endigma
Copy link
Member

@endigma endigma commented Jul 22, 2025

Summary by CodeRabbit

  • Refactor
    • Improved planning-phase instrumentation to enhance trace timing and planner metric accuracy, including clearer cache-hit attribution and error logging during planning. No changes to app behavior or APIs.
  • Chores
    • Enhanced observability around planning operations for more reliable diagnostics and performance insights, with no user-facing impact.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • I have read the Contributors Guide.

@coderabbitai
Copy link

coderabbitai bot commented Jul 22, 2025

Walkthrough

Adjusts sequencing and conditions of planning-phase instrumentation in PreHandler.handleOperation. EndPlanning is now conditional based on ExcludePlannerStats; planningTime is computed after EndPlanning; plan cache-hit attribute is recorded post-EndPlanning; error attachment occurs after planningTime calculation. No changes to exported/public APIs.

Changes

Cohort / File(s) Summary of changes
GraphQL prehandler instrumentation
router/core/graphql_prehandler.go
Reordered planning instrumentation: conditional EndPlanning based on ExcludePlannerStats; moved plan cache-hit attribute setting to after EndPlanning; computed planningTime after EndPlanning; in error path, computed planningTime before attaching error and after conditional EndPlanning; no public API changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jesse/eng-7408-planning-time-alert

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

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

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.

@endigma endigma force-pushed the jesse/eng-7408-planning-time-alert branch from d9f7662 to cc6fb30 Compare July 22, 2025 11:09
@github-actions
Copy link

github-actions bot commented Jul 22, 2025

Router-nonroot image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-2ffa9503f86349d9a3cbec8314e901e987a8379f-nonroot

@endigma endigma force-pushed the jesse/eng-7408-planning-time-alert branch 6 times, most recently from 6f9a84a to 72c66c6 Compare July 30, 2025 14:19
@endigma endigma force-pushed the jesse/eng-7408-planning-time-alert branch 4 times, most recently from a229d8e to 69c6af3 Compare August 7, 2025 09:04
@endigma endigma force-pushed the jesse/eng-7408-planning-time-alert branch 5 times, most recently from 1a37ef3 to a3ea5a4 Compare August 15, 2025 09:01
@endigma endigma changed the title wip: add log when planning time exceeds threshhold fix(router): record operation planning time correctly in plan error case Aug 15, 2025
@endigma endigma force-pushed the jesse/eng-7408-planning-time-alert branch from a3ea5a4 to 9f6c4a0 Compare August 15, 2025 13:12
@endigma endigma marked this pull request as ready for review August 15, 2025 13:12
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)
router/core/graphql_prehandler.go (1)

985-996: Good fix: compute planningTime and end planning timing before attaching the error

  • Ending the planning timing (when enabled) and computing planningTime before attaching the error to the span ensures the reported duration reflects the full planning attempt.
  • Attaching the error to enginePlanSpan after timing is computed is the right order.

One consideration: do we want to observe/emit the planning time metric even on planning errors? Right now, the measurement happens only in the success path. If the intent of this PR is to “record operation planning time correctly in plan error case,” you might also want to emit the metric on error. If that matches product expectations, consider this small addition inside the error branch:

Apply this diff inside the error branch (after planningTime is computed and before ending the span):

   if err != nil {
     httpOperation.requestLogger.Debug("failed to plan operation", zap.Error(err))

     if !requestContext.operation.traceOptions.ExcludePlannerStats {
       httpOperation.traceTimings.EndPlanning()
     }

     requestContext.operation.planningTime = time.Since(startPlanning)

+    // Optionally record planning time metric even on error
+    planningAttrs := *requestContext.telemetry.AcquireAttributes()
+    planningAttrs = append(planningAttrs, otel.WgEnginePlanCacheHit.Bool(requestContext.operation.planCacheHit))
+    planningAttrs = append(planningAttrs, requestContext.telemetry.metricAttrs...)
+    httpOperation.operationMetrics.routerMetrics.MetricStore().MeasureOperationPlanningTime(
+      req.Context(),
+      requestContext.operation.planningTime,
+      requestContext.telemetry.metricSliceAttrs,
+      otelmetric.WithAttributeSet(attribute.NewSet(planningAttrs...)),
+    )
+    requestContext.telemetry.ReleaseAttributes(&planningAttrs)
+
     rtrace.AttachErrToSpan(enginePlanSpan, err)
     enginePlanSpan.End()

     return err
   }

If the desired behavior is to only emit planning-time metrics on success, feel free to ignore the suggestion.

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2a1164a and 9f6c4a0.

📒 Files selected for processing (1)
  • router/core/graphql_prehandler.go (2 hunks)
⏰ 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). (11)
  • GitHub Check: build-router
  • GitHub Check: image_scan (nonroot)
  • GitHub Check: image_scan
  • GitHub Check: build_push_image (nonroot)
  • GitHub Check: integration_test (./events)
  • GitHub Check: build_push_image
  • GitHub Check: integration_test (./. ./fuzzquery ./lifecycle ./modules)
  • GitHub Check: build_test
  • GitHub Check: integration_test (./telemetry)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
router/core/graphql_prehandler.go (2)

966-971: Conditional StartPlanning is correct and consistent with other timing sections

Making traceTimings.StartPlanning conditional on ExcludePlannerStats aligns with how parse/normalize/validate timings are handled. No issues spotted.


1001-1008: Success path ordering looks good

  • EndPlanning is conditional, planningTime is computed after EndPlanning, and the plan cache-hit attribute is set before ending the span. This sequencing avoids skewed timing and ensures attributes are attached to the correct span.

Copy link
Contributor

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

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

LGTM

@endigma endigma merged commit efbd9f6 into main Aug 15, 2025
28 checks passed
@endigma endigma deleted the jesse/eng-7408-planning-time-alert branch August 15, 2025 13:36
@Noroth Noroth mentioned this pull request Sep 30, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants