root: make sentry sample rate configurable

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-11-29 13:52:34 +01:00
parent e597bb4542
commit e3a5ef1907
3 changed files with 43 additions and 21 deletions

View File

@ -5,7 +5,7 @@ from django.conf import settings
from django.db import models from django.db import models
from drf_spectacular.utils import extend_schema from drf_spectacular.utils import extend_schema
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
from rest_framework.fields import BooleanField, CharField, ChoiceField, IntegerField, ListField from rest_framework.fields import BooleanField, CharField, ChoiceField, FloatField, IntegerField, ListField
from rest_framework.permissions import AllowAny from rest_framework.permissions import AllowAny
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
@ -23,14 +23,20 @@ class Capabilities(models.TextChoices):
CAN_GEO_IP = "can_geo_ip" CAN_GEO_IP = "can_geo_ip"
CAN_BACKUP = "can_backup" CAN_BACKUP = "can_backup"
class ErrorReportingConfigSerializer(PassiveSerializer):
"""Config for error reporting"""
enabled = BooleanField(read_only=True)
environment = CharField(read_only=True)
send_pii = BooleanField(read_only=True)
traces_sample_rate=FloatField(read_only=True)
class ConfigSerializer(PassiveSerializer): class ConfigSerializer(PassiveSerializer):
"""Serialize authentik Config into DRF Object""" """Serialize authentik Config into DRF Object"""
error_reporting_enabled = BooleanField(read_only=True) error_reporting = ErrorReportingConfigSerializer(required=True)
error_reporting_environment = CharField(read_only=True)
error_reporting_send_pii = BooleanField(read_only=True)
capabilities = ListField(child=ChoiceField(choices=Capabilities.choices)) capabilities = ListField(child=ChoiceField(choices=Capabilities.choices))
cache_timeout = IntegerField(required=True) cache_timeout = IntegerField(required=True)
@ -66,9 +72,12 @@ class ConfigView(APIView):
"""Retrieve public configuration options""" """Retrieve public configuration options"""
config = ConfigSerializer( config = ConfigSerializer(
{ {
"error_reporting_enabled": CONFIG.y("error_reporting.enabled"), "error_reporting": {
"error_reporting_environment": CONFIG.y("error_reporting.environment"), "enabled": CONFIG.y("error_reporting.enabled"),
"error_reporting_send_pii": CONFIG.y("error_reporting.send_pii"), "environment": CONFIG.y("error_reporting.environment"),
"send_pii": CONFIG.y("error_reporting.send_pii"),
"traces_sample_rate": float(CONFIG.y("error_reporting.sample_rate", 0.4)),
},
"capabilities": self.get_capabilities(), "capabilities": self.get_capabilities(),
"cache_timeout": int(CONFIG.y("redis.cache_timeout")), "cache_timeout": int(CONFIG.y("redis.cache_timeout")),
"cache_timeout_flows": int(CONFIG.y("redis.cache_timeout_flows")), "cache_timeout_flows": int(CONFIG.y("redis.cache_timeout_flows")),

View File

@ -424,7 +424,7 @@ if _ERROR_REPORTING:
], ],
before_send=before_send, before_send=before_send,
release=f"authentik@{__version__}", release=f"authentik@{__version__}",
traces_sample_rate=0.6, traces_sample_rate=float(CONFIG.y("error_reporting.sample_rate", 0.4)),
environment=CONFIG.y("error_reporting.environment", "customer"), environment=CONFIG.y("error_reporting.environment", "customer"),
send_default_pii=CONFIG.y_bool("error_reporting.send_pii", False), send_default_pii=CONFIG.y_bool("error_reporting.send_pii", False),
) )

View File

@ -20206,15 +20206,8 @@ components:
type: object type: object
description: Serialize authentik Config into DRF Object description: Serialize authentik Config into DRF Object
properties: properties:
error_reporting_enabled: error_reporting:
type: boolean $ref: '#/components/schemas/ErrorReportingConfig'
readOnly: true
error_reporting_environment:
type: string
readOnly: true
error_reporting_send_pii:
type: boolean
readOnly: true
capabilities: capabilities:
type: array type: array
items: items:
@ -20233,9 +20226,7 @@ components:
- cache_timeout_policies - cache_timeout_policies
- cache_timeout_reputation - cache_timeout_reputation
- capabilities - capabilities
- error_reporting_enabled - error_reporting
- error_reporting_environment
- error_reporting_send_pii
ConsentChallenge: ConsentChallenge:
type: object type: object
description: Challenge info for consent screens description: Challenge info for consent screens
@ -20949,6 +20940,28 @@ components:
required: required:
- code - code
- string - string
ErrorReportingConfig:
type: object
description: Config for error reporting
properties:
enabled:
type: boolean
readOnly: true
environment:
type: string
readOnly: true
send_pii:
type: boolean
readOnly: true
traces_sample_rate:
type: number
format: float
readOnly: true
required:
- enabled
- environment
- send_pii
- traces_sample_rate
Event: Event:
type: object type: object
description: Event Serializer description: Event Serializer