-
Notifications
You must be signed in to change notification settings - Fork 471
feat: add sentry config #745
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
06051b8
feat: integrate Sentry for error tracking and reporting in TrueFoundry
thesujai 8f99d18
refactor: simplify Sentry authentication data fetching in TrueFoundry
thesujai d001b7a
feat: enhance Sentry integration for improved error reporting and cus…
thesujai 5a6f2ba
refactor: remove Sentry error capturing from TrueFoundryServiceFoundr…
thesujai 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@truefoundry/trueforge": patch | ||
| --- | ||
|
|
||
| Add Sentry for critical-flow error reporting (TrueFoundry auth-server or SENTRY_DSN init) with configurable additional tags. |
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
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,16 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
|
|
||
| export function captureCriticalException( | ||
| err: unknown, | ||
| options?: { tags?: Record<string, string>; extra?: Record<string, unknown> }, | ||
| ): void { | ||
| Sentry.withScope(scope => { | ||
| if (options?.tags) { | ||
| scope.setTags(options.tags); | ||
| } | ||
| if (options?.extra) { | ||
| scope.setExtras(options.extra); | ||
| } | ||
| Sentry.captureException(err); | ||
| }); | ||
| } |
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 @@ | ||
| export { captureCriticalException } from './captureCriticalException'; | ||
| export { initSentry, type InitSentryOptions } from './initSentry'; | ||
|
thesujai marked this conversation as resolved.
|
||
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,58 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import type { Logger } from 'winston'; | ||
|
|
||
| import { isTrueFoundryModeEnabled, type ServerConfiguration } from '../config'; | ||
| import { PACKAGE_VERSION } from '../packageVersion'; | ||
| import { initTrueFoundrySentry } from '../truefoundry/initTrueFoundrySentry'; | ||
|
|
||
| function isLocalLikeEnv(nodeEnv: string | undefined): boolean { | ||
| return nodeEnv === 'development' || nodeEnv === 'test' || nodeEnv === 'local'; | ||
| } | ||
|
|
||
| function applyGlobalTags(tags: Record<string, string>): void { | ||
| const scope = Sentry.getGlobalScope(); | ||
| for (const [key, value] of Object.entries(tags)) { | ||
| scope.setTag(key, value); | ||
| } | ||
| } | ||
|
|
||
| export interface InitSentryOptions { | ||
| tags?: Record<string, string>; | ||
| } | ||
|
|
||
| export async function initSentry( | ||
| config: ServerConfiguration, | ||
| logger: Pick<Logger, 'info' | 'error'>, | ||
| options?: InitSentryOptions, | ||
| ): Promise<void> { | ||
| if (!config.SENTRY_ENABLED || isLocalLikeEnv(config.NODE_ENV)) { | ||
| logger.info('Sentry is not enabled (SENTRY_ENABLED=false or local-like NODE_ENV)'); | ||
| return; | ||
| } | ||
|
|
||
| const globalTags: Record<string, string> = { | ||
| service: 'trueforge', | ||
| TRUEFORGE_VERSION: PACKAGE_VERSION, | ||
| ...config.SENTRY_ADDITIONAL_TAGS, | ||
| ...options?.tags, | ||
| }; | ||
|
|
||
| if (isTrueFoundryModeEnabled(config)) { | ||
| await initTrueFoundrySentry({ logger, tags: globalTags }); | ||
| return; | ||
| } | ||
|
|
||
| const dsn = config.SENTRY_DSN; | ||
| if (dsn === undefined || dsn.trim() === '') { | ||
| logger.error('SENTRY_DSN is required when SENTRY_ENABLED=true'); | ||
| return; | ||
| } | ||
| Sentry.init({ | ||
| dsn, | ||
| includeLocalVariables: false, | ||
| defaultIntegrations: false, | ||
| integrations: [], | ||
| }); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| applyGlobalTags(globalTags); | ||
| logger.info('Sentry initialised'); | ||
| } | ||
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.
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.