feat(captcha): improve telemetry on captcha error (#12836)
This commit is contained in:
@ -30,6 +30,7 @@ export class CaptchaGuard implements CanActivate {
|
|||||||
await this.metricsService.incrementCounter({
|
await this.metricsService.incrementCounter({
|
||||||
key: MetricsKeys.InvalidCaptcha,
|
key: MetricsKeys.InvalidCaptcha,
|
||||||
eventId: token || '',
|
eventId: token || '',
|
||||||
|
...(result.error ? { attributes: { error: result.error } } : {}),
|
||||||
});
|
});
|
||||||
|
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
|
|||||||
@ -32,7 +32,7 @@ export class GoogleRecaptchaDriver implements CaptchaDriver {
|
|||||||
return {
|
return {
|
||||||
success: responseData.success,
|
success: responseData.success,
|
||||||
...(!responseData.success && {
|
...(!responseData.success && {
|
||||||
error: responseData['error-codes']?.[0] ?? 'Captcha Error',
|
error: responseData['error-codes']?.[0] ?? 'unknown-error',
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ export class TurnstileDriver implements CaptchaDriver {
|
|||||||
return {
|
return {
|
||||||
success: responseData.success,
|
success: responseData.success,
|
||||||
...(!responseData.success && {
|
...(!responseData.success && {
|
||||||
error: responseData['error-codes']?.[0] ?? 'Captcha Error',
|
error: responseData['error-codes']?.[0] ?? 'unknown-error',
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
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 { MetricsCacheService } from 'src/engine/core-modules/metrics/metrics-cache.service';
|
||||||
import { MetricsKeys } from 'src/engine/core-modules/metrics/types/metrics-keys.type';
|
import { MetricsKeys } from 'src/engine/core-modules/metrics/types/metrics-keys.type';
|
||||||
@ -12,17 +12,19 @@ export class MetricsService {
|
|||||||
async incrementCounter({
|
async incrementCounter({
|
||||||
key,
|
key,
|
||||||
eventId,
|
eventId,
|
||||||
|
attributes,
|
||||||
shouldStoreInCache = true,
|
shouldStoreInCache = true,
|
||||||
}: {
|
}: {
|
||||||
key: MetricsKeys;
|
key: MetricsKeys;
|
||||||
eventId?: string;
|
eventId?: string;
|
||||||
|
attributes?: Attributes;
|
||||||
shouldStoreInCache?: boolean;
|
shouldStoreInCache?: boolean;
|
||||||
}) {
|
}) {
|
||||||
//TODO : Define meter name usage in monitoring
|
//TODO : Define meter name usage in monitoring
|
||||||
const meter = metrics.getMeter('twenty-server');
|
const meter = metrics.getMeter('twenty-server');
|
||||||
const counter = meter.createCounter(key);
|
const counter = meter.createCounter(key);
|
||||||
|
|
||||||
counter.add(1);
|
counter.add(1, attributes);
|
||||||
|
|
||||||
if (shouldStoreInCache && eventId) {
|
if (shouldStoreInCache && eventId) {
|
||||||
this.metricsCacheService.updateCounter(key, [eventId]);
|
this.metricsCacheService.updateCounter(key, [eventId]);
|
||||||
@ -32,17 +34,19 @@ export class MetricsService {
|
|||||||
async batchIncrementCounter({
|
async batchIncrementCounter({
|
||||||
key,
|
key,
|
||||||
eventIds,
|
eventIds,
|
||||||
|
attributes,
|
||||||
shouldStoreInCache = true,
|
shouldStoreInCache = true,
|
||||||
}: {
|
}: {
|
||||||
key: MetricsKeys;
|
key: MetricsKeys;
|
||||||
eventIds: string[];
|
eventIds: string[];
|
||||||
|
attributes?: Attributes;
|
||||||
shouldStoreInCache?: boolean;
|
shouldStoreInCache?: boolean;
|
||||||
}) {
|
}) {
|
||||||
//TODO : Define meter name usage in monitoring
|
//TODO : Define meter name usage in monitoring
|
||||||
const meter = metrics.getMeter('twenty-server');
|
const meter = metrics.getMeter('twenty-server');
|
||||||
const counter = meter.createCounter(key);
|
const counter = meter.createCounter(key);
|
||||||
|
|
||||||
counter.add(eventIds.length);
|
counter.add(eventIds.length, attributes);
|
||||||
|
|
||||||
if (shouldStoreInCache) {
|
if (shouldStoreInCache) {
|
||||||
this.metricsCacheService.updateCounter(key, eventIds);
|
this.metricsCacheService.updateCounter(key, eventIds);
|
||||||
|
|||||||
Reference in New Issue
Block a user