: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 typing import Optional, cast
from products.warehouse_sources.sources.rootly._config import RootlySourceConfig
from products.warehouse_sources.sources.rootly.canonical_descriptions import CANONICAL_DESCRIPTIONS
from products.warehouse_sources.sources.rootly.rootly import RootlyResumeConfig, probe_credentials, rootly_source
from products.warehouse_sources.sources.rootly.settings import ENDPOINTS, INCREMENTAL_FIELDS, SHOULD_SYNC_DEFAULT
from products.warehouse_sources.sources.sdk import (
CanonicalDescriptions,
DataWarehouseSourceCategory,
ExternalDataSourceType,
FieldType,
ReleaseStatus,
ResumableSource,
ResumableSourceManager,
SourceConfig,
SourceFieldInputConfig,
SourceFieldInputConfigType,
SourceInputs,
SourceRegistry,
SourceResponse,
SourceSchema,
build_endpoint_schemas,
detect,
)
@SourceRegistry.register
class RootlySource(ResumableSource[RootlySourceConfig, RootlyResumeConfig]):
codebase_detection = detect(
env=("^ROOTLY_",),
npm=("@rootly/pulumi",),
pypi=("rootly",),
go=(
"github.com/rootlyhq/rootly-go",
"github.com/rootlyhq/rootly-catalog-sync",
"github.com/rootlyhq/rootly-cli",
"github.com/rootlyhq/rootly-tui",
),
swiftpm=("github.com/rootlyhq/rootly-swift",),
)
api_docs_url = "https://docs.rootly.com/api-reference"
@property
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.ROOTLY
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=ExternalDataSourceType.ROOTLY,
category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,
label="Rootly",
releaseStatus=ReleaseStatus.BETA,
caption="""Enter your Rootly API key to automatically pull your Rootly incident-management data into the PostHog Data warehouse.
You can create an API key in your [Rootly account settings](https://rootly.com/account/api_keys). A Global-scope key can read every resource; Team- and User-scope keys only see the resources they are granted.""",
iconPath="/static/services/rootly.png",
docsUrl="https://posthog.com/docs/cdp/sources/rootly",
fields=cast(
list[FieldType],
[
SourceFieldInputConfig(
name="api_key",
label="API key",
type=SourceFieldInputConfigType.PASSWORD,
required=True,
placeholder="rootly_...",
secret=True,
),
],
),
)
def get_canonical_descriptions(self) -> CanonicalDescriptions:
return CANONICAL_DESCRIPTIONS
def get_non_retryable_errors(self) -> dict[str, str | None]:
return {
# 401/403 surface as a requests HTTPError when the REST client calls `raise_for_status()`.
# No retry can satisfy a credential/scope problem. Match the stable status text + base
# host, not the per-request path/query.
"401 Client Error: Unauthorized for url: https://api.rootly.com": "Your Rootly API key is invalid or has been revoked. Create a new API key in your Rootly account settings, then reconnect.",
"403 Client Error: Forbidden for url: https://api.rootly.com": "Your Rootly API key is missing access to this resource. Grant the key access in your Rootly account settings, then reconnect.",
}
def get_schemas(
self,
config: RootlySourceConfig,
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names, should_sync_default=SHOULD_SYNC_DEFAULT)
def validate_credentials(
self,
config: RootlySourceConfig,
team_id: int,
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
status = probe_credentials(config.api_key, schema_name)
if status == 200:
return True, None
# At source-create (schema_name is None) a 403 means the token is genuine but scoped away
# from the probe resource — accept it; per-endpoint scope is checked when configuring a schema.
if status == 403 and schema_name is None:
return True, None
if status == 401:
return False, "Your Rootly API key is invalid or has been revoked."
if status == 403:
return False, "Your Rootly API key does not have access to this resource."
return False, "Could not validate your Rootly API key. Please check the key and try again."
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[RootlyResumeConfig]:
return ResumableSourceManager[RootlyResumeConfig](inputs, RootlyResumeConfig)
def source_for_pipeline(
self,
config: RootlySourceConfig,
resumable_source_manager: ResumableSourceManager[RootlyResumeConfig],
inputs: SourceInputs,
) -> SourceResponse:
return rootly_source(
api_key=config.api_key,
endpoint=inputs.schema_name,
team_id=inputs.team_id,
job_id=inputs.job_id,
resumable_source_manager=resumable_source_manager,
should_use_incremental_field=inputs.should_use_incremental_field,
db_incremental_field_last_value=inputs.db_incremental_field_last_value
if inputs.should_use_incremental_field
else None,
incremental_field=inputs.incremental_field,
)