feat(captcha): improve telemetry on captcha error (#12836)

This commit is contained in:
Antoine Moreaux
2025-06-24 17:43:03 +02:00
committed by GitHub
parent 3cef6c9048
commit b7e72c3aa6
4 changed files with 10 additions and 5 deletions

View File

@ -30,6 +30,7 @@ export class CaptchaGuard implements CanActivate {
await this.metricsService.incrementCounter({
key: MetricsKeys.InvalidCaptcha,
eventId: token || '',
...(result.error ? { attributes: { error: result.error } } : {}),
});
throw new BadRequestException(

View File

@ -32,7 +32,7 @@ export class GoogleRecaptchaDriver implements CaptchaDriver {
return {
success: responseData.success,
...(!responseData.success && {
error: responseData['error-codes']?.[0] ?? 'Captcha Error',
error: responseData['error-codes']?.[0] ?? 'unknown-error',
}),
};
}

View File

@ -32,7 +32,7 @@ export class TurnstileDriver implements CaptchaDriver {
return {
success: responseData.success,
...(!responseData.success && {
error: responseData['error-codes']?.[0] ?? 'Captcha Error',
error: responseData['error-codes']?.[0] ?? 'unknown-error',
}),
};
}

View File

@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { metrics } from '@opentelemetry/api';
import { metrics, Attributes } from '@opentelemetry/api';
import { MetricsCacheService } from 'src/engine/core-modules/metrics/metrics-cache.service';
import { MetricsKeys } from 'src/engine/core-modules/metrics/types/metrics-keys.type';
@ -12,17 +12,19 @@ export class MetricsService {
async incrementCounter({
key,
eventId,
attributes,
shouldStoreInCache = true,
}: {
key: MetricsKeys;
eventId?: string;
attributes?: Attributes;
shouldStoreInCache?: boolean;
}) {
//TODO : Define meter name usage in monitoring
const meter = metrics.getMeter('twenty-server');
const counter = meter.createCounter(key);
counter.add(1);
counter.add(1, attributes);
if (shouldStoreInCache && eventId) {
this.metricsCacheService.updateCounter(key, [eventId]);
@ -32,17 +34,19 @@ export class MetricsService {
async batchIncrementCounter({
key,
eventIds,
attributes,
shouldStoreInCache = true,
}: {
key: MetricsKeys;
eventIds: string[];
attributes?: Attributes;
shouldStoreInCache?: boolean;
}) {
//TODO : Define meter name usage in monitoring
const meter = metrics.getMeter('twenty-server');
const counter = meter.createCounter(key);
counter.add(eventIds.length);
counter.add(eventIds.length, attributes);
if (shouldStoreInCache) {
this.metricsCacheService.updateCounter(key, eventIds);