Compare commits

...

2 Commits

Author SHA1 Message Date
Mathis HERRIOT
f7cd514997 chore: bump version to 1.10.2
All checks were successful
CI/CD Pipeline / Valider backend (push) Successful in 1m47s
CI/CD Pipeline / Valider frontend (push) Successful in 1m52s
CI/CD Pipeline / Valider documentation (push) Successful in 1m55s
CI/CD Pipeline / Déploiement en Production (push) Successful in 5m48s
2026-02-09 13:00:26 +01:00
Mathis HERRIOT
3a4f6624fc feat(health): add Sentry status check to health endpoint
- Integrated Sentry status check functionality in the health controller.
- Updated tests to validate Sentry active/disabled states.
- Improved Sentry initialization with enhanced logging and error handling.
2026-02-09 12:57:31 +01:00
6 changed files with 66 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@memegoat/backend",
"version": "1.10.1",
"version": "1.10.2",
"description": "",
"author": "",
"private": true,

View File

@@ -1,8 +1,13 @@
import { CACHE_MANAGER } from "@nestjs/cache-manager";
import { Test, TestingModule } from "@nestjs/testing";
import * as Sentry from "@sentry/nestjs";
import { DatabaseService } from "./database/database.service";
import { HealthController } from "./health.controller";
jest.mock("@sentry/nestjs", () => ({
getClient: jest.fn(),
}));
describe("HealthController", () => {
let controller: HealthController;
@@ -37,10 +42,15 @@ describe("HealthController", () => {
it("should return ok if database and redis are connected", async () => {
mockDb.execute.mockResolvedValue([]);
mockCacheManager.set.mockResolvedValue(undefined);
(Sentry.getClient as jest.Mock).mockReturnValue({
getOptions: () => ({ dsn: "http://dsn" }),
});
const result = await controller.check();
expect(result.status).toBe("ok");
expect(result.database).toBe("connected");
expect(result.redis).toBe("connected");
expect(result.sentry).toBe("active");
});
it("should return error if database is disconnected", async () => {
@@ -62,4 +72,19 @@ describe("HealthController", () => {
expect(result.redis).toBe("disconnected");
expect(result.redisError).toBe("Redis Error");
});
it("should return sentry disabled if client or dsn is missing", async () => {
mockDb.execute.mockResolvedValue([]);
mockCacheManager.set.mockResolvedValue(undefined);
(Sentry.getClient as jest.Mock).mockReturnValue(undefined);
const result = await controller.check();
expect(result.sentry).toBe("disabled");
(Sentry.getClient as jest.Mock).mockReturnValue({
getOptions: () => ({ dsn: undefined }),
});
const result2 = await controller.check();
expect(result2.sentry).toBe("disabled");
});
});

View File

@@ -1,5 +1,6 @@
import { CACHE_MANAGER } from "@nestjs/cache-manager";
import { Controller, Get, Inject } from "@nestjs/common";
import * as Sentry from "@sentry/nestjs";
import type { Cache } from "cache-manager";
import { sql } from "drizzle-orm";
import { DatabaseService } from "./database/database.service";
@@ -39,6 +40,14 @@ export class HealthController {
health.redisError = error.message;
}
// Check Sentry status
const sentryClient = Sentry.getClient();
if (sentryClient?.getOptions().dsn) {
health.sentry = "active";
} else {
health.sentry = "disabled";
}
return health;
}
}

View File

@@ -19,22 +19,35 @@ async function bootstrap() {
const sentryDsn = configService.get<string>("SENTRY_DSN");
if (sentryDsn) {
Sentry.init({
dsn: sentryDsn,
integrations: [nodeProfilingIntegration()],
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
sendDefaultPii: false, // RGPD
beforeSend(event) {
// Hachage de l'IP utilisateur pour Sentry si elle est présente
if (event.user?.ip_address) {
event.user.ip_address = createHash("sha256")
.update(event.user.ip_address)
.digest("hex");
}
return event;
},
});
try {
Sentry.init({
dsn: sentryDsn,
integrations: [Sentry.nestIntegration(), nodeProfilingIntegration()],
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
sendDefaultPii: false, // RGPD
beforeSend(event) {
// Hachage de l'IP utilisateur pour Sentry si elle est présente
if (event.user?.ip_address) {
event.user.ip_address = createHash("sha256")
.update(event.user.ip_address)
.digest("hex");
}
return event;
},
});
const client = Sentry.getClient();
if (client?.getOptions().dsn) {
logger.log("Sentry is initialized and connection is active");
} else {
logger.warn("Sentry initialized but DSN is missing");
}
} catch (error) {
logger.error(`Failed to initialize Sentry: ${error.message}`);
}
} else {
logger.warn("Sentry is disabled (SENTRY_DSN not configured)");
}
// Sécurité

View File

@@ -1,6 +1,6 @@
{
"name": "@memegoat/frontend",
"version": "1.10.1",
"version": "1.10.2",
"private": true,
"scripts": {
"dev": "next dev",

View File

@@ -1,6 +1,6 @@
{
"name": "@memegoat/source",
"version": "1.10.1",
"version": "1.10.2",
"description": "",
"scripts": {
"version:get": "cmake -P version.cmake GET",