fix(health): send healthcheck result to sentry to improve debugging

This commit is contained in:
Julian Tölle 2022-06-11 14:02:48 +02:00
parent d1a5eb57d7
commit dbf4374aeb

View file

@ -1,12 +1,13 @@
import { Controller, Get } from "@nestjs/common"; import { Controller, Get } from "@nestjs/common";
import { ConfigService } from "@nestjs/config"; import { ConfigService } from "@nestjs/config";
import { import {
HttpHealthIndicator,
HealthCheck, HealthCheck,
HealthCheckResult, HealthCheckResult,
HealthCheckService, HealthCheckService,
HttpHealthIndicator,
TypeOrmHealthIndicator, TypeOrmHealthIndicator,
} from "@nestjs/terminus"; } from "@nestjs/terminus";
import { configureScope, Scope } from "@sentry/node";
@Controller("api/v1/health") @Controller("api/v1/health")
export class HealthCheckController { export class HealthCheckController {
@ -19,8 +20,8 @@ export class HealthCheckController {
@Get() @Get()
@HealthCheck() @HealthCheck()
check(): Promise<HealthCheckResult> { async check(): Promise<HealthCheckResult> {
return this.health.check([ const health = await this.health.check([
() => () =>
this.http.pingCheck( this.http.pingCheck(
"spotify-web", "spotify-web",
@ -33,5 +34,11 @@ export class HealthCheckController {
), ),
() => this.typeorm.pingCheck("db"), () => this.typeorm.pingCheck("db"),
]); ]);
configureScope((scope: Scope) => {
scope.setExtra("health", health);
});
return health;
} }
} }