-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Sentry Monitoring (and break API routes) (#5)
* feat: Deploy media reference app with Skylark deployment * feat: Add Sentry * refactor: enable Sentry on production and test deployments * refactor: add Sentry to pr app build * fix: Add useServerlessTraceTarget to fix Sentry build
- Loading branch information
1 parent
c810e40
commit bfd1df3
Showing
27 changed files
with
464 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,8 @@ yarn-error.log* | |
# typescript | ||
*.tsbuildinfo | ||
|
||
# Storybook | ||
build-storybook.log | ||
|
||
# Sentry | ||
.sentryclirc |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as Sentry from "@sentry/nextjs"; | ||
import NextErrorComponent, { ErrorProps as NextErrorProps } from "next/error"; | ||
import { NextPageContext } from "next"; | ||
|
||
type ErrorPageProps = { | ||
err: Error; | ||
statusCode: number; | ||
isReadyToRender: boolean; | ||
children?: React.ReactElement; | ||
}; | ||
|
||
type ErrorProps = { | ||
isReadyToRender: boolean; | ||
} & NextErrorProps; | ||
|
||
const ErrorPage = (props: ErrorPageProps): JSX.Element => { | ||
const { statusCode, isReadyToRender, err, children = null } = props; | ||
|
||
if (!isReadyToRender && err) { | ||
Sentry.captureException(err); | ||
} | ||
|
||
return <>{children ?? <NextErrorComponent statusCode={statusCode} />}</>; | ||
}; | ||
|
||
ErrorPage.getInitialProps = async ( | ||
props: NextPageContext | ||
): Promise<ErrorProps> => { | ||
const { res, err, asPath } = props; | ||
|
||
const errorInitialProps: ErrorProps = | ||
(await NextErrorComponent.getInitialProps({ | ||
res, | ||
err, | ||
} as NextPageContext)) as ErrorProps; | ||
|
||
errorInitialProps.isReadyToRender = true; | ||
|
||
if (res?.statusCode === 404) { | ||
return { statusCode: 404, isReadyToRender: true }; | ||
} | ||
|
||
if (err) { | ||
Sentry.captureException(err); | ||
await Sentry.flush(2000); | ||
return errorInitialProps; | ||
} | ||
|
||
Sentry.captureException( | ||
new Error( | ||
`_error.js getInitialProps missing data at path: ${asPath as string}` | ||
) | ||
); | ||
await Sentry.flush(2000); | ||
|
||
return errorInitialProps; | ||
}; | ||
|
||
export default ErrorPage; |
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,10 @@ | ||
// This file configures the initialization of Sentry on the browser. | ||
// The config you add here will be used whenever a page is visited. | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
||
import * as Sentry from "@sentry/nextjs"; | ||
import { getSentryOptions } from "@skylark-reference-apps/lib"; | ||
|
||
Sentry.init({ | ||
...getSentryOptions({}), | ||
}); |
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,3 @@ | ||
defaults.url=https://sentry.io/ | ||
defaults.org=ostmodern | ||
defaults.project=skylark-reference-apps |
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,10 @@ | ||
// This file configures the initialization of Sentry on the server. | ||
// The config you add here will be used whenever the server handles a request. | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
||
import * as Sentry from "@sentry/nextjs"; | ||
import { getSentryOptions } from "@skylark-reference-apps/lib"; | ||
|
||
Sentry.init({ | ||
...getSentryOptions({}), | ||
}); |
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./cognito/index"; | ||
export * from "./cognito"; | ||
export * from "./sentry"; |
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 @@ | ||
export * from "./sentry.config"; |
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,31 @@ | ||
import { NodeOptions } from "@sentry/nextjs"; | ||
|
||
type NextjsOptions = NodeOptions; | ||
|
||
interface SentryOpts { | ||
dsn?: string; | ||
environment?: string; | ||
} | ||
|
||
const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN; | ||
const NODE_ENV = process.env.NODE_ENV || process.env.NEXT_PUBLIC_NODE_ENV; | ||
|
||
// DSN from https://sentry.io/settings/ostmodern/projects/skylark-reference-apps/keys/ | ||
const defaultDSN = | ||
"https://[email protected]/6323940"; | ||
|
||
export const getSentryOptions = ({ | ||
dsn, | ||
environment, | ||
}: SentryOpts): NextjsOptions => ({ | ||
dsn: dsn || SENTRY_DSN || defaultDSN, | ||
environment: environment || NODE_ENV, | ||
// Disable when "next dev" is run | ||
enabled: environment !== "development", | ||
// Adjust this value in production, or use tracesSampler for greater control | ||
tracesSampleRate: 1.0, | ||
// ... | ||
// Note: if you want to override the automatic release value, do not set a | ||
// `release` value here - use the environment variable `SENTRY_RELEASE`, so | ||
// that it will also get attached to your source maps | ||
}); |
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.