Skip to content

feat: add more tracing instrumentation to the composition worker pool - #2905

Merged
Aenimus merged 7 commits into
mainfrom
wilson/eng-9673-controlplane-add-more-instrumentation-for-composition
Jun 2, 2026
Merged

feat: add more tracing instrumentation to the composition worker pool#2905
Aenimus merged 7 commits into
mainfrom
wilson/eng-9673-controlplane-add-more-instrumentation-for-composition

Conversation

@wilsonrivera

@wilsonrivera wilsonrivera commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Improved observability: end-to-end tracing now spans controller and worker composition steps, with trace context propagated into worker tasks for richer performance and error insights.
  • Chores

    • Config separation: monitoring-related environment validation was split and strengthened for clearer, more robust Sentry/tracing configuration.

Checklist

Open Source AI Manifesto

This project follows the principles of the Open Source AI Manifesto. Please ensure your contribution aligns with its principles.

@wilsonrivera
wilsonrivera requested a review from a team as a code owner June 1, 2026 20:11

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR extracts Sentry env parsing into a separate schema, instruments WorkerPool creation and deserialization with Sentry spans, adds an optional trace field to composition tasks, injects trace context into pool.run, and continues the trace inside the composition worker with nested spans.

Changes

Sentry Instrumentation for Composition Worker

Layer / File(s) Summary
Environment schema separation and configuration
controlplane/src/core/env.schema.ts, controlplane/src/core/sentry.config.ts
Extract SENTRY_* vars into sentryEnvVariables with numeric coercion/defaults; parse Sentry env independently and guard Sentry init logging outside production.
Composition task type with trace field
controlplane/src/core/composition/composeGraphs.types.ts
Add optional trace to ComposeGraphsTaskInput carrying sentryTrace and baggage for worker payload propagation.
Pool instrumentation and trace context injection
controlplane/src/core/composition/composeGraphs.pool.ts
Create WorkerPool inside a Sentry.startSpan, wrap deserialization functions in spans, change exported composeGraphsInWorker to omit caller trace, fetch Sentry.getTraceData() and pass trace into pool.run.
Worker composition instrumentation with continued trace
controlplane/src/core/composition/composeGraphs.worker.ts
Initialize Sentry conditionally inside worker; use Sentry.continueTrace, add top-level worker span with attributes, and wrap composition steps (parseGRPCMapping, DTO->router subgraphs, serialization, schema/route build) in nested spans.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • wundergraph/cosmo#2901: Adds Sentry instrumentation to the composition worker pool with Sentry.startSpan wrapping the composeGraphsInWorker execution path.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding Sentry tracing instrumentation throughout the composition worker pool infrastructure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controlplane/src/core/composition/composeGraphs.pool.ts`:
- Around line 77-80: The code is truncating Sentry numeric settings by calling
toFixed(2) on SENTRY_TRACES_SAMPLE_RATE, SENTRY_PROFILE_SESSION_SAMPLE_RATE, and
SENTRY_EVENT_LOOP_BLOCK_THRESHOLD_MS in composeGraphs.pool.ts; remove the
toFixed(2) calls and forward the original numeric values (or explicitly
stringify them with String(...) only if the workers require strings) so sampling
rates and thresholds keep full precision; update the SENTRY_PROFILE_LIFECYCLE
entry only if it needs conversion, but do not alter numeric values via toFixed
in any of the referenced env fields.

In `@controlplane/src/core/env.schema.ts`:
- Around line 233-236: Sentry numeric env values currently accept any number;
tighten validation in env.schema.ts by constraining SENTRY_TRACES_SAMPLE_RATE
and SENTRY_PROFILE_SESSION_SAMPLE_RATE to the valid sampling range 0–1 (use
z.coerce.number().min(0).max(1).optional().default(...)) and constrain
SENTRY_EVENT_LOOP_BLOCK_THRESHOLD_MS to non‑negative (e.g.,
z.coerce.number().min(0).optional().default(100) and optionally a sensible upper
bound like .max(60000)); update the validations for the symbols
SENTRY_TRACES_SAMPLE_RATE, SENTRY_PROFILE_SESSION_SAMPLE_RATE, and
SENTRY_EVENT_LOOP_BLOCK_THRESHOLD_MS accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d134d64b-7609-4472-bb19-1a38e3ada0ff

📥 Commits

Reviewing files that changed from the base of the PR and between c363893 and adfe0de.

