forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:redwoodjs/redwood into feat/make-vi…
…te-default * 'main' of github.com:redwoodjs/redwood: (23 commits) fix: remove react 17/18 warning (redwoodjs#8300) chore(release): tolerate lerna publish faliure Recover lost connection (redwoodjs#8284) chore(deps): update dependency @faker-js/faker to v8 (redwoodjs#8296) chore(release): better git commits during release feat: experimental - Studio Overview and Performance Widgets (redwoodjs#8292) fix(forms): disable webpack-dev-server overlay (redwoodjs#8298) Fix studio lint warning (redwoodjs#8297) Fastify server: Default to localhost (redwoodjs#8019) Fix GraphQL proxy in dev environments without IPv6 (redwoodjs#8233) fix(deps): update dependency @graphiql/plugin-explorer to v0.1.18 (redwoodjs#8290) chore(deps): update dependency supertokens-auth-react to v0.32.3 (redwoodjs#8289) Add `setup sentry` command (redwoodjs#7790) chore: readme update core team and all contributors (redwoodjs#8288) fix(deps): update nivo monorepo to ^0.83.0 (redwoodjs#8286) fix(deps): update dependency babel-plugin-polyfill-corejs3 to v0.8.1 (redwoodjs#8281) chore(deps): update dependency @replayio/playwright to v0.3.30 (redwoodjs#8282) fix(deps): update dependency webpack to v5.82.1 (redwoodjs#8283) Add epilogue to builders (redwoodjs#8285) feat(studio): v2 studio (redwoodjs#8173) ...
- Loading branch information
Showing
133 changed files
with
7,182 additions
and
2,666 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
28 changes: 16 additions & 12 deletions
28
packages/cli/src/commands/experimental/setupOpentelemetry.js
This file contains 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
This file contains 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,23 @@ | ||
import { getEpilogue } from './util' | ||
|
||
export const command = 'setup-sentry' | ||
|
||
export const description = 'Setup Sentry error and performance tracking' | ||
|
||
export const EXPERIMENTAL_TOPIC_ID = 4880 | ||
|
||
export const builder = (yargs) => { | ||
yargs | ||
.option('force', { | ||
alias: 'f', | ||
default: false, | ||
description: 'Overwrite existing sentry.js config files', | ||
type: 'boolean', | ||
}) | ||
.epilogue(getEpilogue(command, description, EXPERIMENTAL_TOPIC_ID, true)) | ||
} | ||
|
||
export const handler = async (options) => { | ||
const { handler } = await import('./setupSentryHandler') | ||
return handler(options) | ||
} |
200 changes: 200 additions & 0 deletions
200
packages/cli/src/commands/experimental/setupSentryHandler.js
This file contains 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,200 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
import { Listr } from 'listr2' | ||
|
||
import { | ||
addApiPackages, | ||
addEnvVarTask, | ||
addWebPackages, | ||
colors as c, | ||
getPaths, | ||
isTypeScriptProject, | ||
prettify, | ||
writeFilesTask, | ||
} from '@redwoodjs/cli-helpers' | ||
import { getConfigPath } from '@redwoodjs/project-config' | ||
import { errorTelemetry } from '@redwoodjs/telemetry' | ||
|
||
import { writeFile } from '../../lib' | ||
|
||
const PATHS = getPaths() | ||
|
||
export const handler = async ({ force }) => { | ||
const extension = isTypeScriptProject ? 'ts' : 'js' | ||
|
||
const notes = [] | ||
|
||
const tasks = new Listr([ | ||
addApiPackages([ | ||
'@envelop/sentry@5', | ||
'@sentry/node@7', | ||
'@sentry/tracing@7', | ||
]), | ||
addWebPackages(['@sentry/react@7', '@sentry/tracing@7']), | ||
addEnvVarTask( | ||
'SENTRY_DSN', | ||
'https://XXXXXXX@XXXXXXX.ingest.sentry.io/XXXXXXX', | ||
'https://docs.sentry.io/product/sentry-basics/dsn-explainer/' | ||
), | ||
{ | ||
title: 'Setting up Sentry on the API and web sides', | ||
task: () => | ||
writeFilesTask( | ||
{ | ||
[path.join(PATHS.api.lib, `sentry.${extension}`)]: fs | ||
.readFileSync( | ||
path.join(__dirname, 'templates/sentryApi.ts.template') | ||
) | ||
.toString(), | ||
[path.join(PATHS.web.src, 'lib', `sentry.${extension}`)]: fs | ||
.readFileSync( | ||
path.join(__dirname, 'templates/sentryWeb.ts.template') | ||
) | ||
.toString(), | ||
}, | ||
{ existingFiles: force ? 'OVERWRITE' : 'SKIP' } | ||
), | ||
}, | ||
{ | ||
title: 'Implementing the Envelop plugin', | ||
task: (ctx) => { | ||
const graphqlHandlerPath = path.join( | ||
PATHS.api.functions, | ||
`graphql.${extension}` | ||
) | ||
|
||
const contentLines = fs | ||
.readFileSync(graphqlHandlerPath) | ||
.toString() | ||
.split('\n') | ||
|
||
const handlerIndex = contentLines.findLastIndex((line) => | ||
/^export const handler = createGraphQLHandler\({/.test(line) | ||
) | ||
|
||
const pluginsIndex = contentLines.findLastIndex((line) => | ||
/extraPlugins:/.test(line) | ||
) | ||
|
||
if (handlerIndex === -1 || pluginsIndex !== -1) { | ||
ctx.addEnvelopPluginSkipped = true | ||
return | ||
} | ||
|
||
contentLines.splice( | ||
handlerIndex, | ||
1, | ||
"import 'src/lib/sentry'", | ||
'', | ||
'export const handler = createGraphQLHandler({', | ||
'extraPlugins: [useSentry({', | ||
'includeRawResult: true,', | ||
'includeResolverArgs: true,', | ||
'includeExecuteVariables: true,', | ||
'})],' | ||
) | ||
|
||
contentLines.splice(0, 0, "import { useSentry } from '@envelop/sentry'") | ||
|
||
fs.writeFileSync( | ||
graphqlHandlerPath, | ||
prettify('graphql.ts', contentLines.join('\n')) | ||
) | ||
}, | ||
}, | ||
{ | ||
title: "Replacing Redwood's Error boundary", | ||
task: () => { | ||
const contentLines = fs | ||
.readFileSync(PATHS.web.app) | ||
.toString() | ||
.split('\n') | ||
|
||
const webImportIndex = contentLines.findLastIndex((line) => | ||
/^import { FatalErrorBoundary, RedwoodProvider } from '@redwoodjs\/web'$/.test( | ||
line | ||
) | ||
) | ||
contentLines.splice( | ||
webImportIndex, | ||
1, | ||
"import { RedwoodProvider } from '@redwoodjs/web'" | ||
) | ||
|
||
const boundaryOpenIndex = contentLines.findLastIndex((line) => | ||
/<FatalErrorBoundary page={FatalErrorPage}>/.test(line) | ||
) | ||
contentLines.splice( | ||
boundaryOpenIndex, | ||
1, | ||
'<Sentry.ErrorBoundary fallback={FatalErrorPage}>' | ||
) | ||
|
||
const boundaryCloseIndex = contentLines.findLastIndex((line) => | ||
/<\/FatalErrorBoundary>/.test(line) | ||
) | ||
contentLines.splice(boundaryCloseIndex, 1, '</Sentry.ErrorBoundary>') | ||
|
||
contentLines.splice(0, 0, "import Sentry from 'src/lib/sentry'") | ||
|
||
fs.writeFileSync( | ||
PATHS.web.app, | ||
prettify('App.tsx', contentLines.join('\n')) | ||
) | ||
}, | ||
}, | ||
{ | ||
title: 'Adding config to redwood.toml...', | ||
task: (_ctx, task) => { | ||
const redwoodTomlPath = getConfigPath() | ||
const configContent = fs.readFileSync(redwoodTomlPath, 'utf-8') | ||
if (!configContent.includes('[experimental.sentry]')) { | ||
// Use string replace to preserve comments and formatting | ||
writeFile( | ||
redwoodTomlPath, | ||
configContent.concat(`\n[experimental.sentry]\n\tenabled = true\n`), | ||
{ | ||
overwriteExisting: true, // redwood.toml always exists | ||
} | ||
) | ||
} else { | ||
task.skip( | ||
`The [experimental.sentry] config block already exists in your 'redwood.toml' file.` | ||
) | ||
} | ||
}, | ||
}, | ||
{ | ||
title: 'One more thing...', | ||
task: (ctx) => { | ||
notes.push( | ||
c.green( | ||
'You will need to add `SENTRY_DSN` to `includeEnvironmentVariables` in redwood.toml.' | ||
) | ||
) | ||
|
||
if (ctx.addEnvelopPluginSkipped) { | ||
notes.push( | ||
`${c.underline( | ||
'Make sure you implement the Sentry Envelop plugin:' | ||
)} https://redwoodjs.com/docs/cli-commands#sentry-envelop-plugin` | ||
) | ||
} else { | ||
notes.push( | ||
"Check out RedwoodJS' docs for more: https://redwoodjs.com/docs/cli-commands#setup-sentry" | ||
) | ||
} | ||
}, | ||
}, | ||
]) | ||
|
||
try { | ||
await tasks.run() | ||
console.log(notes.join('\n')) | ||
} catch (e) { | ||
errorTelemetry(process.argv, e.message) | ||
console.error(c.error(e.message)) | ||
process.exit(e?.exitCode || 1) | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.