: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
from dataclasses import dataclass, field
from products.warehouse_sources.sources.sdk import IncrementalField, IncrementalFieldType
# Every ServiceNow table exposes the same audit columns, so every endpoint advertises
# the same incremental options. `sys_updated_on` catches both inserts and updates;
# `sys_created_on` is offered for append-only style syncs.
SERVICENOW_INCREMENTAL_FIELDS: list[IncrementalField] = [
{
"label": "sys_updated_on",
"type": IncrementalFieldType.DateTime,
"field": "sys_updated_on",
"field_type": IncrementalFieldType.DateTime,
},
{
"label": "sys_created_on",
"type": IncrementalFieldType.DateTime,
"field": "sys_created_on",
"field_type": IncrementalFieldType.DateTime,
},
]
@dataclass
class ServiceNowEndpointConfig:
name: str
"""Stream name shown to the user."""
table: str
"""The underlying ServiceNow table queried via the Table API."""
primary_key: str = "sys_id"
partition_key: str = "sys_created_on"
"""Stable creation timestamp used for datetime partitioning (never `sys_updated_on`)."""
default_incremental_field: str = "sys_updated_on"
incremental_fields: list[IncrementalField] = field(default_factory=lambda: list(SERVICENOW_INCREMENTAL_FIELDS))
# Default stream catalog, cross-referenced against the Airbyte/Fivetran ServiceNow
# connectors. Friendly stream names map to the canonical ITSM table names. Every table
# carries `sys_id`, `sys_created_on`, and `sys_updated_on`, so the incremental and
# partition config is uniform across all of them.
SERVICENOW_ENDPOINTS: dict[str, ServiceNowEndpointConfig] = {
"incidents": ServiceNowEndpointConfig(name="incidents", table="incident"),
"problems": ServiceNowEndpointConfig(name="problems", table="problem"),
"change_requests": ServiceNowEndpointConfig(name="change_requests", table="change_request"),
"change_tasks": ServiceNowEndpointConfig(name="change_tasks", table="change_task"),
"tasks": ServiceNowEndpointConfig(name="tasks", table="task"),
"catalog_requests": ServiceNowEndpointConfig(name="catalog_requests", table="sc_request"),
"requested_items": ServiceNowEndpointConfig(name="requested_items", table="sc_req_item"),
"catalog_tasks": ServiceNowEndpointConfig(name="catalog_tasks", table="sc_task"),
"users": ServiceNowEndpointConfig(name="users", table="sys_user"),
"user_groups": ServiceNowEndpointConfig(name="user_groups", table="sys_user_group"),
"configuration_items": ServiceNowEndpointConfig(name="configuration_items", table="cmdb_ci"),
"knowledge_articles": ServiceNowEndpointConfig(name="knowledge_articles", table="kb_knowledge"),
"assets": ServiceNowEndpointConfig(name="assets", table="alm_asset"),
"task_slas": ServiceNowEndpointConfig(name="task_slas", table="task_sla"),
"metric_instances": ServiceNowEndpointConfig(name="metric_instances", table="metric_instance"),
"choices": ServiceNowEndpointConfig(name="choices", table="sys_choice"),
"service_offerings": ServiceNowEndpointConfig(name="service_offerings", table="service_offering"),
# The core service table also holds its Business Service and Technology Management Service child
# classes, plus business services from instances that have not moved them to the child table yet.
"services": ServiceNowEndpointConfig(name="services", table="cmdb_ci_service"),
"group_members": ServiceNowEndpointConfig(name="group_members", table="sys_user_grmember"),
}
ENDPOINTS = tuple(SERVICENOW_ENDPOINTS.keys())
INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
name: config.incremental_fields for name, config in SERVICENOW_ENDPOINTS.items()
}