📒 Files selected for processing (6)
  • controlplane/src/core/composition/composeGraphs.pool.ts
  • controlplane/src/core/composition/composeGraphs.types.ts
  • controlplane/src/core/composition/composeGraphs.worker.ts
  • controlplane/src/core/env.schema.ts
  • controlplane/src/core/sentry.config.ts
  • controlplane/src/index.ts

Comment thread controlplane/src/core/composition/composeGraphs.pool.ts Outdated
Comment thread controlplane/src/core/env.schema.ts Outdated

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
controlplane/src/core/env.schema.ts (1)

222-241: ⚡ Quick win

Zod is resolved to v3 (zod@3.25.76), so z.string().optional().transform((val) => val === 'true').default('false') parses the default through the transform and produces boolean false—the truthy-string concern is Zod-4-specific. If upgrading to Zod 4 later, switch these .default('false') values to .default(false) to match the output type.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@controlplane/src/core/env.schema.ts` around lines 222 - 241, The boolean-like
env fields (SENTRY_ENABLED, SENTRY_SEND_DEFAULT_PII, SENTRY_ENABLE_LOGS)
currently use .string().optional().transform(...).default('false') which relies
on Zod v3 behavior; when you upgrade to Zod v4 change each .default('false') to
.default(false) so the default value matches the transformed boolean output
(update SENTRY_ENABLED, SENTRY_SEND_DEFAULT_PII, SENTRY_ENABLE_LOGS to use
.default(false)).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@controlplane/src/core/env.schema.ts`:
- Around line 222-241: The boolean-like env fields (SENTRY_ENABLED,
SENTRY_SEND_DEFAULT_PII, SENTRY_ENABLE_LOGS) currently use
.string().optional().transform(...).default('false') which relies on Zod v3
behavior; when you upgrade to Zod v4 change each .default('false') to
.default(false) so the default value matches the transformed boolean output
(update SENTRY_ENABLED, SENTRY_SEND_DEFAULT_PII, SENTRY_ENABLE_LOGS to use
.default(false)).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 113b4acd-cab6-48f6-b94a-9195fd7ca11d

📥 Commits

Reviewing files that changed from the base of the PR and between adfe0de and 589500c.

📒 Files selected for processing (2)
  • controlplane/src/core/composition/composeGraphs.pool.ts
  • controlplane/src/core/env.schema.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • controlplane/src/core/composition/composeGraphs.pool.ts

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
controlplane/src/core/composition/composeGraphs.worker.ts (1)

190-201: 💤 Low value

Consider differentiating span names for better trace clarity.

Both printSchemaWithDirectives spans have identical names, which could make it harder to distinguish them in traces. Consider naming them printSchemaWithDirectives.federatedGraphSchema and printSchemaWithDirectives.federatedGraphClientSchema respectively.

♻️ Proposed fix
     const composedSchema = result.success
