Skip to content

Commit

Permalink
refactor(repeater): send errors to sentry (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsndr authored Oct 4, 2023
1 parent 298e85f commit 3723bad
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 44 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ jobs:

- name: Build package
run: npm run build

env:
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}

- name: Pack artifacts
run: npm pack

Expand Down
179 changes: 145 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@neuralegion/capture-har": "^0.3.4",
"@neuralegion/os-service": "^1.2.2",
"@neuralegion/raw-socket": "^1.8.2",
"@sentry/node": "^7.70.0",
"ajv": "^6.12.6",
"amqplib": "~0.10.2",
"arch": "^2.2.0",
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/RunRepeater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,15 @@ export class RunRepeater implements CommandModule {
['SIGTERM', 'SIGINT', 'SIGHUP'].forEach((event) =>
process.on(event, async () => {
await repeaterLauncher.close();
process.exit(0);
process.exitCode = 0;
})
);

await repeaterLauncher.run(args.id as string, args.run as boolean);
} catch (e) {
logger.error(e.message);
logger.error(e);
await repeaterLauncher.close();
process.exit(1);
process.exitCode = 1;
}
}
}
16 changes: 15 additions & 1 deletion src/Config/CliBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CliConfig, ConfigReader } from './ConfigReader';
import { ClusterArgs, Helpers, logger, LogLevel } from '../Utils';
import { CliInfo } from './CliInfo';
import { Arguments, Argv, CommandModule } from 'yargs';
import { runWithAsyncContext, setContext } from '@sentry/node';

export interface CliBuilderOptions {
info: CliInfo;
Expand Down Expand Up @@ -85,7 +86,20 @@ export class CliBuilder {
);

return commands
.reduce((acc: Argv, item: CommandModule) => acc.command(item), cli)
.reduce((acc: Argv, item: CommandModule) => {
const handler = item.handler.bind(item);

item.handler = (args) =>
runWithAsyncContext(() => {
setContext('args', args);

handler(args);
});

acc.command(item);

return acc;
}, cli)
.recommendCommands()
.demandCommand(1)
.strict(true)
Expand Down
2 changes: 1 addition & 1 deletion src/Repeater/DefaultRepeaterLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class DefaultRepeaterLauncher implements RepeaterLauncher {
@inject(delay(() => CliInfo)) private readonly info: CliInfo
) {
this.bus.onReconnectionFailure(async (e: Error) => {
logger.error(e.message);
logger.error(e);
await this.close();
process.exit(1);
});
Expand Down
2 changes: 1 addition & 1 deletion src/Repeater/DefaultRepeaterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class DefaultRepeaterServer implements RepeaterServer {
payload,
error
);
logger.error('Error: %s', error.message);
logger.error(error);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Repeater/ServerRepeaterLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class ServerRepeaterLauncher implements RepeaterLauncher {
}

private reconnectionFailed({ error }: RepeaterServerReconnectionFailedEvent) {
logger.error(error.message);
logger.error(error);
this.close().catch(logger.error);
process.exit(1);
}
Expand Down
Loading

0 comments on commit 3723bad

Please sign in to comment.