Skip to content

Commit

Permalink
fix(test): forcing cli build to test isolating sentry, temporarily up…
Browse files Browse the repository at this point in the history
…dating tests
  • Loading branch information
ryan-cahill committed Oct 18, 2023
1 parent 50a881e commit 629de76
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class SentryService {
}

private async ignoreTryCatch(fn: () => Promise<void>, debug_message: string) {
console.log('****SENTRY IGNORE TRY CATCH');
try {
await fn();
} catch {
Expand All @@ -31,12 +32,13 @@ export default class SentryService {
}

initSentry(): void {
console.log('****INIT SENTRY');
this.ignoreTryCatch(async () => {
Sentry.init({
enabled: process.env.TEST !== '1' && process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== ENVIRONMENT.PREVIEW,
enabled: true, // TODO: restore: process.env.TEST !== '1' && process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== ENVIRONMENT.PREVIEW,
dsn: CLI_SENTRY_DSN,
debug: true, // TODO: restore: false
environment: process.env?.NODE_ENV ?? 'production',
environment: 'staging', // TODO: restore process.env?.NODE_ENV ?? 'production',
release: process.env?.npm_package_version,
tracesSampleRate: 1.0,
attachStacktrace: true,
Expand All @@ -52,12 +54,14 @@ export default class SentryService {
...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
],
beforeSend(event: any) {
console.log('****SENTRY BEFORE SEND');
if (event.req?.data?.token) {
event.req.data.token = '*'.repeat(20);
}
return event;
},
beforeBreadcrumb(breadcrumb: any) {
console.log('****SENTRY BEFORE BREADCRUMB');
if (breadcrumb.category === 'console') {
breadcrumb.message = PromptUtils.stripAsciiColorCodes(breadcrumb.message);
}
Expand All @@ -68,6 +72,7 @@ export default class SentryService {
}

private async getUser(): Promise<User | undefined> {
console.log('****SENTRY GET USER');
try {
const user = await this.command.app.checkLogin();
if (user) {
Expand All @@ -79,6 +84,7 @@ export default class SentryService {
}

async startSentryTransaction(): Promise<void> {
console.log('****START SENTRY TRANSACTION');
this.ignoreTryCatch(async () => {
this.file_out = this.command.app.config.environment !== ENVIRONMENT.TEST && this.command.app.config.environment !== ENVIRONMENT.PREVIEW;
this.sentry_history_file_path = path.join(this.command.app.config?.getConfigDir(), LocalPaths.SENTRY_FILENAME);
Expand Down Expand Up @@ -144,6 +150,7 @@ export default class SentryService {
}

async updateSentryTransaction(error?: any): Promise<void> {
console.log('****UPDATE SENTRY TRANSACTION');
try {
// Only query for docker containers if there is an error to improve performance of cmds
const updated_docker_info = error ? await this.getRunningDockerContainers() : [];
Expand All @@ -153,7 +160,7 @@ export default class SentryService {
error.stack = PromptUtils.stripAsciiColorCodes(error.stack);
}

const sentry_session_metadata = await {
const sentry_session_metadata = {
docker_info: updated_docker_info,
linked_components: this.command.app.linkedComponents,
command: this.command.constructor.name,
Expand Down Expand Up @@ -187,6 +194,7 @@ export default class SentryService {
}

async endSentryTransaction(error?: any): Promise<void> {
console.log('****END SENTRY TRANSACTION');
await this.ignoreTryCatch(async () => {
if (this.command.app.config.environment === ENVIRONMENT.TEST) {
Sentry.close(0);
Expand Down

0 comments on commit 629de76

Please sign in to comment.