-      ? Sentry.startSpan({ name: 'printSchemaWithDirectives' }, () =>
+      ? Sentry.startSpan({ name: 'printSchemaWithDirectives.federatedGraphSchema' }, () =>
           printSchemaWithDirectives(result.federatedGraphSchema),
         )
       : undefined;

     const federatedClientSchema = result.success
-      ? Sentry.startSpan({ name: 'printSchemaWithDirectives' }, () =>
+      ? Sentry.startSpan({ name: 'printSchemaWithDirectives.federatedGraphClientSchema' }, () =>
           printSchemaWithDirectives(result.federatedGraphClientSchema),
         )
       : undefined;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@controlplane/src/core/composition/composeGraphs.worker.ts` around lines 190 -
201, The two Sentry.startSpan calls that wrap printSchemaWithDirectives (for
result.federatedGraphSchema and result.federatedGraphClientSchema) use the same
name and should be differentiated; update the span names used in the
Sentry.startSpan invocations (the ones around
printSchemaWithDirectives(result.federatedGraphSchema) and
printSchemaWithDirectives(result.federatedGraphClientSchema)) to distinct
identifiers such as "printSchemaWithDirectives.federatedGraphSchema" and
"printSchemaWithDirectives.federatedGraphClientSchema" so traces clearly show
which schema is being printed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controlplane/src/core/composition/composeGraphs.worker.ts`:
- Around line 42-63: The Sentry env schema uses
z.string().transform(...).default('false') which yields a type mismatch under
Zod v4: the transform returns boolean but the default is the string 'false' so
the default must match the transformed type; update SENTRY_ENABLED,
SENTRY_SEND_DEFAULT_PII, and SENTRY_ENABLE_LOGS in the sentryEnvVariables object
to use .default(false) (or alternatively make the schema a
z.string().default('false').transform(...) so the default is a string that gets
transformed) so the default value type aligns with the transform output in the
sentryEnvVariables definition.

---

Nitpick comments:
In `@controlplane/src/core/composition/composeGraphs.worker.ts`:
- Around line 190-201: The two Sentry.startSpan calls that wrap
printSchemaWithDirectives (for result.federatedGraphSchema and
result.federatedGraphClientSchema) use the same name and should be
differentiated; update the span names used in the Sentry.startSpan invocations
(the ones around printSchemaWithDirectives(result.federatedGraphSchema) and
printSchemaWithDirectives(result.federatedGraphClientSchema)) to distinct
identifiers such as "printSchemaWithDirectives.federatedGraphSchema" and
"printSchemaWithDirectives.federatedGraphClientSchema" so traces clearly show
which schema is being printed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92964c62-263c-47c8-8921-1c712dd69528

📥 Commits

Reviewing files that changed from the base of the PR and between 589500c and 6256139.

📒 Files selected for processing (4)
  • controlplane/src/core/composition/composeGraphs.pool.ts
  • controlplane/src/core/composition/composeGraphs.worker.ts
  • controlplane/src/core/env.schema.ts
  • controlplane/src/core/sentry.config.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • controlplane/src/core/composition/composeGraphs.pool.ts
  • controlplane/src/core/env.schema.ts

Comment thread controlplane/src/core/composition/composeGraphs.worker.ts

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controlplane/src/core/env.schema.ts`:
- Around line 4-8: Update the Sentry env schema entries to add the missing
numeric validations: for SENTRY_TRACES_SAMPLE_RATE and
SENTRY_PROFILE_SESSION_SAMPLE_RATE apply .min(0).max(1) (keeping them
numeric/floating validations), and for SENTRY_EVENT_LOOP_BLOCK_THRESHOLD_MS
apply .int().min(0); keep the existing SENTRY_ENABLED string->boolean transform
and 'false' default as-is (Zod v3.25.x compatible) and locate these changes
around the SENTRY_* schema definitions (symbols: SENTRY_TRACES_SAMPLE_RATE,
SENTRY_PROFILE_SESSION_SAMPLE_RATE, SENTRY_EVENT_LOOP_BLOCK_THRESHOLD_MS,
SENTRY_ENABLED).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6b3e8792-cf0e-44db-a416-ad353bb63325

📥 Commits

Reviewing files that changed from the base of the PR and between 6256139 and fdee46a.

📒 Files selected for processing (3)
  • controlplane/src/core/composition/composeGraphs.pool.ts
  • controlplane/src/core/env.schema.ts
  • controlplane/src/core/sentry.config.ts
✅ Files skipped from review due to trivial changes (1)
  • controlplane/src/core/sentry.config.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • controlplane/src/core/composition/composeGraphs.pool.ts

Comment thread controlplane/src/core/env.schema.ts
@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 19.93464% with 245 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.81%. Comparing base (254810f) to head (650f741).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...plane/src/core/composition/composeGraphs.worker.ts 0.00% 239 Missing ⚠️
controlplane/src/core/sentry.config.ts 0.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2905      +/-   ##
==========================================
+ Coverage   64.61%   64.81%   +0.19%     
==========================================
  Files         326      326              
  Lines       46629    46746     +117     
  Branches     5145     5153       +8     
==========================================
+ Hits        30131    30299     +168     
+ Misses      16473    16423      -50     
+ Partials       25       24       -1     
Files with missing lines Coverage Δ
...olplane/src/core/composition/composeGraphs.pool.ts 87.59% <100.00%> (+3.28%) ⬆️
...lplane/src/core/composition/composeGraphs.types.ts 100.00% <ø> (ø)
controlplane/src/core/env.schema.ts 97.24% <100.00%> (+97.24%) ⬆️
controlplane/src/core/sentry.config.ts 0.00% <0.00%> (ø)
...plane/src/core/composition/composeGraphs.worker.ts 0.00% <0.00%> (ø)
🚀 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.

@Aenimus
Aenimus enabled auto-merge (squash) June 2, 2026 14:33
@Aenimus
Aenimus merged commit 81f82e7 into main Jun 2, 2026
10 checks passed
@Aenimus
Aenimus deleted the wilson/eng-9673-controlplane-add-more-instrumentation-for-composition branch June 2, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants