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(ingestion): explain active event ingestion restrictions in the app banner (#89762)

Nick Best74e32e7cfa29
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index d34db2dacdfc..aaa6c290ebc1 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -3152,6 +3152,18 @@ snapshots:
hash: v1.k794b7964.8147d6d169af167868bdf292f919e40073423ae49dffcc468831f34eef2fd020.EITCH6oreQApfcBumW0XPJ2jZ_mGiajcs4QgpusFQ0A
layout-nav-bar-installation-status--local-session-active--light:
hash: v1.k794b7964.3862c2f44a83857e0b8723b7239b046f57fdfd567c0077480f353c351c9b321a.dlSfwZqhbIYc_dvTH75ZoyYJMihnh_iAkr8hcOw1t14
+ layout-navigation-eventingestionrestrictiondetails--many-distinct-ids--dark:
+ hash: v1.k794b7964.64258ae40e87b4714ca4f8163d4cd1394e5912dcda695ee9b71328d5761795dc.cbMF-F4sSUCnWr_xL0FmJ0Zex8wuDgdVSgavOhsqFaM
+ layout-navigation-eventingestionrestrictiondetails--many-distinct-ids--light:
+ hash: v1.k794b7964.e57191edb722c733c5ca66da244bcc4e69561c697bd6362c76b2d2170ce0132d.JR2JHdEirCpgYUJIT3RsOctlscTg-T-iSpmu2I7mERw
+ layout-navigation-eventingestionrestrictiondetails--scoped-to-distinct-ids--dark:
+ hash: v1.k794b7964.44608b94f2282f6c5ae9da37b140fe58860a4c172594d0ef6a5045d044d8b870.gNIzqZZYcoWT1OKlCh2dKpIcSym6-levf5tHDnGX_YE
+ layout-navigation-eventingestionrestrictiondetails--scoped-to-distinct-ids--light:
+ hash: v1.k794b7964.52631c02f4230e802ab998dd453ea248c0f8528f991aa84a6e9d25a68201b7b5.yHlmiUQi6BhAIa0zfcffFRipF23RxdCt-8YqvdUqzWs
+ layout-navigation-eventingestionrestrictiondetails--whole-project--dark:
+ hash: v1.k794b7964.dea67e50d4956ed1865124e7dba12c5deeb0703b19cac0513c82facb069e6a60.gkkPUZ2bAqgN4OxaM6W5sfI8m4O2uxsHh7xqL1PLsg4
+ layout-navigation-eventingestionrestrictiondetails--whole-project--light:
+ hash: v1.k794b7964.56e91dee845e8cae758c631b29733ddb23d0bd46c4669cd904032f3f668c8dd9.lrp6-51HhFOiy6Rqy1o5KlQamvWmozjUVC8EQnCPhrU
layout-project-tree--all-products--dark:
hash: v1.k794b7964.f5ecd6decc0aa7b7e9641cc874f81b12d2f73973fc7a991367907c8bf9e6a3cf.GmiqvAu4XbxVgya6Rn15ChvXn-l9XU6ttxGUqmPoi4o
layout-project-tree--all-products--light:
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.ts
index 63cd18826880..c29fc34052a2 100644
--- a/frontend/src/generated/core/api.schemas.ts
+++ b/frontend/src/generated/core/api.schemas.ts
@@ -3381,6 +3381,61 @@ export interface PatchedProjectBackwardCompatApi {
readonly events_retention_enforced?: boolean
}
+/**
+ * * `skip_person_processing` - Skip Person Processing
+ * * `drop_event_from_ingestion` - Drop Event From Ingestion
+ * * `force_overflow_from_ingestion` - Force Overflow From Ingestion
+ * * `redirect_to_dlq` - Redirect To Dlq
+ * * `redirect_to_topic` - Redirect To Topic
+ */
+export type RestrictionTypeEnumApi = (typeof RestrictionTypeEnumApi)[keyof typeof RestrictionTypeEnumApi]
+
+export const RestrictionTypeEnumApi = {
+ SkipPersonProcessing: 'skip_person_processing',
+ DropEventFromIngestion: 'drop_event_from_ingestion',
+ ForceOverflowFromIngestion: 'force_overflow_from_ingestion',
+ RedirectToDlq: 'redirect_to_dlq',
+ RedirectToTopic: 'redirect_to_topic',
+} as const
+
+/**
+ * * `analytics` - Analytics
+ * * `session_recordings` - Session Recordings
+ * * `errortracking` - Errortracking
+ * * `clientwarnings` - Clientwarnings
+ * * `ai` - Ai
+ */
+export type PipelinesEnumApi = (typeof PipelinesEnumApi)[keyof typeof PipelinesEnumApi]
+
+export const PipelinesEnumApi = {
+ Analytics: 'analytics',
+ SessionRecordings: 'session_recordings',
+ Errortracking: 'errortracking',
+ Clientwarnings: 'clientwarnings',
+ Ai: 'ai',
+} as const
+
+export interface EventIngestionRestrictionApi {
+ /** What happens to matching events: dropped, sent to the overflow lane, or ingested without person processing.
+ *
+ * * `skip_person_processing` - Skip Person Processing
+ * * `drop_event_from_ingestion` - Drop Event From Ingestion
+ * * `force_overflow_from_ingestion` - Force Overflow From Ingestion
+ * * `redirect_to_dlq` - Redirect To Dlq
+ * * `redirect_to_topic` - Redirect To Topic */
+ restriction_type: RestrictionTypeEnumApi
+ /** Distinct IDs the restriction applies to. Empty means it is not filtered by distinct ID. */
+ distinct_ids: string[]
+ /** Session IDs the restriction applies to. Empty means it is not filtered by session ID. */
+ session_ids: string[]
+ /** Event names the restriction applies to. Empty means it is not filtered by event name. */
+ event_names: string[]
+ /** Event UUIDs the restriction applies to. Empty means it is not filtered by event UUID. */
+ event_uuids: string[]
+ /** Ingestion pipelines the restriction applies to. Filters combine with AND; values within a filter combine with OR. */
+ pipelines: PipelinesEnumApi[]
+}
+
export interface SharePasswordApi {
readonly id: number
readonly created_at: string
@@ -4834,6 +4889,13 @@ export type OrganizationsProjectsListParams = {
search?: string
}
+export type OrganizationsProjectsEventIngestionRestrictionsListParams = {
+ /**
+ * A search term.
+ */
+ search?: string
+}
+
export type ExportsListParams = {
/**
* Number of results to return per page.
diff --git a/frontend/src/generated/core/api.ts b/frontend/src/generated/core/api.ts
index 54bad2e4b9c8..9f8af4e858a8 100644
--- a/frontend/src/generated/core/api.ts
+++ b/frontend/src/generated/core/api.ts
@@ -17,6 +17,7 @@ import type {
CimdVerificationTokensListParams,
DomainsListParams,
EnterprisePropertyDefinitionApi,
+ EventIngestionRestrictionApi,
ExportedAssetApi,
ExportedAssetCreateApi,
ExportsListParams,
@@ -39,6 +40,7 @@ import type {
OrganizationDomainApi,
OrganizationInviteApi,
OrganizationInviteDelegateApi,
+ OrganizationsProjectsEventIngestionRestrictionsListParams,
OrganizationsProjectsListParams,
PaginatedCIMDVerificationTokenListApi,
PaginatedEnterprisePropertyDefinitionListApi,
@@ -1040,20 +1042,37 @@ export const organizationsProjectsDeleteSecretTokenBackupPartialUpdate = async (
)
}
-export const getOrganizationsProjectsEventIngestionRestrictionsRetrieveUrl = (organizationId: string, id: number) => {
- return `/api/organizations/${organizationId}/projects/${id}/event_ingestion_restrictions/`
+export const getOrganizationsProjectsEventIngestionRestrictionsListUrl = (
+ organizationId: string,
+ id: number,
+ params?: OrganizationsProjectsEventIngestionRestrictionsListParams
+) => {
+ const normalizedParams = new URLSearchParams()
+
+ Object.entries(params || {}).forEach(([key, value]) => {
+ if (value !== undefined) {
+ normalizedParams.append(key, value === null ? 'null' : String(value))
+ }
+ })
+
+ const stringifiedParams = normalizedParams.toString()
+
+ return stringifiedParams.length > 0
+ ? `/api/organizations/${organizationId}/projects/${id}/event_ingestion_restrictions/?${stringifiedParams}`
+ : `/api/organizations/${organizationId}/projects/${id}/event_ingestion_restrictions/`
}
/**
* Projects for the current organization.
*/
-export const organizationsProjectsEventIngestionRestrictionsRetrieve = async (
+export const organizationsProjectsEventIngestionRestrictionsList = async (
organizationId: string,
id: number,
+ params?: OrganizationsProjectsEventIngestionRestrictionsListParams,
options?: RequestInit
-): Promise<ProjectBackwardCompatApi> => {
- return apiMutator<ProjectBackwardCompatApi>(
- getOrganizationsProjectsEventIngestionRestrictionsRetrieveUrl(organizationId, id),
+): Promise<EventIngestionRestrictionApi[]> => {
+ return apiMutator<EventIngestionRestrictionApi[]>(
+ getOrganizationsProjectsEventIngestionRestrictionsListUrl(organizationId, id, params),
{
...options,
method: 'GET',
diff --git a/frontend/src/layout/navigation/EventIngestionRestrictionDetails.stories.tsx b/frontend/src/layout/navigation/EventIngestionRestrictionDetails.stories.tsx
new file mode 100644
index 000000000000..64d72254b576
--- /dev/null
+++ b/frontend/src/layout/navigation/EventIngestionRestrictionDetails.stories.tsx
@@ -0,0 +1,55 @@
+import { Meta, StoryObj } from '@storybook/react'
+
+import { EventIngestionRestriction, RestrictionType } from 'lib/logic/eventIngestionRestrictionLogic'
+
+import { EventIngestionRestrictionDetails } from './EventIngestionRestrictionDetails'
+
+function restriction(overrides: Partial<EventIngestionRestriction>): EventIngestionRestriction {
+ return {
+ restriction_type: RestrictionType.DROP_EVENT_FROM_INGESTION,
+ distinct_ids: [],
+ session_ids: [],
+ event_names: [],
+ event_uuids: [],
+ pipelines: ['analytics'],
+ ...overrides,
+ }
+}
+
+const meta: Meta<typeof EventIngestionRestrictionDetails> = {
+ title: 'Layout/Navigation/EventIngestionRestrictionDetails',
+ component: EventIngestionRestrictionDetails,
+ tags: ['autodocs'],
+}
+export default meta
+
+type Story = StoryObj<typeof EventIngestionRestrictionDetails>
+
+export const WholeProject: Story = {
+ args: {
+ restrictions: [restriction({})],
+ },
+}
+
+export const ScopedToDistinctIds: Story = {
+ args: {
+ restrictions: [
+ restriction({
+ restriction_type: RestrictionType.SKIP_PERSON_PROCESSING,
+ distinct_ids: ['user-1', 'user-2', 'anonymous-3f2a'],
+ }),
+ restriction({
+ restriction_type: RestrictionType.FORCE_OVERFLOW_FROM_INGESTION,
+ distinct_ids: ['user-1'],
+ event_names: ['$pageview'],
+ pipelines: ['analytics', 'session_recordings'],
+ }),
+ ],
+ },
+}
+
+export const ManyDistinctIds: Story = {
+ args: {
+ restrictions: [restriction({ distinct_ids: Array.from({ length: 30 }, (_, i) => `user-${i + 1}`) })],
+ },
+}
diff --git a/frontend/src/layout/navigation/EventIngestionRestrictionDetails.test.tsx b/frontend/src/layout/navigation/EventIngestionRestrictionDetails.test.tsx
new file mode 100644
index 000000000000..5634e62c247b
--- /dev/null
+++ b/frontend/src/layout/navigation/EventIngestionRestrictionDetails.test.tsx
@@ -0,0 +1,70 @@
+import { cleanup, render, screen } from '@testing-library/react'
+
+import { EventIngestionRestriction, RestrictionType } from 'lib/logic/eventIngestionRestrictionLogic'
+
+import { EventIngestionRestrictionDetails } from './EventIngestionRestrictionDetails'
+
+function restriction(overrides: Partial<EventIngestionRestriction>): EventIngestionRestriction {
+ return {
+ restriction_type: RestrictionType.DROP_EVENT_FROM_INGESTION,
+ distinct_ids: [],
+ session_ids: [],
+ event_names: [],
+ event_uuids: [],
+ pipelines: ['analytics'],
+ ...overrides,
+ }
+}
+
+describe('EventIngestionRestrictionDetails', () => {
+ afterEach(cleanup)
+
+ it('reports an unfiltered restriction as applying to all events', () => {
+ render(<EventIngestionRestrictionDetails restrictions={[restriction({})]} />)
+ expect(screen.getByText('Events dropped')).toBeTruthy()
+ expect(screen.getByText('Applies to all events in analytics')).toBeTruthy()
+ })
+
+ it('lists every scope filter and pipeline, and notes that filters combine', () => {
+ render(
+ <EventIngestionRestrictionDetails
+ restrictions={[
+ restriction({
+ restriction_type: RestrictionType.SKIP_PERSON_PROCESSING,
+ distinct_ids: ['u1', 'u2'],
+ event_names: ['$pageview'],
+ pipelines: ['session_recordings', 'ai'],
+ }),
+ ]}
+ />
+ )
+ expect(screen.getByText('Person processing disabled')).toBeTruthy()
+ expect(screen.getByText('Applies to some events in session recordings, AI')).toBeTruthy()
+ expect(screen.getByText('Only these 2 distinct IDs:')).toBeTruthy()
+ expect(screen.getByText('Only this event name:')).toBeTruthy()
+ expect(screen.getByText('u1')).toBeTruthy()
+ expect(screen.getByText('$pageview')).toBeTruthy()
+ expect(screen.getByText('An event is affected only when it matches every filter below.')).toBeTruthy()
+ })
+
+ it('lists redirect restrictions and unknown types instead of hiding them', () => {
+ render(
+ <EventIngestionRestrictionDetails
+ restrictions={[
+ restriction({ restriction_type: RestrictionType.REDIRECT_TO_DLQ }),
+ restriction({ restriction_type: 'some_future_type' as RestrictionType }),
+ ]}
+ />
+ )
+ expect(screen.getByText('Events held')).toBeTruthy()
+ expect(screen.getByText('Restricted')).toBeTruthy()
+ })
+
+ it('truncates long value lists', () => {
+ const distinctIds = Array.from({ length: 25 }, (_, i) => `user-${i}`)
+ render(<EventIngestionRestrictionDetails restrictions={[restriction({ distinct_ids: distinctIds })]} />)
+ expect(screen.getByText('user-19')).toBeTruthy()
+ expect(screen.queryByText('user-20')).toBeNull()
+ expect(screen.getByText('and 5 more')).toBeTruthy()
+ })
+})
diff --git a/frontend/src/layout/navigation/EventIngestionRestrictionDetails.tsx b/frontend/src/layout/navigation/EventIngestionRestrictionDetails.tsx
new file mode 100644
index 000000000000..7a3f079f870f
--- /dev/null
+++ b/frontend/src/layout/navigation/EventIngestionRestrictionDetails.tsx
@@ -0,0 +1,137 @@
+import { LemonTag } from 'lib/lemon-ui/LemonTag'
+import { EventIngestionRestriction, RestrictionType } from 'lib/logic/eventIngestionRestrictionLogic'
+
+import type { PipelinesEnumApi } from '~/generated/core/api.schemas'
+
+interface RestrictionEffect {
+ label: string
+ description: string
+}
+
+const RESTRICTION_EFFECTS: Partial<Record<string, RestrictionEffect>> = {
+ [RestrictionType.DROP_EVENT_FROM_INGESTION]: {
+ label: 'Events dropped',
+ description: 'Matching events are not stored. This data is lost and cannot be recovered.',
+ },
+ [RestrictionType.FORCE_OVERFLOW_FROM_INGESTION]: {
+ label: 'Processing delayed',
+ description: 'Matching events are routed to a slower queue. They still arrive, but may take longer to appear.',
+ },
+ [RestrictionType.SKIP_PERSON_PROCESSING]: {
+ label: 'Person processing disabled',
+ description:
+ 'Matching events are stored, but person profiles and properties are not created or updated from them.',
+ },
+ [RestrictionType.REDIRECT_TO_DLQ]: {
+ label: 'Events held',
+ description:
+ 'Matching events are set aside and not processed. Contact support to find out whether they can be recovered.',
+ },
+ [RestrictionType.REDIRECT_TO_TOPIC]: {
+ label: 'Events rerouted',
+ description: 'Matching events take a different processing path. They may be delayed.',
+ },
+}
+
+const UNKNOWN_EFFECT: RestrictionEffect = {
+ label: 'Restricted',
+ description: 'Matching events are handled differently from normal. Contact support for details.',
+}
+
+const PIPELINE_LABELS: Record<PipelinesEnumApi, string> = {
+ analytics: 'analytics',
+ session_recordings: 'session recordings',
+ errortracking: 'error tracking',
+ clientwarnings: 'client warnings',
+ ai: 'AI',
+}
+
+const MAX_VALUES_SHOWN = 20
+
+interface ScopeFilter {
+ label: string
+ values: string[]
+}
+
+function scopeFilters(restriction: EventIngestionRestriction): ScopeFilter[] {
+ return [
+ { label: 'distinct ID', values: restriction.distinct_ids ?? [] },
+ { label: 'session ID', values: restriction.session_ids ?? [] },
+ { label: 'event name', values: restriction.event_names ?? [] },
+ { label: 'event UUID', values: restriction.event_uuids ?? [] },
+ ].filter((filter) => filter.values.length > 0)
+}
+
+function ScopeFilterValues({ filter }: { filter: ScopeFilter }): JSX.Element {
+ const hidden = filter.values.length - MAX_VALUES_SHOWN
+ return (
+ <div>
+ <div className="text-secondary text-xs mb-1">
+ Only {filter.values.length === 1 ? 'this' : `these ${filter.values.length}`} {filter.label}
+ {filter.values.length === 1 ? '' : 's'}:
+ </div>
+ <div className="flex flex-wrap gap-1">
+ {filter.values.slice(0, MAX_VALUES_SHOWN).map((value) => (
+ <LemonTag key={value} type="muted" size="small" className="font-mono break-all">
+ {value}
+ </LemonTag>
+ ))}
+ {hidden > 0 && <span className="text-secondary text-xs">and {hidden} more</span>}
+ </div>
+ </div>
+ )
+}
+
+/** Explains each active ingestion restriction: what it does to matching events and which events it targets. */
+export function EventIngestionRestrictionDetails({
+ restrictions,
+}: {
+ restrictions: EventIngestionRestriction[]
+}): JSX.Element {
+ if (restrictions.length === 0) {
+ return <p>No active restrictions were found for this project. Refresh the page to check again.</p>
+ }
+
+ return (
+ <div className="deprecated-space-y-4">
+ <p>
+ PostHog has applied one or more restrictions to events sent with this project's token. Restrictions are
+ usually put in place to protect the ingestion pipeline. Contact support if you need one removed.
+ </p>
+ <ul className="deprecated-space-y-3">
+ {restrictions.map((restriction) => {
+ const effect = RESTRICTION_EFFECTS[restriction.restriction_type] ?? UNKNOWN_EFFECT
+ const filters = scopeFilters(restriction)
+ const pipelines = (restriction.pipelines ?? []).map(
+ (pipeline) => PIPELINE_LABELS[pipeline] ?? pipeline
+ )
+ const isScoped = filters.length > 0
+ return (
+ <li key={restriction.restriction_type} className="border rounded p-3">
+ <div className="flex items-center gap-2 mb-1">
+ <LemonTag type={isScoped ? 'warning' : 'danger'}>{effect.label}</LemonTag>
+ <span className="text-secondary text-xs">
+ {isScoped ? 'Applies to some events' : 'Applies to all events'}
+ {pipelines.length > 0 ? ` in ${pipelines.join(', ')}` : ''}
+ </span>
+ </div>
+ <p className="mb-0">{effect.description}</p>
+ {isScoped && (
+ <div className="mt-2 deprecated-space-y-2">
+ {filters.length > 1 && (
+ <div className="text-secondary text-xs">
+ An event is affected only when it matches every filter below.
+ </div>
+ )}
+ {filters.map((filter) => (
+ <ScopeFilterValues key={filter.label} filter={filter} />
+ ))}
+ </div>
+ )}
+ </li>
+ )
+ })}
+ </ul>
+ </div>
+ )
+}
diff --git a/frontend/src/layout/navigation/projectNoticeLogic.tsx b/frontend/src/layout/navigation/projectNoticeLogic.tsx
index 6fa9816a8059..ae10a9790dd2 100644
--- a/frontend/src/layout/navigation/projectNoticeLogic.tsx
+++ b/frontend/src/layout/navigation/projectNoticeLogic.tsx
@@ -9,6 +9,7 @@ import { getProductPushDisplay } from 'lib/components/NavPanelAdvertisement/navP
import { reverseProxyCheckerLogic } from 'lib/components/ReverseProxyChecker/reverseProxyCheckerLogic'
import { superpowersLogic } from 'lib/components/Superpowers/superpowersLogic'
import { LemonBannerProps } from 'lib/lemon-ui/LemonBanner/LemonBanner'
+import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { Link } from 'lib/lemon-ui/Link'
import { apiStatusLogic } from 'lib/logic/apiStatusLogic'
import { eventIngestionRestrictionLogic } from 'lib/logic/eventIngestionRestrictionLogic'
@@ -31,6 +32,8 @@ import { brandingForProduct } from 'scenes/welcome/productBranding'
import { ProductKey } from '~/queries/schema/schema-general'
import { OnboardingStepKey, UserType } from '~/types'
+import { EventIngestionRestrictionDetails } from './EventIngestionRestrictionDetails'
+
export type ProjectNoticeVariant =
| 'billing_alert'
| 'demo_project'
@@ -257,6 +260,9 @@ export interface projectNoticeLogicActions {
reportNoticeShown: () => {
value: true
}
+ showEventIngestionRestrictionDetails: () => {
+ value: true
+ }
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -353,6 +359,7 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([
actions({
dismissProjectNotice: (dismissKey: string | null) => ({ dismissKey }),
reportNoticeShown: true,
+ showEventIngestionRestrictionDetails: true,
}),
loaders(({ values }) => ({
proxyRecords: {
@@ -676,6 +683,11 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([
message:
'Event ingestion restrictions have been applied to a token in this project. Please contact support.',
type: 'warning',
+ action: {
+ onClick: () => projectNoticeLogic.actions.showEventIngestionRestrictionDetails(),
+ 'data-attr': 'event-ingestion-restriction-details_link',
+ children: 'See details',
+ },
}
case 'missing_reverse_proxy':
return {
@@ -697,6 +709,18 @@ export const projectNoticeLogic = kea<projectNoticeLogicType>([
],
}),
listeners(({ actions, values }) => ({
+ showEventIngestionRestrictionDetails: () => {
+ LemonDialog.open({
+ title: 'Event ingestion restrictions',
+ content: (
+ <EventIngestionRestrictionDetails
+ restrictions={eventIngestionRestrictionLogic.values.eventIngestionRestrictions}
+ />
+ ),
+ primaryButton: { children: 'Close' },
+ width: 560,
+ })
+ },
dismissProjectNotice: ({ dismissKey }) => {
if (dismissKey) {
storeNoticeDismissal(dismissKey)
diff --git a/frontend/src/lib/logic/eventIngestionRestrictionLogic.ts b/frontend/src/lib/logic/eventIngestionRestrictionLogic.ts
index 74a7e1246ec7..3cdef36a3955 100644
--- a/frontend/src/lib/logic/eventIngestionRestrictionLogic.ts
+++ b/frontend/src/lib/logic/eventIngestionRestrictionLogic.ts
@@ -4,16 +4,17 @@ import { lazyLoaders } from 'kea-loaders'
import api from 'lib/api'
import { teamLogic } from 'scenes/teamLogic'
+import type { EventIngestionRestrictionApi } from '~/generated/core/api.schemas'
+
export enum RestrictionType {
DROP_EVENT_FROM_INGESTION = 'drop_event_from_ingestion',
SKIP_PERSON_PROCESSING = 'skip_person_processing',
FORCE_OVERFLOW_FROM_INGESTION = 'force_overflow_from_ingestion',
+ REDIRECT_TO_DLQ = 'redirect_to_dlq',
+ REDIRECT_TO_TOPIC = 'redirect_to_topic',
}
-export interface EventIngestionRestriction {
- restriction_type: RestrictionType
- distinct_ids: string[] | null
-}
+export type EventIngestionRestriction = EventIngestionRestrictionApi
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface eventIngestionRestrictionLogicValues {
@@ -45,7 +46,7 @@ export interface eventIngestionRestrictionLogicActions {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface eventIngestionRestrictionLogicMeta {
__keaTypeGenInternalSelectorTypes: {
- hasProjectNoticeRestriction: (eventIngestionRestrictions: EventIngestionRestriction[]) => boolean
+ hasProjectNoticeRestriction: (eventIngestionRestrictions: EventIngestionRestrictionApi[]) => boolean
}
}
diff --git a/posthog/api/project.py b/posthog/api/project.py
index 006dc3d052d5..a162b2da115d 100644
--- a/posthog/api/project.py
+++ b/posthog/api/project.py
@@ -32,6 +32,7 @@ from posthog.api.team import (
TEAM_CONFIG_MEMBER_FIELDS_SET,
EvaluationContextSuggestionRequestSerializer,
EvaluationContextSuggestionResponseSerializer,
+ EventIngestionRestrictionSerializer,
TeamCustomerAnalyticsConfigSerializer,
TeamMarketingAnalyticsConfigSerializer,
TeamRevenueAnalyticsConfigSerializer,
@@ -44,6 +45,7 @@ from posthog.api.team import (
handle_experiments_config,
handle_logs_config,
report_conversations_settings_changes,
+ team_event_ingestion_restrictions_view,
validate_secret_token_generation,
validate_team_attrs,
)
@@ -67,7 +69,6 @@ from posthog.models.activity_logging.activity_log import (
log_activity,
)
from posthog.models.activity_logging.activity_page import activity_page_response
-from posthog.models.event_ingestion_restriction_config import EventIngestionRestrictionConfig
from posthog.models.group_type_mapping import cached_group_types_for_project
from posthog.models.organization import Organization, OrganizationMembership
from posthog.models.product_intent.product_intent import (
@@ -384,15 +385,6 @@ def team_settings_as_of_view(team: Team, request: request.Request) -> response.R
return response.Response(snapshot)
-def team_event_ingestion_restrictions_view(team: Team, request: request.Request) -> response.Response:
- restrictions = EventIngestionRestrictionConfig.objects.filter(token=team.api_token)
- data = [
- {"restriction_type": restriction.restriction_type, "distinct_ids": restriction.distinct_ids}
- for restriction in restrictions
- ]
- return response.Response(data)
-
-
def team_default_evaluation_contexts_view(
team: Team, request: request.Request, user_permissions: UserPermissions
) -> response.Response:
@@ -1727,7 +1719,14 @@ class ProjectViewSet(
"""
return team_settings_as_of_view(self.get_object().passthrough_team, request)
- @action(methods=["GET"], detail=True, required_scopes=["project:read"], url_path="event_ingestion_restrictions")
+ @extend_schema(responses=EventIngestionRestrictionSerializer(many=True))
+ @action(
+ methods=["GET"],
+ detail=True,
+ required_scopes=["project:read"],
+ url_path="event_ingestion_restrictions",
+ pagination_class=None,
+ )
def event_ingestion_restrictions(self, request, **kwargs):
return team_event_ingestion_restrictions_view(self.get_object().passthrough_team, request)
diff --git a/posthog/api/team.py b/posthog/api/team.py
index e5693fa05a9c..f7cfb118d001 100644
--- a/posthog/api/team.py
+++ b/posthog/api/team.py
@@ -61,7 +61,11 @@ from posthog.models.activity_logging.activity_log import (
)
from posthog.models.activity_logging.activity_page import activity_page_response
from posthog.models.data_color_theme import DataColorTheme
-from posthog.models.event_ingestion_restriction_config import EventIngestionRestrictionConfig
+from posthog.models.event_ingestion_restriction_config import (
+ EventIngestionRestrictionConfig,
+ IngestionPipeline,
+ RestrictionType,
+)
from posthog.models.filters.utils import validate_group_type_index
from posthog.models.group_type_mapping import cached_group_types_for_team
from posthog.models.organization import Organization, OrganizationMembership
@@ -2130,6 +2134,49 @@ class EvaluationContextSuggestionResponseSerializer(serializers.Serializer):
)
+class EventIngestionRestrictionSerializer(serializers.Serializer):
+ restriction_type = serializers.ChoiceField(
+ choices=RestrictionType.choices,
+ help_text="What happens to matching events: dropped, sent to the overflow lane, or ingested without person processing.",
+ )
+ distinct_ids = serializers.ListField(
+ child=serializers.CharField(),
+ help_text="Distinct IDs the restriction applies to. Empty means it is not filtered by distinct ID.",
+ )
+ session_ids = serializers.ListField(
+ child=serializers.CharField(),
+ help_text="Session IDs the restriction applies to. Empty means it is not filtered by session ID.",
+ )
+ event_names = serializers.ListField(
+ child=serializers.CharField(),
+ help_text="Event names the restriction applies to. Empty means it is not filtered by event name.",
+ )
+ event_uuids = serializers.ListField(
+ child=serializers.CharField(),
+ help_text="Event UUIDs the restriction applies to. Empty means it is not filtered by event UUID.",
+ )
+ pipelines = serializers.ListField(
+ child=serializers.ChoiceField(choices=IngestionPipeline.choices),
+ help_text="Ingestion pipelines the restriction applies to. Filters combine with AND; values within a filter combine with OR.",
+ )
+
+
+def team_event_ingestion_restrictions_view(team: Team, request: request.Request) -> response.Response:
+ restrictions = EventIngestionRestrictionConfig.objects.filter(token=team.api_token)
+ data = [
+ {
+ "restriction_type": restriction.restriction_type,
+ "distinct_ids": restriction.distinct_ids or [],
+ "session_ids": restriction.session_ids or [],
+ "event_names": restriction.event_names or [],
+ "event_uuids": restriction.event_uuids or [],
+ "pipelines": restriction.pipelines or [],
+ }
+ for restriction in restrictions
+ ]
+ return response.Response(EventIngestionRestrictionSerializer(data, many=True).data)
+
+
class TeamViewSet(
TeamAndOrgViewSetMixin, AccessControlSettingsViewSetMixin, AccessControlViewSetMixin, viewsets.ModelViewSet
):
@@ -2569,18 +2616,16 @@ class TeamViewSet(
return response.Response(TeamSerializer(team, context=self.get_serializer_context()).data)
- @action(methods=["GET"], detail=True, required_scopes=["project:read"], url_path="event_ingestion_restrictions")
+ @extend_schema(responses=EventIngestionRestrictionSerializer(many=True))
+ @action(
+ methods=["GET"],
+ detail=True,
+ required_scopes=["project:read"],
+ url_path="event_ingestion_restrictions",
+ pagination_class=None,
+ )
def event_ingestion_restrictions(self, request, **kwargs):
- team = self.get_object()
- restrictions = EventIngestionRestrictionConfig.objects.filter(token=team.api_token)
- data = [
- {
- "restriction_type": restriction.restriction_type,
- "distinct_ids": restriction.distinct_ids,
- }
- for restriction in restrictions
- ]
- return response.Response(data)
+ return team_event_ingestion_restrictions_view(self.get_object(), request)
@cached_property
def user_permissions(self):
diff --git a/posthog/api/test/test_team.py b/posthog/api/test/test_team.py
index 689f8ad4cbe1..fbfcf173d175 100644
--- a/posthog/api/test/test_team.py
+++ b/posthog/api/test/test_team.py
@@ -24,6 +24,7 @@ from posthog.api.team import (
_reset_default_data_color_theme_id_cache,
)
from posthog.constants import AvailableFeature
+from posthog.models.event_ingestion_restriction_config import EventIngestionRestrictionConfig, RestrictionType
from posthog.models.group_type_mapping import (
GROUP_TYPES_CACHE_KEY_PREFIX,
GROUP_TYPES_STALE_CACHE_KEY_PREFIX,
@@ -236,6 +237,40 @@ def team_api_test_factory():
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.json(), self.not_found_response())
+ def test_event_ingestion_restrictions_are_scoped_to_own_team(self):
+ other_org = Organization.objects.create(name="New Org")
+ other_team = Team.objects.create(organization=other_org, name="Default project")
+ EventIngestionRestrictionConfig.objects.create(
+ token=self.team.api_token,
+ restriction_type=RestrictionType.SKIP_PERSON_PROCESSING,
+ distinct_ids=["own-user"],
+ note="internal note",
+ )
+ EventIngestionRestrictionConfig.objects.create(
+ token=other_team.api_token,
+ restriction_type=RestrictionType.DROP_EVENT_FROM_INGESTION,
+ distinct_ids=["other-user"],
+ )
+
+ response = self.client.get(f"/api/environments/{self.team.pk}/event_ingestion_restrictions/")
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ self.assertEqual(
+ response.json(),
+ [
+ {
+ "restriction_type": RestrictionType.SKIP_PERSON_PROCESSING,
+ "distinct_ids": ["own-user"],
+ "session_ids": [],
+ "event_names": [],
+ "event_uuids": [],
+ "pipelines": ["analytics"],
+ }
+ ],
+ )
+
+ response = self.client.get(f"/api/environments/{other_team.pk}/event_ingestion_restrictions/")
+ self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
+
@freeze_time("2022-02-08")
def test_update_team_timezone(self):
self._assert_activity_log_is_empty()
diff --git a/services/mcp/definitions/core.yaml b/services/mcp/definitions/core.yaml
index ed5cd7d5a794..69d530afc9dc 100644
--- a/services/mcp/definitions/core.yaml
+++ b/services/mcp/definitions/core.yaml
@@ -250,8 +250,8 @@ tools:
organizations-projects-default-release-conditions-update:
operation: organizations_projects_default_release_conditions_update
enabled: false
- organizations-projects-event-ingestion-restrictions-retrieve:
- operation: organizations_projects_event_ingestion_restrictions_retrieve
+ organizations-projects-event-ingestion-restrictions-list:
+ operation: organizations_projects_event_ingestion_restrictions_list
enabled: false
organizations-projects-experiments-config-partial-update:
operation: organizations_projects_experiments_config_partial_update
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 5230a2e86971..a07e5b63dfc3 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -32684,6 +32684,63 @@ export namespace Schemas {
readonly updated_at: string;
}
+ /**
+ * * `skip_person_processing` - Skip Person Processing
+ * * `drop_event_from_ingestion` - Drop Event From Ingestion
+ * * `force_overflow_from_ingestion` - Force Overflow From Ingestion
+ * * `redirect_to_dlq` - Redirect To Dlq
+ * * `redirect_to_topic` - Redirect To Topic
+ */
+ export type RestrictionTypeEnum = typeof RestrictionTypeEnum[keyof typeof RestrictionTypeEnum];
+
+
+ export const RestrictionTypeEnum = {
+ SkipPersonProcessing: 'skip_person_processing',
+ DropEventFromIngestion: 'drop_event_from_ingestion',
+ ForceOverflowFromIngestion: 'force_overflow_from_ingestion',
+ RedirectToDlq: 'redirect_to_dlq',
+ RedirectToTopic: 'redirect_to_topic',
+ } as const;
+
+ /**
+ * * `analytics` - Analytics
+ * * `session_recordings` - Session Recordings
+ * * `errortracking` - Errortracking
+ * * `clientwarnings` - Clientwarnings
+ * * `ai` - Ai
+ */
+ export type PipelinesEnum = typeof PipelinesEnum[keyof typeof PipelinesEnum];
+
+
+ export const PipelinesEnum = {
+ Analytics: 'analytics',
+ SessionRecordings: 'session_recordings',
+ Errortracking: 'errortracking',
+ Clientwarnings: 'clientwarnings',
+ Ai: 'ai',
+ } as const;
+
+ export interface EventIngestionRestriction {
+ /** What happens to matching events: dropped, sent to the overflow lane, or ingested without person processing.
+ *
+ * * `skip_person_processing` - Skip Person Processing
+ * * `drop_event_from_ingestion` - Drop Event From Ingestion
+ * * `force_overflow_from_ingestion` - Force Overflow From Ingestion
+ * * `redirect_to_dlq` - Redirect To Dlq
+ * * `redirect_to_topic` - Redirect To Topic */
+ restriction_type: RestrictionTypeEnum;
+ /** Distinct IDs the restriction applies to. Empty means it is not filtered by distinct ID. */
+ distinct_ids: string[];
+ /** Session IDs the restriction applies to. Empty means it is not filtered by session ID. */
+ session_ids: string[];
+ /** Event names the restriction applies to. Empty means it is not filtered by event name. */
+ event_names: string[];
+ /** Event UUIDs the restriction applies to. Empty means it is not filtered by event UUID. */
+ event_uuids: string[];
+ /** Ingestion pipelines the restriction applies to. Filters combine with AND; values within a filter combine with OR. */
+ pipelines: PipelinesEnum[];
+ }
+
/**
* * `DateTime` - DateTime
* * `String` - String
@@ -88212,6 +88269,13 @@ export namespace Schemas {
context_name: string;
};
+ export type OrganizationsProjectsEventIngestionRestrictionsListParams = {
+ /**
+ * A search term.
+ */
+ search?: string;
+ };
+
export type RoleExternalReferencesListParams = {
/**
* Number of results to return per page.