generated from openmcp-project/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
fix(sentry): sentry information now coming from bff #269
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
691c39d
fix(discussable): added unsafe eval to script src
n3rdc4ptn 590bf4b
fix: moved sentry information to bff supplied at runtime
n3rdc4ptn df48941
chore(deps): remove ts-node dependency from package.json
n3rdc4ptn dce8606
Merge branch 'main' into sentry-fix
n3rdc4ptn 04f4adc
fix(helmet): remove 'unsafe-eval' from script-src directives
n3rdc4ptn 7cb0fb2
refactor(sentry): moved sentry into separate file and added proper er…
n3rdc4ptn 6da469f
fix(sentry): update environment variable for Sentry initialization
n3rdc4ptn 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ | |
<script type="module" src="/src/mount.ts"></script> | ||
</body> | ||
|
||
</html> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,65 @@ | ||
import * as Sentry from '@sentry/react'; | ||
import React from 'react'; | ||
import { Routes, useLocation, useNavigationType, createRoutesFromChildren, matchRoutes } from 'react-router-dom'; | ||
|
||
// Define proper typing for Sentry configuration | ||
interface SentryConfig { | ||
FRONTEND_SENTRY_DSN: string; | ||
FRONTEND_SENTRY_ENVIRONMENT: string; | ||
} | ||
|
||
// Validate sentryConfig format | ||
function isValidSentryConfig(config: unknown): config is SentryConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 👍 |
||
if (typeof config !== 'object' || config === null) { | ||
return false; | ||
} | ||
|
||
const typedConfig = config as Record<string, unknown>; | ||
return ( | ||
typeof typedConfig.FRONTEND_SENTRY_DSN === 'string' && | ||
typedConfig.FRONTEND_SENTRY_DSN.length > 0 && | ||
typeof typedConfig.FRONTEND_SENTRY_ENVIRONMENT === 'string' && | ||
typedConfig.FRONTEND_SENTRY_ENVIRONMENT.length > 0 | ||
); | ||
} | ||
|
||
// Fetch Sentry configuration from server | ||
async function fetchSentryConfig(): Promise<unknown> { | ||
try { | ||
const response = await fetch('/sentry'); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
return await response.json(); | ||
} catch (error) { | ||
console.warn('Failed to fetch Sentry configuration:', error); | ||
return null; | ||
} | ||
} | ||
|
||
// Initialize Sentry and return the wrapped Routes component | ||
export async function initializeSentry(): Promise<typeof Routes> { | ||
const sentryConfig = await fetchSentryConfig(); | ||
|
||
if (!isValidSentryConfig(sentryConfig)) { | ||
console.warn('Invalid or missing Sentry configuration, continuing without Sentry integration'); | ||
return Routes; | ||
} | ||
|
||
// Initialize Sentry with valid configuration | ||
Sentry.init({ | ||
dsn: sentryConfig.FRONTEND_SENTRY_DSN, | ||
environment: sentryConfig.FRONTEND_SENTRY_ENVIRONMENT, | ||
integrations: [ | ||
Sentry.reactRouterV7BrowserTracingIntegration({ | ||
useEffect: React.useEffect, | ||
useLocation, | ||
useNavigationType, | ||
createRoutesFromChildren, | ||
matchRoutes, | ||
}), | ||
], | ||
}); | ||
|
||
return Sentry.withSentryReactRouterV7Routing(Routes); | ||
} |
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,29 +1,11 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import { createApp } from './main.tsx'; | ||
import * as Sentry from '@sentry/react'; | ||
import React from 'react'; | ||
import { Routes, useLocation, useNavigationType, createRoutesFromChildren, matchRoutes } from 'react-router-dom'; | ||
import { initializeSentry } from './lib/sentry.ts'; | ||
|
||
let sentryRoutes = Routes; | ||
if (import.meta.env.VITE_SENTRY_DSN && import.meta.env.VITE_SENTRY_DSN.length > 0) { | ||
Sentry.init({ | ||
dsn: import.meta.env.VITE_SENTRY_DSN, | ||
environment: import.meta.env.VITE_SENTRY_ENVIRONMENT, | ||
integrations: [ | ||
Sentry.reactRouterV7BrowserTracingIntegration({ | ||
useEffect: React.useEffect, | ||
useLocation, | ||
useNavigationType, | ||
createRoutesFromChildren, | ||
matchRoutes, | ||
}), | ||
], | ||
}); | ||
// Initialize Sentry and get the Routes component (with or without Sentry integration) | ||
const SentryRoutes = await initializeSentry(); | ||
|
||
sentryRoutes = Sentry.withSentryReactRouterV7Routing(Routes); | ||
} | ||
|
||
export const SentryRoutes = sentryRoutes; | ||
export { SentryRoutes }; | ||
|
||
const root = createRoot(document.getElementById('root')!); | ||
root.render(createApp()); |
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.
Uh oh!
There was an error while loading. Please reload this page.