Skip to content

Enrich Sentry events with diagnostic context for workflows, cron, MCP, and connectors - #938

Merged
kody-bot merged 2 commits into
mainfrom
cursor/sentry-diagnostic-context-40e1
Jul 25, 2026
Merged

kody-bot merged 2 commits into
mainfrom
cursor/sentry-diagnostic-context-40e1

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Jul 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Recent production Sentry issues (workflow timeouts, scheduled Analytics Engine failures, MCP storage_query errors, remote-connector session noise) were hard to triage because auto-captures only had environment/release/IP. This PR attaches the coordinates we already have in-process onto Sentry scopes.

  • Workflows: set user + workflow.source_type / workflow.kody_id tags and a workflow context (package/export/instance/idempotency) at the start of DynamicCallableWorkflow so instrumentWorkflowWithSentry auto-captures are diagnosable.
  • Scheduled lanes: tag scheduled.lane and include cron/scheduledTime context on lane captureException.
  • MCP: copy conversationId, storageId, and call-site detail into the Sentry mcp context (kept off tags to avoid high cardinality).
  • Remote connectors: promote connectorId to a tag, attribute captures to the originating socket's ingress user, and move extras into a remote_connector context.

Test plan

  • Unit tests for MCP observability context enrichment
  • Unit tests for workflow Sentry scope helper
  • Remote connector session capture expectations updated (including socket user attribution)
  • Scheduled lane workers test asserts lane + cron context
  • npm run typecheck / npm run lint / focused vitest
System recap — extends existing primitives (medium risk)

Mode: recap · Base: main @ 7d88928a · Head: 59f252c0

Classification: extends — observability capture sites gain richer tags/contexts; no new primitives and no behavior changes outside Sentry reporting.

Primitives touched

Primitive Group Impact
workflows assistant extends — attach user/package/export context before auto-capture
scheduled-cron surfaces extends — tag failing lanes on capture
mcp-server surfaces extends — include conversationId/storageId/detail on MCP failures
capability-registry assistant composes — pass storageId through defineCapability logging
package-runtime runtime composes — shared workflow Sentry helper
remote-connectors / connector-ingress assistant / surfaces extends — connector id + originating socket user on session captures

System map

How failures reach Sentry, and which coordinates this PR attaches at each capture site.

Legend: green = composes · amber = extended · gray = context

flowchart LR
  subgraph surfaces["surfaces"]
    MCP["mcp-server"]
    CRON["scheduled-cron"]
    ING["connector-ingress"]
  end
  subgraph assistant["assistant"]
    WF["workflows"]
    CAP["capability-registry"]
    RC["remote-connectors"]
  end
  subgraph runtime["runtime"]
    PR["package-runtime"]
  end
  Sentry[(Sentry)]

  CAP -->|storageId on logMcpEvent| MCP
  MCP -->|mcp context + detail| Sentry
  WF -->|user + workflow context| Sentry
  PR -.->|helper| WF
  CRON -->|scheduled.lane tag| Sentry
  ING --> RC
  RC -->|remote_connector.id + socket user| Sentry

  style WF fill:#f5c542,stroke:#333,color:#000
  style CRON fill:#f5c542,stroke:#333,color:#000
  style MCP fill:#f5c542,stroke:#333,color:#000
  style RC fill:#f5c542,stroke:#333,color:#000
  style ING fill:#f5c542,stroke:#333,color:#000
  style CAP fill:#8fd19e,stroke:#333,color:#000
  style PR fill:#8fd19e,stroke:#333,color:#000
  style Sentry fill:#c8c8c8,stroke:#333,color:#000
Loading

Risk and invariants

  • Medium risk: changes only what is reported to Sentry; no user-facing control flow changes.
  • Per-user isolation: only stable user.id is set (no email/PII); sendDefaultPii remains false.
  • High-cardinality ids (conversationId, storageId, workflow instance ids) stay on contexts, not tags.

Docs

No docs updates — contributor-facing observability detail only.

Open in Web Open in Cursor 

Summary by CodeRabbit

  • Observability

    • Improved monitoring for scheduled task lane failures with richer Sentry scope context.
    • Enhanced MCP activity reporting with added conversation/storage identifiers and more structured diagnostic details.
    • Improved remote connector session message reporting with clearer scope tags/levels and connector context.
    • Added dynamic Sentry scoping for workflow executions (packaged vs inline) with workflow metadata.
    • Monitoring instrumentation is guarded so it won’t disrupt execution.
  • Bug Fixes

    • Better coverage and validation for scheduled lane failure isolation while keeping sibling lanes running.

Attach user/package/export coordinates on workflow auto-captures, tag
scheduled lane failures, and copy conversationId/storageId/detail into
MCP and remote-connector Sentry scopes so recent production issues are
diagnosable without digging through truncated breadcrumbs.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR enriches Sentry reporting across scheduled lanes, MCP operations, dynamic workflows, and remote connector sessions with structured scope metadata, identifiers, source details, errors, and connected users. Tests update mocks and assertions for the scoped instrumentation.

