set up metrics collecting with open telemetry (#11236)

Done :  
- move metrics and health cache services from health module to metrics
module
- refactor metrics counter from specific method to set up from enum keys
- add OpenTelemetry (Otel) instrumentation for metrics
- set up Otel SDK to send metrics to Otel collector

To do later : 
- implement Otel instrumentation for traces + plug Sentry on top
This commit is contained in:
Etienne
2025-03-28 08:45:24 +01:00
committed by GitHub
parent e9e33c4d29
commit 391392dd87
32 changed files with 575 additions and 297 deletions

View File

@ -7,13 +7,14 @@ import {
import { GqlExecutionContext } from '@nestjs/graphql';
import { CaptchaService } from 'src/engine/core-modules/captcha/captcha.service';
import { HealthCacheService } from 'src/engine/core-modules/health/health-cache.service';
import { MetricsService } from 'src/engine/core-modules/metrics/metrics.service';
import { MetricsKeys } from 'src/engine/core-modules/metrics/types/metrics-keys.type';
@Injectable()
export class CaptchaGuard implements CanActivate {
constructor(
private captchaService: CaptchaService,
private healthCacheService: HealthCacheService,
private metricsService: MetricsService,
) {}
async canActivate(context: ExecutionContext): Promise<boolean> {
@ -26,7 +27,10 @@ export class CaptchaGuard implements CanActivate {
if (result.success) {
return true;
} else {
await this.healthCacheService.updateInvalidCaptchaCache(token);
await this.metricsService.incrementCounter({
key: MetricsKeys.InvalidCaptcha,
eventId: token,
});
throw new BadRequestException(
'Invalid Captcha, please try another device',