-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(astro): Parametrize routes on client-side #17133
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 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ea536c9
feat(astro): Parametrize routes on client-side
s1gr1d 04ddbdd
fix regex (non-greedy)
s1gr1d 74164df
encode URI
s1gr1d 0eeadf3
Merge branch 'develop' into sig/astro-client-param
s1gr1d 8fcfe9b
revert some stuff
s1gr1d 43fdebb
review suggestions
s1gr1d e8655bb
Merge branch 'develop' into sig/astro-client-param
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,41 @@ | ||
import { browserTracingIntegration as originalBrowserTracingIntegration, WINDOW } from '@sentry/browser'; | ||
import type { Integration, TransactionSource } from '@sentry/core'; | ||
import { debug, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; | ||
import { DEBUG_BUILD } from '../debug-build'; | ||
|
||
/** | ||
* Returns the value of a meta-tag | ||
*/ | ||
function getMetaContent(metaName: string): string | undefined { | ||
const optionalDocument = WINDOW.document as (typeof WINDOW)['document'] | undefined; | ||
const metaTag = optionalDocument?.querySelector(`meta[name=${metaName}]`); | ||
return metaTag?.getAttribute('content') || undefined; | ||
} | ||
|
||
/** | ||
* A custom browser tracing integrations for Astro. | ||
*/ | ||
export function browserTracingIntegration( | ||
options: Parameters<typeof originalBrowserTracingIntegration>[0] = {}, | ||
): Integration { | ||
const integration = originalBrowserTracingIntegration(options); | ||
|
||
return { | ||
...integration, | ||
setup(client) { | ||
// Original integration setup call | ||
integration.setup?.(client); | ||
|
||
client.on('afterStartPageLoadSpan', pageLoadSpan => { | ||
const routeNameFromMetaTags = getMetaContent('sentry-route-name'); | ||
|
||
if (routeNameFromMetaTags) { | ||
DEBUG_BUILD && debug.log(`[Tracing] Using route name from Sentry HTML meta-tag: ${routeNameFromMetaTags}`); | ||
|
||
pageLoadSpan.updateName(routeNameFromMetaTags); | ||
pageLoadSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route' as TransactionSource); | ||
} | ||
}); | ||
}, | ||
}; | ||
} |
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,8 @@ | ||
declare const __DEBUG_BUILD__: boolean; | ||
|
||
/** | ||
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code. | ||
* | ||
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking. | ||
*/ | ||
export const DEBUG_BUILD = __DEBUG_BUILD__; |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export * from '@sentry/browser'; | ||
|
||
// Override the browserTracingIntegration with the custom Astro version | ||
export { browserTracingIntegration } from './client/browserTracingIntegration'; | ||
|
||
export { init } from './client/sdk'; |
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
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.
We could also update the
sentry.origin
here to reflect that this is coming from the custom browser instrumentation.