Changes

Scheduled lane observability

Layer / File(s) Summary
Scheduled failure scope and validation
packages/worker/src/index.ts, packages/worker/src/index.workers.test.ts
Scheduled lane failures configure Sentry with lane and schedule context before capturing the exception, and tests verify the scoped metadata.

MCP observability context

Layer / File(s) Summary
MCP context contract
packages/worker/src/mcp/observability.ts, packages/worker/src/mcp/observability.node.test.ts
MCP payloads include conversation and storage identifiers, while failure context nests event details under detail; tests cover the resulting context shape.
MCP caller field propagation
packages/worker/src/mcp/capabilities/define-capability.ts, packages/worker/src/mcp/tools/execute.ts, packages/worker/src/mcp/tools/search-tool-runner.ts
MCP capability, execute, and search event payloads consistently spread shared caller fields, including optional storage identifiers.

Dynamic workflow observability

Layer / File(s) Summary
Workflow scope helper
packages/worker/src/package-runtime/package-workflows-sentry.ts
Adds typed package and inline workflow payloads and applies source-specific Sentry user, tags, and context without interrupting workflow execution.
Workflow execution integration and tests
packages/worker/src/package-runtime/package-workflows.ts, packages/worker/src/package-runtime/package-workflows-sentry.node.test.ts
Dynamic workflow runs apply the Sentry scope after payload validation and before execution; package and inline metadata are tested.

Remote connector observability

Layer / File(s) Summary
Connector message scope
packages/worker/src/remote-connector/session.ts
Remote connector messages use scoped Sentry level, tags, user, and structured context, with ingress user resolution at error sites.
Connector scope assertions
packages/worker/src/remote-connector/session.node.test.ts
Tests mock and reset Sentry scope setters and verify metadata for malformed tool results.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WorkflowRuntime
  participant ScopeHelper
  participant Sentry
  WorkflowRuntime->>ScopeHelper: Apply validated workflow payload and instanceId
  ScopeHelper->>Sentry: Set workflow user, tags, and context
  WorkflowRuntime->>WorkflowRuntime: Continue scheduling and step execution
Loading

Possibly related PRs

🚥 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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: enriching Sentry events with diagnostic context across workflows, cron/scheduled lanes, MCP, and connectors.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/sentry-diagnostic-context-40e1

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

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

@kody-bot
kody-bot marked this pull request as ready for review July 25, 2026 15:18
@github-actions

github-actions Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-938.kody-a99.workers.dev

Worker: kody-pr-938
D1: kody-pr-938-db
KV: kody-pr-938-oauth-kv

Mocks:

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 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 `@packages/worker/src/index.workers.test.ts`:
- Around line 342-348: Update the setContext assertion in the scheduled test to
also verify the cron property, using the exact cron value defined by the test
controller fixture. Keep the existing lane and scheduledTime assertions
unchanged so removing or renaming cron causes the test to fail.

In `@packages/worker/src/package-runtime/package-workflows-sentry.node.test.ts`:
- Line 28: Remove the unsupported version: 2 fields from the fresh
WorkflowSentryPayload fixture object literals in the package-workflows-sentry
tests, leaving the remaining payload properties unchanged so they satisfy the
WorkflowSentryPayload type.

In `@packages/worker/src/remote-connector/session.ts`:
- Around line 118-145: Update captureSessionMessage and its socket-originated
callers to accept and pass the triggering websocket’s loadIngressUserId(ws)
result, rather than resolving the first connected socket via
resolveConnectedIngressUserId; keep null for socket-independent events. Add a
test with two sockets and distinct users verifying each captured Sentry event is
attributed to its originating socket’s user.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9318de15-8ab2-4585-8d9f-8e28ff85d8ae

📥 Commits

Reviewing files that changed from the base of the PR and between 7d88928 and 97876d7.

📒 Files selected for processing (12)
  • packages/worker/src/index.ts
  • packages/worker/src/index.workers.test.ts
  • packages/worker/src/mcp/capabilities/define-capability.ts
  • packages/worker/src/mcp/observability.node.test.ts
  • packages/worker/src/mcp/observability.ts
  • packages/worker/src/mcp/tools/execute.ts
  • packages/worker/src/mcp/tools/search-tool-runner.ts
  • packages/worker/src/package-runtime/package-workflows-sentry.node.test.ts
  • packages/worker/src/package-runtime/package-workflows-sentry.ts
  • packages/worker/src/package-runtime/package-workflows.ts
  • packages/worker/src/remote-connector/session.node.test.ts
  • packages/worker/src/remote-connector/session.ts

Pass the originating websocket ingress user into remote-connector
Sentry captures, assert scheduled cron context, and drop excess
version fields from workflow sentry fixtures.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kody-bot
kody-bot merged commit 5ba106a into main Jul 25, 2026
5 checks passed
@kody-bot
kody-bot deleted the cursor/sentry-diagnostic-context-40e1 branch July 25, 2026 15:34
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.

3 participants