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.

2.2 KB
Raw Blame
from dataclasses import dataclass, field
from typing import Optional

from products.warehouse_sources.sources.sdk import IncrementalField


@dataclass(frozen=False)
class AirOpsEndpointConfig:
    name: str
    # Partition on a STABLE creation timestamp so partitions don't rewrite on every sync. Apps expose
    # `created_at`; executions expose `createdAt`.
    partition_key: Optional[str] = None
    primary_keys: list[str] = field(default_factory=lambda: ["id"])
    # AirOps exposes no server-side timestamp filter on either list endpoint, and executions mutate
    # after creation (status transitions, feedback), so every endpoint is full refresh only.
    incremental_fields: list[IncrementalField] = field(default_factory=list)
    should_sync_default: bool = True


AIROPS_ENDPOINTS: dict[str, AirOpsEndpointConfig] = {
    "apps": AirOpsEndpointConfig(
        name="apps",
        partition_key="created_at",
    ),
    "executions": AirOpsEndpointConfig(
        name="executions",
        partition_key="createdAt",
        # Execution ids are scoped per app, so the app id is part of the composite key to keep two
        # apps' executions that share an id from colliding into one warehouse row.
        primary_keys=["airops_app_id", "id"],
    ),
    # AI search-visibility surface. `brand_kits` is the top-level object; `prompts` and `citations`
    # are listed per brand kit (fan-out), so their composite keys carry the parent brand kit id.
    "brand_kits": AirOpsEndpointConfig(
        name="brand_kits",
        partition_key="created_at",
    ),
    "prompts": AirOpsEndpointConfig(
        name="prompts",
        partition_key="created_at",
        primary_keys=["brand_kit_id", "id"],
    ),
    "citations": AirOpsEndpointConfig(
        name="citations",
        # Citations carry no id or creation timestamp — a citation is identified by its URL within a
        # brand kit, and there is no stable creation time to partition on.
        primary_keys=["brand_kit_id", "url"],
    ),
}

ENDPOINTS = tuple(AIROPS_ENDPOINTS.keys())

INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
    name: config.incremental_fields for name, config in AIROPS_ENDPOINTS.items()
}