Skip to content

feat(plugin-sentry): add plugin for sentry#547

Merged
orionmiz merged 13 commits intodaangn:mainfrom
ysh4296:feature/plugin-sentry
Mar 30, 2026
Merged

feat(plugin-sentry): add plugin for sentry#547
orionmiz merged 13 commits intodaangn:mainfrom
ysh4296:feature/plugin-sentry

Conversation

@ysh4296
Copy link
Copy Markdown
Contributor

@ysh4296 ysh4296 commented Dec 16, 2024

plugin-sentry (Issue from #520)

Stackflow has a unique screen handling with "Activity."
Currently, Sentry doesn't support tracing for this mechanism,
So we had to create own plugin.

This pr contains a basic functional plugin that works for:

  • Tracing page load events
  • Tracing activity changes (push, pop, replace)

How I Tested It:

  • Test with demo project working on localhost, personal sentry account
  • Load built package from local file path
// demo/.../Stack.tsx

import * as Sentry from "@sentry/browser";
import { sentryPlugin } from "../../../extensions/plugin-sentry/dist";

export const { Stack, actions } = stackflow({
  config,
  components: {
    Main,
    Article,
  },
  plugins: [
    sentryPlugin({
      dsn: "https://example-dsn-key",
      integrations: [Sentry.replayIntegration()],
      // Tracing
      tracesSampleRate: 1.0, //  Capture 100% of the transactions
      // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
      tracePropagationTargets: ["localhost"],
      // Session Replay
      replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
      replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
    }),
  ],
});

Screen shots & additional explanation

Performance

image
  • Recorded transactions can be viewed under the Performance tab.
  • Both Page Load and Activity Changes (navigation events) are successfully recorded.

Error Tracing

image
  • This plugin integrates seamlessly with other tools (e.g., Replay Integration).
  • It traces user actions within transactions, providing more context for debugging.

Note

I'm not sure if this is the 'desired' behavior, so I would appreciate any feedback.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Dec 16, 2024

🦋 Changeset detected

Latest commit: 2d09def

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@stackflow/plugin-sentry Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
stackflow-docs ✅ Ready (Inspect) Visit Preview Jan 18, 2025 5:44am

@ysh4296 ysh4296 marked this pull request as ready for review December 16, 2024 07:41
@tonyfromundefined tonyfromundefined self-requested a review December 16, 2024 08:57
@tonyfromundefined
Copy link
Copy Markdown
Member

Hello @ysh4296! It's the end of the year and we're currently busy with other work, so the review is delayed. I think it will be possible early next year, so please keep that in mind.

orionmiz and others added 4 commits March 30, 2026 18:04
- Separate Sentry init from plugin (user inits Sentry, plugin handles navigation spans)
- Move @sentry/browser, @sentry/core, @stackflow/core to peerDependencies
- Replace internal WINDOW import with direct window check
- Remove unsafe integrations type cast
- Extract shared navigation span helper and add breadcrumb support
- Upgrade devDependencies to @sentry/browser@10, @sentry/core@10
- Fix version field typo (commas to dots)
- Update README with two-step setup guide

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…set to minor

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
stackflow-docs 3a116b3 Mar 30 2026, 10:08 AM

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d8795131-57de-42f9-a333-8e58d7297756

📥 Commits

Reviewing files that changed from the base of the PR and between 4d979ec and 2d09def.

📒 Files selected for processing (1)
  • .changeset/fix-plugin-sentry.md
✅ Files skipped from review due to trivial changes (1)
  • .changeset/fix-plugin-sentry.md

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a Sentry plugin that records automatic browser tracing for Stackflow navigation and step events, emitting navigation spans and breadcrumbs.
    • Added an integration helper to simplify Sentry initialization and decouple setup from the plugin.
    • Bumped the plugin to a new minor version.
  • Documentation

    • Added setup guide and usage instructions for the plugin and integration.

Walkthrough

Adds a new @stackflow/plugin-sentry package implementing a Sentry browser-tracing integration and a Stackflow plugin that emits navigation spans and breadcrumbs, plus package metadata, build config, TypeScript config, README, and Yarn PnP runtime entries.

Changes

Cohort / File(s) Summary
Plugin Implementation
extensions/plugin-sentry/src/index.ts, extensions/plugin-sentry/src/sentryPlugin.ts, extensions/plugin-sentry/src/integration.ts
Introduces sentryPlugin() (hooks into Stackflow lifecycle events to emit Sentry navigation spans and info-level breadcrumbs) and stackflowBrowserTracingIntegration() (wraps Sentry browserTracing, disables automatic navigation/page-load instrumentation, and starts an optional initial pageload span).
Package Configuration
extensions/plugin-sentry/package.json, extensions/plugin-sentry/esbuild.config.js, extensions/plugin-sentry/tsconfig.json
New package manifest with exports map, entrypoints, peer/dev deps, and build scripts; esbuild config emits CJS/ESM outputs and supports watch mode; tsconfig extends repo root and sets baseUrl/outDir.
Documentation & Changeset
extensions/plugin-sentry/README.md, .changeset/fix-plugin-sentry.md
Adds README with setup examples (initialize Sentry integration, add plugin to Stackflow) and a changeset recording a minor version bump for @stackflow/plugin-sentry.
Dependency Graph (Yarn PnP)
.pnp.cjs
Adds workspace entry for @stackflow/plugin-sentry and maps new pinned Sentry package entries (e.g., @sentry/browser, @sentry/core, internal packages) and dependency links into the serialized runtime state.

Sequence Diagram

sequenceDiagram
    participant App as App
    participant Stackflow as Stackflow Core
    participant Plugin as Sentry Plugin
    participant Sentry as Sentry Client
    participant Browser as Browser

    App->>Stackflow: navigation action (push/pop/replace / step events)
    Stackflow->>Plugin: emit lifecycle event (onPushed/onPopped/...)
    Plugin->>Sentry: start navigation span (name, attributes, params)
    Sentry->>Browser: record span
    Plugin->>Sentry: add breadcrumb (message, data)
    Sentry->>Browser: record breadcrumb
    Plugin->>Stackflow: plugin hook complete
    Stackflow->>App: navigation complete
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: adding a Sentry plugin to Stackflow, matching the primary objective of the PR.
Description check ✅ Passed The description comprehensively explains the plugin's purpose, functionality (page load and activity tracing), testing approach, usage example, and includes supporting screenshots demonstrating integration with Sentry's Performance and Session Replay features.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@orionmiz
Copy link
Copy Markdown
Collaborator

안녕하세요! 좋은 플러그인 감사합니다.

코드를 리뷰하면서 몇 가지 수정사항을 직접 반영했습니다:

구조 변경

  • Sentry 초기화 분리: 플러그인이 Sentry.init()을 직접 호출하지 않도록 변경했습니다. 사용자가 Sentry.init()을 직접 호출하고, stackflowBrowserTracingIntegration()을 integrations에 추가하는 방식으로 바꿨습니다.
  • dependency 구조 수정: @sentry/browser, @sentry/core, @stackflow/corepeerDependencies로 이동했습니다.

기능 추가

  • Breadcrumb 기록: 모든 navigation 이벤트에 Sentry.addBreadcrumb()를 추가해서 에러 발생 시 navigation 히스토리를 확인할 수 있게 했습니다.
  • Activity params 포함: span attributes와 breadcrumb data에 activity params를 포함하도록 했습니다.
  • Step navigation 트레이싱: onStepPushed, onStepPopped, onStepReplaced 훅을 추가했습니다.

기타

  • @sentry/types 제거 (v8에서 deprecated, @sentry/core에서 직접 import)
  • WINDOW 내부 API 제거, typeof window !== "undefined" 사용
  • version 오타 수정 (0,0,00.0.0)
  • Sentry 패키지 v10으로 업그레이드
  • navigation span 생성 로직을 헬퍼 함수로 추출

수정사항 확인 후 머지 진행하겠습니다!

Copy link
Copy Markdown

@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: 1

🧹 Nitpick comments (2)
extensions/plugin-sentry/README.md (1)

24-37: Consider adding a typed activity example.

The setup example shows the plugin integration but doesn't demonstrate TypeScript type safety for activities and their parameters. Adding a brief typed example would help users understand how to properly type their Stackflow activities:

📚 Suggested enhancement
 ```typescript
 import { stackflow } from "@stackflow/react";
 import { sentryPlugin } from "@stackflow/plugin-sentry";
 
+type Activities = {
+  HomePage: {};
+  ArticlePage: {
+    articleId: string;
+  };
+};
+
-const { Stack, useFlow } = stackflow({
+const { Stack, useFlow } = stackflow<Activities>({
   activities: {
-    // ...
+    HomePage: HomePage,
+    ArticlePage: ArticlePage,
   },
   plugins: [
     sentryPlugin(),
     // ... other plugins
   ],
 });
 ```

As per coding guidelines, TypeScript type safety should be provided for activities and their parameters using strict typing.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@extensions/plugin-sentry/README.md` around lines 24 - 37, The README example
for integrating sentryPlugin lacks a TypeScript-typed activities example; add a
concise typed snippet that declares an Activities type (e.g., type Activities =
{ HomePage: {}; ArticlePage: { articleId: string } }), then call stackflow with
the generic stackflow<Activities> and list the activities (HomePage,
ArticlePage) in the activities map so consumers see correct type safety for
useFlow/Stack and plugin usage (referencing sentryPlugin, stackflow, Stack,
useFlow, HomePage, ArticlePage, and Activities).
extensions/plugin-sentry/package.json (1)

30-30: Dev script won't run TypeScript watcher concurrently.

The && operator means build:dts --watch will only start after build:js --watch exits, but in watch mode it never exits. Consider using concurrently or similar to run both watchers in parallel.

Proposed fix using parallel execution
-    "dev": "yarn build:js --watch && yarn build:dts --watch"
+    "dev": "yarn build:js --watch & yarn build:dts --watch"

Or add a dependency on concurrently:

"dev": "concurrently \"yarn build:js --watch\" \"yarn build:dts --watch\""
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@extensions/plugin-sentry/package.json` at line 30, The "dev" npm script uses
&& which runs "build:dts --watch" only after "build:js --watch" exits (and watch
never exits), so the d.ts watcher never starts; update the "dev" script (the
"dev" entry in package.json) to run both watchers in parallel — e.g., use a tool
like concurrently to run "yarn build:js --watch" and "yarn build:dts --watch" at
the same time so both watchers (build:js and build:dts) start and stay active
concurrently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/fix-plugin-sentry.md:
- Line 5: Update the changeset message string "fix(plugin-sentry): decouple
Sentry init from plugin, fix dependency structure, remove internal API usage" to
accurately describe that this PR adds a new plugin package (e.g., use
"feat(plugin-sentry): add new Sentry plugin package" or similar), ensure the
changeset body mentions it's an addition rather than a fix, and keep any
dependency notes intact so release tooling will treat it as a new feature.

---

Nitpick comments:
In `@extensions/plugin-sentry/package.json`:
- Line 30: The "dev" npm script uses && which runs "build:dts --watch" only
after "build:js --watch" exits (and watch never exits), so the d.ts watcher
never starts; update the "dev" script (the "dev" entry in package.json) to run
both watchers in parallel — e.g., use a tool like concurrently to run "yarn
build:js --watch" and "yarn build:dts --watch" at the same time so both watchers
(build:js and build:dts) start and stay active concurrently.

In `@extensions/plugin-sentry/README.md`:
- Around line 24-37: The README example for integrating sentryPlugin lacks a
TypeScript-typed activities example; add a concise typed snippet that declares
an Activities type (e.g., type Activities = { HomePage: {}; ArticlePage: {
articleId: string } }), then call stackflow with the generic
stackflow<Activities> and list the activities (HomePage, ArticlePage) in the
activities map so consumers see correct type safety for useFlow/Stack and plugin
usage (referencing sentryPlugin, stackflow, Stack, useFlow, HomePage,
ArticlePage, and Activities).
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e7cb965f-2f38-434a-ab1f-a1db83953cba

📥 Commits

Reviewing files that changed from the base of the PR and between 2072658 and 3a116b3.

⛔ Files ignored due to path filters (7)
  • .yarn/cache/@sentry-browser-npm-10.46.0-91e2f4dcc5-f447c01f96.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/@sentry-core-npm-10.46.0-8ff3972576-bbe823f9de.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/@sentry-internal-browser-utils-npm-10.46.0-c2bfafc8a9-6ae7c6cc8d.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/@sentry-internal-feedback-npm-10.46.0-94a0d30ebb-e6c0b1fa93.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/@sentry-internal-replay-canvas-npm-10.46.0-e0dee1cb26-0ddfacfc79.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/@sentry-internal-replay-npm-10.46.0-21ab33d9b1-e7c3e9e880.zip is excluded by !**/.yarn/**, !**/*.zip
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (9)
  • .changeset/fix-plugin-sentry.md
  • .pnp.cjs
  • extensions/plugin-sentry/README.md
  • extensions/plugin-sentry/esbuild.config.js
  • extensions/plugin-sentry/package.json
  • extensions/plugin-sentry/src/index.ts
  • extensions/plugin-sentry/src/integration.ts
  • extensions/plugin-sentry/src/sentryPlugin.ts
  • extensions/plugin-sentry/tsconfig.json

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 30, 2026

  • @stackflow/demo

    yarn add https://pkg.pr.new/daangn/stackflow/@stackflow/plugin-sentry@547.tgz
    

commit: 2d09def

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@orionmiz orionmiz enabled auto-merge (squash) March 30, 2026 10:24
@orionmiz orionmiz merged commit 7ad3502 into daangn:main Mar 30, 2026
7 checks passed
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