-
Notifications
You must be signed in to change notification settings - Fork 114
feat(plugin-sentry): add plugin for sentry #689
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
721a9f3
init package
ysh4296 af94ba2
add pageload & activity navigation logging
ysh4296 4ce0582
sentry init with props
ysh4296 85a6b76
update manager files
ysh4296 a7368bc
feat: add sample readme & format code
ysh4296 1d27914
update manager files
ysh4296 436ed73
Merge branch 'main' into feature/plugin-sentry
ysh4296 17c9a32
fix(plugin-sentry): improve plugin structure and upgrade sentry
orionmiz 563a8a7
feat(plugin-sentry): include activity params in spans and breadcrumbs
orionmiz 04686f5
feat(plugin-sentry): add step navigation tracing
orionmiz 3a116b3
chore(plugin-sentry): update README with step navigation, bump change…
orionmiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@stackflow/plugin-sentry": minor | ||
| --- | ||
|
|
||
| fix(plugin-sentry): decouple Sentry init from plugin, fix dependency structure, remove internal API usage |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+401 KB
.yarn/cache/@sentry-internal-browser-utils-npm-10.46.0-c2bfafc8a9-6ae7c6cc8d.zip
Binary file not shown.
Binary file added
BIN
+175 KB
.yarn/cache/@sentry-internal-feedback-npm-10.46.0-94a0d30ebb-e6c0b1fa93.zip
Binary file not shown.
Binary file added
BIN
+173 KB
.yarn/cache/@sentry-internal-replay-canvas-npm-10.46.0-e0dee1cb26-0ddfacfc79.zip
Binary file not shown.
Binary file added
BIN
+662 KB
.yarn/cache/@sentry-internal-replay-npm-10.46.0-21ab33d9b1-e7c3e9e880.zip
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # plugin-sentry | ||
|
|
||
| Stackflow plugin for Sentry browser tracing. Automatically creates navigation spans and breadcrumbs for activity transitions (`push`, `pop`, `replace`) and step transitions (`stepPush`, `stepPop`, `stepReplace`). | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Initialize Sentry with the `stackflowBrowserTracingIntegration`: | ||
|
|
||
| ```typescript | ||
| import * as Sentry from "@sentry/browser"; | ||
| import { stackflowBrowserTracingIntegration } from "@stackflow/plugin-sentry"; | ||
|
|
||
| Sentry.init({ | ||
| dsn: "https://xxx.ingest.us.sentry.io/xxx", | ||
| integrations: [ | ||
| stackflowBrowserTracingIntegration(), | ||
| // ... other integrations | ||
| ], | ||
| }); | ||
| ``` | ||
|
|
||
| 2. Add `sentryPlugin()` to your stackflow configuration: | ||
|
|
||
| ```typescript | ||
| import { stackflow } from "@stackflow/react"; | ||
| import { sentryPlugin } from "@stackflow/plugin-sentry"; | ||
|
|
||
| const { Stack, useFlow } = stackflow({ | ||
| activities: { | ||
| // ... | ||
| }, | ||
| plugins: [ | ||
| sentryPlugin(), | ||
| // ... other plugins | ||
| ], | ||
| }); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| const { context } = require("esbuild"); | ||
| const config = require("@stackflow/esbuild-config"); | ||
| const pkg = require("./package.json"); | ||
|
|
||
| const watch = process.argv.includes("--watch"); | ||
| const external = Object.keys({ | ||
| ...pkg.dependencies, | ||
| ...pkg.peerDependencies, | ||
| }); | ||
|
|
||
| Promise.all([ | ||
| context({ | ||
| ...config({}), | ||
| format: "cjs", | ||
| external, | ||
| }).then((ctx) => | ||
| watch ? ctx.watch() : ctx.rebuild().then(() => ctx.dispose()), | ||
| ), | ||
| context({ | ||
| ...config({}), | ||
| format: "esm", | ||
| outExtension: { | ||
| ".js": ".mjs", | ||
| }, | ||
| external, | ||
| }).then((ctx) => | ||
| watch ? ctx.watch() : ctx.rebuild().then(() => ctx.dispose()), | ||
| ), | ||
| ]).catch(() => process.exit(1)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "name": "@stackflow/plugin-sentry", | ||
| "version": "0.0.0", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/daangn/stackflow.git", | ||
| "directory": "extensions/plugin-sentry" | ||
| }, | ||
| "license": "MIT", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "require": "./dist/index.js", | ||
| "import": "./dist/index.mjs" | ||
| } | ||
| }, | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.mjs", | ||
| "types": "./dist/index.d.ts", | ||
| "files": [ | ||
| "dist", | ||
| "src", | ||
| "README.md" | ||
| ], | ||
| "scripts": { | ||
| "build": "yarn build:js && yarn build:dts", | ||
| "build:dts": "tsc --emitDeclarationOnly", | ||
| "build:js": "node ./esbuild.config.js", | ||
| "clean": "rimraf dist", | ||
| "dev": "yarn build:js --watch && yarn build:dts --watch" | ||
| }, | ||
| "peerDependencies": { | ||
| "@sentry/browser": ">=8.0.0", | ||
| "@sentry/core": ">=8.0.0", | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "@stackflow/core": "^1.1.0-canary.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@sentry/browser": "^10.46.0", | ||
| "@sentry/core": "^10.46.0", | ||
| "@stackflow/core": "^1.1.0", | ||
| "@stackflow/esbuild-config": "^1.0.3", | ||
| "esbuild": "^0.23.0", | ||
| "typescript": "^5.5.3" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { sentryPlugin } from "./sentryPlugin"; | ||
| export { stackflowBrowserTracingIntegration } from "./integration"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { | ||
| browserTracingIntegration as originalBrowserTracingIntegration, | ||
| startBrowserTracingPageLoadSpan, | ||
| } from "@sentry/browser"; | ||
| import { | ||
| SEMANTIC_ATTRIBUTE_SENTRY_OP, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, | ||
| } from "@sentry/core"; | ||
|
|
||
| export function stackflowBrowserTracingIntegration( | ||
| options: Parameters<typeof originalBrowserTracingIntegration>[0] = {}, | ||
| ) { | ||
| const browserTracingIntegrationInstance = originalBrowserTracingIntegration({ | ||
| ...options, | ||
| instrumentNavigation: false, | ||
| instrumentPageLoad: false, | ||
| }); | ||
| const { instrumentPageLoad = true } = options; | ||
|
|
||
| return { | ||
| ...browserTracingIntegrationInstance, | ||
| afterAllSetup( | ||
| client: Parameters<typeof browserTracingIntegrationInstance.afterAllSetup>[0], | ||
| ) { | ||
| browserTracingIntegrationInstance.afterAllSetup(client); | ||
|
|
||
| const initialWindowLocation = | ||
| typeof window !== "undefined" ? window.location : undefined; | ||
|
|
||
| if (instrumentPageLoad && initialWindowLocation) { | ||
| startBrowserTracingPageLoadSpan(client, { | ||
| name: initialWindowLocation.pathname, | ||
| attributes: { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "pageload", | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.pageload.stackflow", | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url", | ||
| }, | ||
| }); | ||
| } | ||
| }, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import * as Sentry from "@sentry/browser"; | ||
| import { | ||
| SEMANTIC_ATTRIBUTE_SENTRY_OP, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, | ||
| } from "@sentry/core"; | ||
| import type { StackflowPlugin } from "@stackflow/core"; | ||
|
|
||
| type NavigationAction = | ||
| | "push" | ||
| | "pop" | ||
| | "replace" | ||
| | "stepPush" | ||
| | "stepPop" | ||
| | "stepReplace"; | ||
|
|
||
| function startNavigationSpan( | ||
| action: NavigationAction, | ||
| activityName: string, | ||
| params: Record<string, string | undefined>, | ||
| ): void { | ||
| const client = Sentry.getClient(); | ||
| if (!client) return; | ||
|
|
||
| Sentry.startBrowserTracingNavigationSpan(client, { | ||
| name: `${action} ${activityName}`, | ||
| attributes: { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation", | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.stackflow", | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route", | ||
| "stackflow.action": action, | ||
| "stackflow.activity": activityName, | ||
| ...prefixKeys("stackflow.params", params), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| function addNavigationBreadcrumb( | ||
| action: NavigationAction, | ||
| activityName: string, | ||
| params: Record<string, string | undefined>, | ||
| ): void { | ||
| Sentry.addBreadcrumb({ | ||
| category: "navigation", | ||
| message: `${action} ${activityName}`, | ||
| level: "info", | ||
| data: params, | ||
| }); | ||
| } | ||
|
|
||
| function prefixKeys( | ||
| prefix: string, | ||
| params: Record<string, string | undefined>, | ||
| ): Record<string, string> { | ||
| const result: Record<string, string> = {}; | ||
| for (const [key, value] of Object.entries(params)) { | ||
| if (value !== undefined) { | ||
| result[`${prefix}.${key}`] = value; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| export function sentryPlugin(): StackflowPlugin { | ||
| return () => ({ | ||
| key: "plugin-sentry", | ||
| onPushed({ effect }) { | ||
| const { name, params } = effect.activity; | ||
| startNavigationSpan("push", name, params); | ||
| addNavigationBreadcrumb("push", name, params); | ||
| }, | ||
| onPopped({ effect }) { | ||
| const { name, params } = effect.activity; | ||
| startNavigationSpan("pop", name, params); | ||
| addNavigationBreadcrumb("pop", name, params); | ||
| }, | ||
| onReplaced({ effect }) { | ||
| const { name, params } = effect.activity; | ||
| startNavigationSpan("replace", name, params); | ||
| addNavigationBreadcrumb("replace", name, params); | ||
| }, | ||
| onStepPushed({ effect }) { | ||
| const { name, params } = effect.activity; | ||
| const stepParams = effect.step.params; | ||
| startNavigationSpan("stepPush", name, { ...params, ...stepParams }); | ||
| addNavigationBreadcrumb("stepPush", name, { ...params, ...stepParams }); | ||
| }, | ||
| onStepPopped({ effect }) { | ||
| const { name, params } = effect.activity; | ||
| startNavigationSpan("stepPop", name, params); | ||
| addNavigationBreadcrumb("stepPop", name, params); | ||
| }, | ||
| onStepReplaced({ effect }) { | ||
| const { name, params } = effect.activity; | ||
| const stepParams = effect.step.params; | ||
| startNavigationSpan("stepReplace", name, { ...params, ...stepParams }); | ||
| addNavigationBreadcrumb("stepReplace", name, { | ||
| ...params, | ||
| ...stepParams, | ||
| }); | ||
| }, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "baseUrl": "./src", | ||
| "outDir": "./dist" | ||
| }, | ||
| "exclude": ["./dist"] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
devscript won’t run both watchers.yarn build:js --watchis long-running, soyarn build:dts --watchnever starts with&&.🔧 Proposed fix
"devDependencies": { + "concurrently": "^9.0.0", "@sentry/browser": "^10.46.0", "@sentry/core": "^10.46.0",🤖 Prompt for AI Agents