-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nuxt): Add Cloudflare Nitro plugin #15597
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
911e298
feat(nuxt): Add Cloudflare Nitro plugin
s1gr1d 06f7a7c
sort imports
s1gr1d d5b7d81
import from core, not node
s1gr1d f11be16
better cloudflare plugin
s1gr1d 0800086
add some todo comments for trace propagation
s1gr1d efd33a4
Add continous tracing FR
s1gr1d f99497a
enable continuing from propagation context
s1gr1d 983752a
add tests
s1gr1d 761af2c
add todo
s1gr1d 55f1bd2
put option to requesthandler option
s1gr1d 95d162e
switch if statement
s1gr1d 5085e58
delete stuff
s1gr1d 3ccab0c
delete continueTraceFromPropagationContext
s1gr1d a86f1f0
reset code in cloudflare SDK
s1gr1d 56c1fc4
Merge branch 'develop' into sig/nuxt-cloudflare
s1gr1d e93abe2
fix type error
s1gr1d 5913937
delete `isDebug`
s1gr1d db78cd8
check for : in protocol
s1gr1d aa37922
Merge branch 'develop' into sig/nuxt-cloudflare
s1gr1d eac96b6
update yarn.lock
s1gr1d b9c9cc0
warn on double-init
s1gr1d a20ebef
Add WeakMap
s1gr1d 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
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
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
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
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
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,47 @@ | ||
import { captureException, getClient, getCurrentScope } from '@sentry/core'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { H3Error } from 'h3'; | ||
import type { CapturedErrorContext } from 'nitropack'; | ||
import { extractErrorContext, flushIfServerless } from '../utils'; | ||
|
||
/** | ||
* Hook that can be added in a Nitro plugin. It captures an error and sends it to Sentry. | ||
*/ | ||
export async function sentryCaptureErrorHook(error: Error, errorContext: CapturedErrorContext): Promise<void> { | ||
const sentryClient = getClient(); | ||
const sentryClientOptions = sentryClient?.getOptions(); | ||
|
||
if ( | ||
sentryClientOptions && | ||
'enableNitroErrorHandler' in sentryClientOptions && | ||
sentryClientOptions.enableNitroErrorHandler === false | ||
) { | ||
return; | ||
} | ||
|
||
// Do not handle 404 and 422 | ||
if (error instanceof H3Error) { | ||
// Do not report if status code is 3xx or 4xx | ||
if (error.statusCode >= 300 && error.statusCode < 500) { | ||
return; | ||
} | ||
} | ||
|
||
const { method, path } = { | ||
method: errorContext.event?._method ? errorContext.event._method : '', | ||
path: errorContext.event?._path ? errorContext.event._path : null, | ||
}; | ||
|
||
if (path) { | ||
getCurrentScope().setTransactionName(`${method} ${path}`); | ||
} | ||
|
||
const structuredContext = extractErrorContext(errorContext); | ||
|
||
captureException(error, { | ||
captureContext: { contexts: { nuxt: structuredContext } }, | ||
mechanism: { handled: false }, | ||
}); | ||
|
||
await flushIfServerless(); | ||
} |
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 @@ | ||
// fixme: Can this be exported like this? | ||
export { sentryCloudflareNitroPlugin } from './sentry-cloudflare.server'; |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
@AbhiPrasad
Is this a good place for adding the option? As it's only needed in the requestHandler, I added it only here and not in the general Cloudflare SDK options.Actually, I don't need this option because it would always take same trace ID from the Cloudflare environment which leads to multiple pageload spans within a trace as they all have the same trace ID in the meta tags.