Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat: ET rate limit settings (#57497)

Aleksander Błaszkiewiczc6d26c31593c
diff --git a/.semgrep/rules/idor-team-scoped-models.yaml b/.semgrep/rules/idor-team-scoped-models.yaml
index 264f121a82ed..78042b3ba0c4 100644
--- a/.semgrep/rules/idor-team-scoped-models.yaml
+++ b/.semgrep/rules/idor-team-scoped-models.yaml
@@ -105,6 +105,7 @@ rules:
|ErrorTrackingIssueFingerprintV2
|ErrorTrackingRelease
|ErrorTrackingRecommendation
+ |ErrorTrackingSettings
|ErrorTrackingSpikeDetectionConfig
|ErrorTrackingSpikeEvent
|ErrorTrackingStackFrame
@@ -310,6 +311,7 @@ rules:
|ErrorTrackingIssueFingerprintV2
|ErrorTrackingRelease
|ErrorTrackingRecommendation
+ |ErrorTrackingSettings
|ErrorTrackingSpikeDetectionConfig
|ErrorTrackingSpikeEvent
|ErrorTrackingStackFrame
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index e2c81ed3b8ba..bf57edd88977 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -5231,9 +5231,9 @@ snapshots:
scenes-app-settings-environment--settings-environment-error-tracking--light:
hash: v1.k794b7964.b4bf729d080caa78b6bb98d10580d77e217236e0fc6f00c43e72b1be7678b2f2.1_6VuVmWbHmWYusiDjuMTRx3rWlIDWehPi9H_BJD7qc
scenes-app-settings-environment--settings-environment-error-tracking-configuration--dark:
- hash: v1.k794b7964.eedc15309768d1a378b8a376d6464bc12d506849e75c4d593bff437a18c16f65.qWHmIy55qIj0qmq6DymM20ZeksshsAAO0R7HTGk3SJ4
+ hash: v1.k794b7964.beea6d68de5516c6c7e482ce88f065fd0a1b2fdffc50638df199acc38d73a77c.V8mH4gzfvHK9nMszJJUv4CsxPJsUSOeTYOWPr-P_xAQ
scenes-app-settings-environment--settings-environment-error-tracking-configuration--light:
- hash: v1.k794b7964.43bf3ce21388340b7ac5c6acc8f7dec23bfe66276a19ae78405cd5de833ff347.g0gFmLtLXj31-MPy5x6h0hIw4_MQ6Q4HTZomS4SUDy8
+ hash: v1.k794b7964.31cfe7a159eceba2b5b77a509be4bdb5aecfcd563f5ac026308a7821036cdfa5.G9Mf095SgmmZVmSzplDhCbnoqh5o7h5F7Cr1J__5XAs
scenes-app-settings-environment--settings-environment-feature-flags--dark:
hash: v1.k794b7964.8e1edff6d728b3343686536c5514b0eb48f25f16a76ea274ee257c5a5844922c.9yA1OXDgg_49YTBECuJG06dwayX_2b-asQIwVUCXGUQ
scenes-app-settings-environment--settings-environment-feature-flags--light:
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts
index 875f3d00ce9b..530752ca2f02 100644
--- a/frontend/src/lib/api.ts
+++ b/frontend/src/lib/api.ts
@@ -247,6 +247,7 @@ import { AlertSimulationResult, AlertType, AlertTypeWrite } from './components/A
import {
ErrorTrackingFingerprint,
ErrorTrackingRelease,
+ ErrorTrackingSettings,
ErrorTrackingSpikeDetectionConfig,
ErrorTrackingSpikeEvent,
ErrorTrackingStackFrame,
@@ -1325,6 +1326,10 @@ export class ApiRequest {
return this.errorTracking(teamId).addPathComponent('spike_detection_config')
}
+ public errorTrackingSettings(teamId?: TeamType['id']): ApiRequest {
+ return this.errorTracking(teamId).addPathComponent('settings')
+ }
+
public errorTrackingSpikeEvents(teamId?: TeamType['id']): ApiRequest {
return this.errorTracking(teamId).addPathComponent('spike_events')
}
@@ -4128,6 +4133,14 @@ const api = {
.update({ data })
},
+ async getSettings(): Promise<ErrorTrackingSettings> {
+ return await new ApiRequest().errorTrackingSettings().withAction('retrieve_settings').get()
+ },
+
+ async updateSettings(data: Partial<ErrorTrackingSettings>): Promise<ErrorTrackingSettings> {
+ return await new ApiRequest().errorTrackingSettings().withAction('update_settings').update({ data })
+ },
+
async getSpikeEvents(params?: {
issueIds?: string[]
limit?: number
diff --git a/frontend/src/lib/components/Errors/types.ts b/frontend/src/lib/components/Errors/types.ts
index c1353917ea76..0cf3d2fbf26f 100644
--- a/frontend/src/lib/components/Errors/types.ts
+++ b/frontend/src/lib/components/Errors/types.ts
@@ -155,6 +155,11 @@ export interface ErrorTrackingSpikeDetectionConfig {
threshold: number
}
+export interface ErrorTrackingSettings {
+ project_rate_limit_value: number | null
+ project_rate_limit_bucket_size_minutes: number | null
+}
+
export interface ErrorTrackingSpikeEventIssue {
id: string
name: string | null
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index b60c6e6948d1..d090126afec6 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -286,6 +286,7 @@ export const FEATURE_FLAGS = {
ERROR_TRACKING_JIRA_INTEGRATION: 'error-tracking-jira-integration', // owner: #team-error-tracking
ERROR_TRACKING_QUERY_V2: 'error-tracking-query-v2', // owner: #team-error-tracking
ERROR_TRACKING_QUERY_V3: 'error-tracking-query-v3', // owner: #team-error-tracking
+ ERROR_TRACKING_RATE_LIMITING: 'error-tracking-rate-limiting', // owner: @ablaszkiewicz #team-error-tracking
ERROR_TRACKING_RECOMMENDATIONS: 'error-tracking-recommendations', // owner: @ablaszkiewicz #team-error-tracking
ERROR_TRACKING_RELATED_ISSUES: 'error-tracking-related-issues', // owner: #team-error-tracking
ERROR_TRACKING_REVENUE_SORTING: 'error-tracking-revenue-sorting', // owner: @david #team-error-tracking
diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsx
index b11bd9cb6ea0..61906f322c24 100644
--- a/frontend/src/scenes/settings/SettingsMap.tsx
+++ b/frontend/src/scenes/settings/SettingsMap.tsx
@@ -2,6 +2,7 @@ import { LemonTag, Link, Tooltip } from '@posthog/lemon-ui'
import { ErrorTrackingAlerting } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/alerting/ErrorTrackingAlerting'
import { AssignmentRules } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/assignment_rules/AssignmentRules'
import { GroupingRules } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/grouping_rules/GroupingRules'
+import { RateLimitSettings } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSettings'
import { Releases } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/releases/Releases'
import { SpikeDetectionSettings } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/spike_detection/SpikeDetectionSettings'
import { SymbolSets } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/symbol_sets/SymbolSets'
@@ -509,6 +510,13 @@ export const SETTINGS_MAP: SettingSection[] = [
title: 'Spike detection',
component: <SpikeDetectionSettings />,
},
+ {
+ id: 'error-tracking-rate-limits',
+ title: 'Rate limits',
+ component: <RateLimitSettings />,
+ flag: 'ERROR_TRACKING_RATE_LIMITING',
+ keywords: ['rate', 'limit', 'throttle', 'ingestion', 'cap'],
+ },
{
id: 'error-tracking-auto-assignment',
title: 'Auto assignment rules',
diff --git a/frontend/src/scenes/settings/types.ts b/frontend/src/scenes/settings/types.ts
index e1ceca868f93..6d71445cbdf2 100644
--- a/frontend/src/scenes/settings/types.ts
+++ b/frontend/src/scenes/settings/types.ts
@@ -136,6 +136,7 @@ export type SettingId =
| 'error-tracking-integrations'
| 'error-tracking-auto-assignment'
| 'error-tracking-spike-detection'
+ | 'error-tracking-rate-limits'
| 'integration-webhooks'
| 'integration-slack'
| 'integration-posthog-code-slack'
diff --git a/posthog/api/__init__.py b/posthog/api/__init__.py
index 7a82f33ece93..c55661da5a63 100644
--- a/posthog/api/__init__.py
+++ b/posthog/api/__init__.py
@@ -65,6 +65,7 @@ from products.error_tracking.backend.api import (
ErrorTrackingIssueViewSet,
ErrorTrackingRecommendationViewSet,
ErrorTrackingReleaseViewSet,
+ ErrorTrackingSettingsViewSet,
ErrorTrackingSpikeDetectionConfigViewSet,
ErrorTrackingSpikeEventViewSet,
ErrorTrackingStackFrameViewSet,
@@ -1017,6 +1018,13 @@ environments_router.register(
["team_id"],
)
+environments_router.register(
+ r"error_tracking/settings",
+ ErrorTrackingSettingsViewSet,
+ "environment_error_tracking_settings",
+ ["team_id"],
+)
+
environments_router.register(
r"error_tracking/spike_events",
ErrorTrackingSpikeEventViewSet,
diff --git a/products/error_tracking/backend/api/__init__.py b/products/error_tracking/backend/api/__init__.py
index fa9c8cb25c33..0c01cc46af95 100644
--- a/products/error_tracking/backend/api/__init__.py
+++ b/products/error_tracking/backend/api/__init__.py
@@ -6,6 +6,7 @@ from .grouping_rules import ErrorTrackingGroupingRuleViewSet
from .issues import ErrorTrackingIssueViewSet
from .recommendations import ErrorTrackingRecommendationViewSet
from .releases import ErrorTrackingReleaseViewSet
+from .settings import ErrorTrackingSettingsViewSet
from .spike_detection_config import ErrorTrackingSpikeDetectionConfigViewSet
from .spike_events import ErrorTrackingSpikeEventViewSet
from .stack_frames import ErrorTrackingStackFrameViewSet
@@ -21,6 +22,7 @@ __all__ = [
"ErrorTrackingFingerprintViewSet",
"ErrorTrackingGroupingRuleViewSet",
"ErrorTrackingReleaseViewSet",
+ "ErrorTrackingSettingsViewSet",
"ErrorTrackingSpikeDetectionConfigViewSet",
"ErrorTrackingSpikeEventViewSet",
"ErrorTrackingSuppressionRuleViewSet",
diff --git a/products/error_tracking/backend/api/settings.py b/products/error_tracking/backend/api/settings.py
new file mode 100644
index 000000000000..c235ed450714
--- /dev/null
+++ b/products/error_tracking/backend/api/settings.py
@@ -0,0 +1,57 @@
+from drf_spectacular.utils import extend_schema
+from rest_framework import serializers, status, viewsets
+from rest_framework.decorators import action
+from rest_framework.response import Response
+
+from posthog.schema import ProductKey
+
+from posthog.api.routing import TeamAndOrgViewSetMixin
+
+from products.error_tracking.backend.models import ErrorTrackingSettings
+
+
+class ErrorTrackingSettingsSerializer(serializers.ModelSerializer):
+ project_rate_limit_value = serializers.IntegerField(
+ min_value=1,
+ allow_null=True,
+ required=False,
+ help_text="Maximum number of exception events ingested per bucket for the entire project. Null removes the limit.",
+ )
+ project_rate_limit_bucket_size_minutes = serializers.IntegerField(
+ min_value=1,
+ allow_null=True,
+ required=False,
+ help_text="Bucket window over which the project-wide rate limit applies, in minutes.",
+ )
+
+ class Meta:
+ model = ErrorTrackingSettings
+ fields = ["project_rate_limit_value", "project_rate_limit_bucket_size_minutes"]
+
+
+@extend_schema(tags=[ProductKey.ERROR_TRACKING])
+class ErrorTrackingSettingsViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
+ scope_object = "error_tracking"
+
+ def _get_or_create_settings(self) -> ErrorTrackingSettings:
+ settings, _ = ErrorTrackingSettings.objects.get_or_create(team=self.team)
+ return settings
+
+ @extend_schema(responses={200: ErrorTrackingSettingsSerializer})
+ @action(detail=False, methods=["get"])
+ def retrieve_settings(self, request, *args, **kwargs):
+ settings = self._get_or_create_settings()
+ serializer = ErrorTrackingSettingsSerializer(settings)
+ return Response(serializer.data)
+
+ @extend_schema(
+ request=ErrorTrackingSettingsSerializer,
+ responses={200: ErrorTrackingSettingsSerializer},
+ )
+ @action(detail=False, methods=["patch"])
+ def update_settings(self, request, *args, **kwargs):
+ settings = self._get_or_create_settings()
+ serializer = ErrorTrackingSettingsSerializer(settings, data=request.data, partial=True)
+ serializer.is_valid(raise_exception=True)
+ serializer.save()
+ return Response(serializer.data, status=status.HTTP_200_OK)
diff --git a/products/error_tracking/backend/migrations/0015_errortrackingsettings.py b/products/error_tracking/backend/migrations/0015_errortrackingsettings.py
new file mode 100644
index 000000000000..3e5860fb349b
--- /dev/null
+++ b/products/error_tracking/backend/migrations/0015_errortrackingsettings.py
@@ -0,0 +1,48 @@
+# Generated by Django 5.2.13 on 2026-05-05 06:52
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("error_tracking", "0014_recommendation"),
+ ("posthog", "1139_alter_datadeletionrequest_person_distinct_ids_and_more"),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="ErrorTrackingSettings",
+ fields=[
+ (
+ "team",
+ models.OneToOneField(
+ on_delete=django.db.models.deletion.CASCADE,
+ primary_key=True,
+ related_name="error_tracking_settings",
+ serialize=False,
+ to="posthog.team",
+ ),
+ ),
+ (
+ "project_rate_limit_value",
+ models.IntegerField(blank=True, null=True),
+ ),
+ (
+ "project_rate_limit_bucket_size_minutes",
+ models.IntegerField(blank=True, null=True),
+ ),
+ (
+ "per_issue_rate_limit_value",
+ models.IntegerField(blank=True, null=True),
+ ),
+ (
+ "per_issue_rate_limit_bucket_size_minutes",
+ models.IntegerField(blank=True, null=True),
+ ),
+ ],
+ options={
+ "db_table": "posthog_errortrackingsettings",
+ },
+ ),
+ ]
diff --git a/products/error_tracking/backend/migrations/max_migration.txt b/products/error_tracking/backend/migrations/max_migration.txt
index c5c58e019c04..b775fe0f35e7 100644
--- a/products/error_tracking/backend/migrations/max_migration.txt
+++ b/products/error_tracking/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0014_recommendation
+0015_errortrackingsettings
diff --git a/products/error_tracking/backend/models.py b/products/error_tracking/backend/models.py
index 56725a37e3df..e6535deabb94 100644
--- a/products/error_tracking/backend/models.py
+++ b/products/error_tracking/backend/models.py
@@ -578,6 +578,22 @@ class ErrorTrackingSpikeDetectionConfig(models.Model):
db_table = "posthog_errortrackingspikedetectionconfig"
+class ErrorTrackingSettings(models.Model):
+ team = models.OneToOneField(
+ "posthog.Team",
+ on_delete=models.CASCADE,
+ primary_key=True,
+ related_name="error_tracking_settings",
+ )
+ project_rate_limit_value = models.IntegerField(null=True, blank=True)
+ project_rate_limit_bucket_size_minutes = models.IntegerField(null=True, blank=True)
+ per_issue_rate_limit_value = models.IntegerField(null=True, blank=True)
+ per_issue_rate_limit_bucket_size_minutes = models.IntegerField(null=True, blank=True)
+
+ class Meta:
+ db_table = "posthog_errortrackingsettings"
+
+
class ErrorTrackingSpikeEvent(UUIDModel):
team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE)
issue = models.ForeignKey(ErrorTrackingIssue, on_delete=models.CASCADE, related_name="spike_events")
diff --git a/products/error_tracking/frontend/generated/api.schemas.ts b/products/error_tracking/frontend/generated/api.schemas.ts
index 2ec94bc35edd..93c1260e6a5b 100644
--- a/products/error_tracking/frontend/generated/api.schemas.ts
+++ b/products/error_tracking/frontend/generated/api.schemas.ts
@@ -827,6 +827,36 @@ export interface PaginatedErrorTrackingRecommendationListApi {
results: ErrorTrackingRecommendationApi[]
}
+export interface ErrorTrackingSettingsApi {
+ /**
+ * Maximum number of exception events ingested per bucket for the entire project. Null removes the limit.
+ * @minimum 1
+ * @nullable
+ */
+ project_rate_limit_value?: number | null
+ /**
+ * Bucket window over which the project-wide rate limit applies, in minutes.
+ * @minimum 1
+ * @nullable
+ */
+ project_rate_limit_bucket_size_minutes?: number | null
+}
+
+export interface PatchedErrorTrackingSettingsApi {
+ /**
+ * Maximum number of exception events ingested per bucket for the entire project. Null removes the limit.
+ * @minimum 1
+ * @nullable
+ */
+ project_rate_limit_value?: number | null
+ /**
+ * Bucket window over which the project-wide rate limit applies, in minutes.
+ * @minimum 1
+ * @nullable
+ */
+ project_rate_limit_bucket_size_minutes?: number | null
+}
+
export interface ErrorTrackingSpikeDetectionConfigApi {
/**
* Time to wait before alerting again for the same issue after a spike is detected.
diff --git a/products/error_tracking/frontend/generated/api.ts b/products/error_tracking/frontend/generated/api.ts
index 31e9b26b0a5a..f6d3b4751195 100644
--- a/products/error_tracking/frontend/generated/api.ts
+++ b/products/error_tracking/frontend/generated/api.ts
@@ -32,6 +32,7 @@ import type {
ErrorTrackingRecommendationsListParams,
ErrorTrackingReleaseApi,
ErrorTrackingReleasesListParams,
+ ErrorTrackingSettingsApi,
ErrorTrackingSpikeDetectionConfigApi,
ErrorTrackingSpikeEventsListParams,
ErrorTrackingStackFrameApi,
@@ -57,6 +58,7 @@ import type {
PatchedErrorTrackingGroupingRuleApi,
PatchedErrorTrackingIssueFullApi,
PatchedErrorTrackingReleaseApi,
+ PatchedErrorTrackingSettingsApi,
PatchedErrorTrackingSpikeDetectionConfigApi,
PatchedErrorTrackingSuppressionRuleApi,
PatchedErrorTrackingSymbolSetApi,
@@ -876,6 +878,37 @@ export const errorTrackingRecommendationsRestoreCreate = async (
})
}
+export const getErrorTrackingSettingsRetrieveSettingsRetrieveUrl = (projectId: string) => {
+ return `/api/environments/${projectId}/error_tracking/settings/retrieve_settings/`
+}
+
+export const errorTrackingSettingsRetrieveSettingsRetrieve = async (
+ projectId: string,
+ options?: RequestInit
+): Promise<ErrorTrackingSettingsApi> => {
+ return apiMutator<ErrorTrackingSettingsApi>(getErrorTrackingSettingsRetrieveSettingsRetrieveUrl(projectId), {
+ ...options,
+ method: 'GET',
+ })
+}
+
+export const getErrorTrackingSettingsUpdateSettingsPartialUpdateUrl = (projectId: string) => {
+ return `/api/environments/${projectId}/error_tracking/settings/update_settings/`
+}
+
+export const errorTrackingSettingsUpdateSettingsPartialUpdate = async (
+ projectId: string,
+ patchedErrorTrackingSettingsApi: PatchedErrorTrackingSettingsApi,
+ options?: RequestInit
+): Promise<ErrorTrackingSettingsApi> => {
+ return apiMutator<ErrorTrackingSettingsApi>(getErrorTrackingSettingsUpdateSettingsPartialUpdateUrl(projectId), {
+ ...options,
+ method: 'PATCH',
+ headers: { 'Content-Type': 'application/json', ...options?.headers },
+ body: JSON.stringify(patchedErrorTrackingSettingsApi),
+ })
+}
+
export const getErrorTrackingSpikeDetectionConfigListUrl = (projectId: string) => {
return `/api/environments/${projectId}/error_tracking/spike_detection_config/`
}
diff --git a/products/error_tracking/frontend/generated/api.zod.ts b/products/error_tracking/frontend/generated/api.zod.ts
index 96a60d811ce8..585201befcea 100644
--- a/products/error_tracking/frontend/generated/api.zod.ts
+++ b/products/error_tracking/frontend/generated/api.zod.ts
@@ -296,6 +296,21 @@ export const ErrorTrackingIssuesBulkCreateBody = /* @__PURE__ */ zod.object({
),
})
+export const ErrorTrackingSettingsUpdateSettingsPartialUpdateBody = /* @__PURE__ */ zod.object({
+ project_rate_limit_value: zod
+ .number()
+ .min(1)
+ .nullish()
+ .describe(
+ 'Maximum number of exception events ingested per bucket for the entire project. Null removes the limit.'
+ ),
+ project_rate_limit_bucket_size_minutes: zod
+ .number()
+ .min(1)
+ .nullish()
+ .describe('Bucket window over which the project-wide rate limit applies, in minutes.'),
+})
+
export const ErrorTrackingSpikeDetectionConfigUpdateConfigPartialUpdateBody = /* @__PURE__ */ zod.object({
snooze_duration_minutes: zod
.number()
diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSettings.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSettings.tsx
new file mode 100644
index 000000000000..fc65e33d7d1c
--- /dev/null
+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSettings.tsx
@@ -0,0 +1,220 @@
+import { useValues } from 'kea'
+import { Form } from 'kea-forms'
+import { useMemo } from 'react'
+
+import { LemonSelect } from '@posthog/lemon-ui'
+
+import { dayjs } from 'lib/dayjs'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { LemonField } from 'lib/lemon-ui/LemonField'
+import { LemonInput } from 'lib/lemon-ui/LemonInput'
+import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'
+import { pluralize } from 'lib/utils'
+
+import { LineGraph } from '~/queries/nodes/DataVisualization/Components/Charts/LineGraph'
+import { ChartDisplayType } from '~/types'
+
+import { BUCKET_OPTIONS, ExceptionVolumeBucket, getBucketOption, rateLimitConfigLogic } from './rateLimitConfigLogic'
+
+export function RateLimitSettings(): JSX.Element {
+ const {
+ configLoading,
+ configFormChanged,
+ isConfigFormSubmitting,
+ configForm,
+ volume,
+ volumeLoading,
+ volumeBucketMinutes,
+ } = useValues(rateLimitConfigLogic)
+
+ if (configLoading) {
+ return (
+ <div className="space-y-4">
+ <LemonSkeleton className="w-full h-10" />
+ <LemonSkeleton className="w-full h-64" />
+ </div>
+ )
+ }
+
+ return (
+ <div className="space-y-4">
+ <div>
+ <h3 className="font-semibold text-base mb-1">Project-wide rate limit</h3>
+ <p className="text-muted-foreground">
+ This limit applies across the entire project. Exceptions received above the configured rate are
+ dropped at ingestion.
+ </p>
+ </div>
+
+ <Form logic={rateLimitConfigLogic} formKey="configForm" enableFormOnSubmit>
+ <div className="grid grid-cols-1 md:grid-cols-10 gap-6">
+ <div className="md:col-span-3 space-y-3">
+ <LemonField name="project_rate_limit_value" label="Maximum exceptions">
+ {({ value, onChange }) => (
+ <LemonInput
+ type="number"
+ min={1}
+ value={value ?? undefined}
+ onChange={(v) => onChange(v ?? null)}
+ placeholder="Unlimited"
+ fullWidth
+ data-attr="rate-limit-value"
+ />
+ )}
+ </LemonField>
+
+ <LemonField name="project_rate_limit_bucket_size_minutes" label="Per">
+ {({ value, onChange }) => (
+ <LemonSelect
+ value={value}
+ onChange={onChange}
+ options={BUCKET_OPTIONS.map((o) => ({ label: o.label, value: o.minutes }))}
+ fullWidth
+ data-attr="rate-limit-bucket-size"
+ />
+ )}
+ </LemonField>
+
+ <p className="text-muted-foreground text-xs">
+ The maximum number of exceptions accepted per time window. Leave the value empty for no
+ limit.
+ </p>
+
+ <div className="flex justify-start pt-2">
+ <LemonButton
+ type="primary"
+ htmlType="submit"
+ disabledReason={!configFormChanged ? 'No changes to save' : undefined}
+ loading={isConfigFormSubmitting}
+ >
+ Save
+ </LemonButton>
+ </div>
+ </div>
+
+ <div className="md:col-span-7">
+ <div className="text-sm font-medium mb-1">
+ Exception volume — past {formatTotalDuration(volumeBucketMinutes)}
+ </div>
+ {volumeLoading ? (
+ <LemonSkeleton className="w-full h-80" />
+ ) : (
+ <RateLimitSimulationChart
+ volume={volume}
+ rateLimit={configForm.project_rate_limit_value}
+ bucketMinutes={volumeBucketMinutes}
+ />
+ )}
+ </div>
+ </div>
+ </Form>
+ </div>
+ )
+}
+
+function formatTotalDuration(bucketMinutes: number): string {
+ const option = getBucketOption(bucketMinutes)
+ const totalMinutes = option.minutes * option.bucketCount
+ if (totalMinutes >= 10080) {
+ return pluralize(Math.round(totalMinutes / 10080), 'week')
+ }
+ if (totalMinutes >= 1440) {
+ return pluralize(Math.round(totalMinutes / 1440), 'day')
+ }
+ return pluralize(Math.round(totalMinutes / 60), 'hour')
+}
+
+function fillBuckets(volume: ExceptionVolumeBucket[], bucketMinutes: number): ExceptionVolumeBucket[] {
+ const option = getBucketOption(bucketMinutes)
+ const bucketMs = option.minutes * 60_000
+ const counts = new Map<number, number>()
+ volume.forEach((b) => {
+ const aligned = Math.floor(dayjs(b.bucket).valueOf() / bucketMs) * bucketMs
+ counts.set(aligned, b.count)
+ })
+ const endMs = Math.floor(Date.now() / bucketMs) * bucketMs
+ const buckets: ExceptionVolumeBucket[] = []
+ for (let i = option.bucketCount - 1; i >= 0; i--) {
+ const ms = endMs - i * bucketMs
+ buckets.push({ bucket: dayjs(ms).toISOString(), count: counts.get(ms) ?? 0 })
+ }
+ return buckets
+}
+
+function formatBucketLabel(iso: string, bucketMinutes: number): string {
+ const ts = dayjs(iso)
+ if (bucketMinutes >= 1440) {
+ return ts.format('MMM D')
+ }
+ return ts.format('MMM D, HH:mm')
+}
+
+function RateLimitSimulationChart({
+ volume,
+ rateLimit,
+ bucketMinutes,
+}: {
+ volume: ExceptionVolumeBucket[]
+ rateLimit: number | null
+ bucketMinutes: number
+}): JSX.Element {
+ const { xData, yData } = useMemo(() => {
+ const filled = fillBuckets(volume, bucketMinutes)
+ const labels = filled.map((b) => formatBucketLabel(b.bucket, bucketMinutes))
+ const counts = filled.map((b) => b.count)
+ return {
+ xData: {
+ column: {
+ name: 'bucket',
+ type: { name: 'STRING' as const, isNumerical: false },
+ label: 'Bucket',
+ dataIndex: 0,
+ },
+ data: labels,
+ },
+ yData: [
+ {
+ column: {
+ name: 'count',
+ type: { name: 'INTEGER' as const, isNumerical: true },
+ label: 'Exceptions',
+ dataIndex: 0,
+ },
+ data: counts,
+ settings: {
+ display: {
+ displayType: 'bar' as const,
+ },
+ },
+ },
+ ],
+ }
+ }, [volume, bucketMinutes])
+
+ const goalLines = useMemo(() => {
+ if (!rateLimit || rateLimit <= 0) {
+ return []
+ }
+ const option = getBucketOption(bucketMinutes)
+ return [
+ {
+ label: `Limit: ${rateLimit} per ${option.label}`,
+ value: rateLimit,
+ displayLabel: true,
+ },
+ ]
+ }, [rateLimit, bucketMinutes])
+
+ return (
+ <div className="h-80 border rounded">
+ <LineGraph
+ className="h-full p-4"
+ xData={xData}
+ yData={yData}
+ visualizationType={ChartDisplayType.ActionsBar}
+ chartSettings={{ showXAxisTicks: false, showXAxisBorder: false }}
+ goalLines={goalLines}
+ />
+ </div>
+ )
+}
diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/rateLimitConfigLogic.ts b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/rateLimitConfigLogic.ts
new file mode 100644
index 000000000000..820373d4a9e6
--- /dev/null
+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/rateLimitConfigLogic.ts
@@ -0,0 +1,162 @@
+import { afterMount, kea, listeners, path, reducers } from 'kea'
+import { forms } from 'kea-forms'
+import { loaders } from 'kea-loaders'
+import posthog from 'posthog-js'
+
+import api from 'lib/api'
+import { ErrorTrackingSettings } from 'lib/components/Errors/types'
+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+
+import { HogQLQueryResponse, NodeKind, ProductKey } from '~/queries/schema/schema-general'
+
+import type { rateLimitConfigLogicType } from './rateLimitConfigLogicType'
+
+export interface RateLimitConfigForm {
+ project_rate_limit_value: number | null
+ project_rate_limit_bucket_size_minutes: number
+}
+
+export interface BucketOption {
+ label: string
+ minutes: number
+ bucketCount: number
+}
+
+export const BUCKET_OPTIONS: BucketOption[] = [
+ { label: '15 minutes', minutes: 15, bucketCount: 96 },
+ { label: '30 minutes', minutes: 30, bucketCount: 96 },
+ { label: '1 hour', minutes: 60, bucketCount: 168 },
+ { label: '1 day', minutes: 1440, bucketCount: 30 },
+ { label: '1 week', minutes: 10080, bucketCount: 12 },
+]
+
+export const DEFAULT_BUCKET_OPTION: BucketOption = BUCKET_OPTIONS.find((o) => o.minutes === 60) ?? BUCKET_OPTIONS[0]
+export const DEFAULT_BUCKET_MINUTES: number = DEFAULT_BUCKET_OPTION.minutes
+
+export function getBucketOption(minutes: number): BucketOption {
+ return BUCKET_OPTIONS.find((o) => o.minutes === minutes) ?? DEFAULT_BUCKET_OPTION
+}
+
+const DEFAULT_CONFIG: RateLimitConfigForm = {
+ project_rate_limit_value: null,
+ project_rate_limit_bucket_size_minutes: DEFAULT_BUCKET_MINUTES,
+}
+
+export interface ExceptionVolumeBucket {
+ bucket: string
+ count: number
+}
+
+export const rateLimitConfigLogic = kea<rateLimitConfigLogicType>([
+ path([
+ 'products',
+ 'error_tracking',
+ 'scenes',
+ 'ErrorTrackingConfigurationScene',
+ 'rate_limit',
+ 'rateLimitConfigLogic',
+ ]),
+
+ reducers({
+ hasLoadedConfig: [
+ false,
+ {
+ loadConfigSuccess: () => true,
+ },
+ ],
+ volumeBucketMinutes: [
+ DEFAULT_BUCKET_MINUTES,
+ {
+ loadVolumeSuccess: (state, { payload: requestedBucketMinutes }: { payload?: number }) =>
+ requestedBucketMinutes ?? state,
+ },
+ ],
+ }),
+
+ loaders({
+ config: [
+ null as ErrorTrackingSettings | null,
+ {
+ loadConfig: async () => {
+ return await api.errorTracking.getSettings()
+ },
+ },
+ ],
+ volume: [
+ [] as ExceptionVolumeBucket[],
+ {
+ loadVolume: async (bucketMinutes: number) => {
+ const option = getBucketOption(bucketMinutes)
+ const totalMinutes = option.minutes * option.bucketCount
+ const response = (await api.query({
+ kind: NodeKind.HogQLQuery,
+ query: `
+ SELECT
+ toStartOfInterval(timestamp, INTERVAL ${option.minutes} MINUTE) AS bucket,
+ count() AS count
+ FROM events
+ WHERE event = '$exception'
+ AND timestamp >= now() - INTERVAL ${totalMinutes} MINUTE
+ GROUP BY bucket
+ ORDER BY bucket
+ `,
+ tags: { productKey: ProductKey.ERROR_TRACKING },
+ })) as HogQLQueryResponse
+ return (response.results ?? []).map(([bucket, count]) => ({
+ bucket: String(bucket),
+ count: Number(count),
+ }))
+ },
+ },
+ ],
+ }),
+
+ forms(({ actions }) => ({
+ configForm: {
+ defaults: DEFAULT_CONFIG,
+ errors: ({ project_rate_limit_value }) => ({
+ project_rate_limit_value:
+ project_rate_limit_value !== null && project_rate_limit_value < 1
+ ? 'Rate limit must be at least 1'
+ : undefined,
+ }),
+ submit: async ({ project_rate_limit_value, project_rate_limit_bucket_size_minutes }) => {
+ try {
+ const payload = { project_rate_limit_value, project_rate_limit_bucket_size_minutes }
+ const updated = await api.errorTracking.updateSettings(payload)
+ actions.loadConfigSuccess(updated)
+ posthog.capture('error_tracking_settings_updated', payload)
+ lemonToast.success('Settings saved')
+ } catch (e) {
+ lemonToast.error('Failed to save settings')
+ throw e
+ }
+ },
+ },
+ })),
+
+ listeners(({ actions }) => ({
+ loadConfigSuccess: ({ config }) => {
+ const bucket = config?.project_rate_limit_bucket_size_minutes ?? DEFAULT_BUCKET_MINUTES
+ if (config) {
+ actions.resetConfigForm({
+ project_rate_limit_value: config.project_rate_limit_value,
+ project_rate_limit_bucket_size_minutes: bucket,
+ })
+ }
+ actions.loadVolume(bucket)
+ },
+ setConfigFormValue: ({ name, value }) => {
+ const fieldName = Array.isArray(name) ? name[name.length - 1] : name
+ if (fieldName === 'project_rate_limit_bucket_size_minutes' && typeof value === 'number') {
+ actions.loadVolume(value)
+ }
+ },
+ })),
+
+ afterMount(({ actions, values }) => {
+ if (!values.hasLoadedConfig) {
+ actions.loadConfig()
+ }
+ }),
+])
diff --git a/products/error_tracking/mcp/tools.yaml b/products/error_tracking/mcp/tools.yaml
index df2ae56b8a5c..f1c6d06cff1b 100644
--- a/products/error_tracking/mcp/tools.yaml
+++ b/products/error_tracking/mcp/tools.yaml
@@ -272,6 +272,12 @@ tools:
error-tracking-releases-update:
operation: error_tracking_releases_update
enabled: false
+ error-tracking-settings-retrieve-settings-retrieve:
+ operation: error_tracking_settings_retrieve_settings_retrieve
+ enabled: false
+ error-tracking-settings-update-settings-partial-update:
+ operation: error_tracking_settings_update_settings_partial_update
+ enabled: false
error-tracking-spike-detection-config-list:
operation: error_tracking_spike_detection_config_list
enabled: false
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 153b253d7218..06e727fd86dd 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -15548,6 +15548,21 @@ export namespace Schemas {
project: string;
}
+ export interface ErrorTrackingSettings {
+ /**
+ * Maximum number of exception events ingested per bucket for the entire project. Null removes the limit.
+ * @minimum 1
+ * @nullable
+ */
+ project_rate_limit_value?: number | null;
+ /**
+ * Bucket window over which the project-wide rate limit applies, in minutes.
+ * @minimum 1
+ * @nullable
+ */
+ project_rate_limit_bucket_size_minutes?: number | null;
+ }
+
export type ErrorTrackingSimilarIssuesQueryKind = typeof ErrorTrackingSimilarIssuesQueryKind[keyof typeof ErrorTrackingSimilarIssuesQueryKind];
@@ -27323,6 +27338,21 @@ export namespace Schemas {
project?: string;
}
+ export interface PatchedErrorTrackingSettings {
+ /**
+ * Maximum number of exception events ingested per bucket for the entire project. Null removes the limit.
+ * @minimum 1
+ * @nullable
+ */
+ project_rate_limit_value?: number | null;
+ /**
+ * Bucket window over which the project-wide rate limit applies, in minutes.
+ * @minimum 1
+ * @nullable
+ */
+ project_rate_limit_bucket_size_minutes?: number | null;
+ }
+
export interface PatchedErrorTrackingSpikeDetectionConfig {
/**
* Time to wait before alerting again for the same issue after a spike is detected.