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.

8.0 KB
Raw Blame
from typing import Optional, cast

from products.warehouse_sources.sources.rollbar._config import RollbarSourceConfig
from products.warehouse_sources.sources.rollbar.rollbar import (
    RollbarResumeConfig,
    rollbar_source,
    validate_credentials as validate_rollbar_credentials,
)
from products.warehouse_sources.sources.rollbar.settings import ENDPOINTS, INCREMENTAL_FIELDS
from products.warehouse_sources.sources.sdk import (
    CanonicalDescriptions,
    DataWarehouseSourceCategory,
    ExternalDataSourceType,
    FieldType,
    ProductKey,
    ReleaseStatus,
    ResumableSource,
    ResumableSourceManager,
    SourceConfig,
    SourceFieldInputConfig,
    SourceFieldInputConfigType,
    SourceInputs,
    SourceRegistry,
    SourceResponse,
    SourceSchema,
    build_endpoint_schemas,
    detect,
)


@SourceRegistry.register
class RollbarSource(ResumableSource[RollbarSourceConfig, RollbarResumeConfig]):
    codebase_detection = detect(
        env=(
            "^ROLLBAR_",
            "^NEXT_PUBLIC_ROLLBAR_CLIENT_TOKEN$",
            "^NEXT_PUBLIC_ROLLBAR_PROJECT_ACCESS_CLIENT_TOKEN$",
            "^VITE_ROLLBAR_ACCESS_TOKEN$",
            "^VITE_PUBLIC_ROLLBAR_TOKEN$",
            "^REACT_APP_ROLLBAR_ACCESS_TOKEN$",
            "^PUBLIC_ROLLBAR_ACCESS_TOKEN$",
        ),
        script_hosts=("cdn.rollbar.com", "d37gvrvc0wt4s1.cloudfront.net"),
        npm=(
            "rollbar",
            "@rollbar/react",
            "rollbar-react-native",
            "rollbar-browser",
            "rollbar-cli",
            "rollbar-cordova",
            "rollbar-redux-middleware",
            "@rollbar/mcp-server",
            "rollbar-sourcemap-webpack-plugin",
            "vite-plugin-rollbar",
            "ember-rollbar-client",
        ),
        pypi=("rollbar", "rollbar-agent"),
        cocoapods=(
            "RollbarNotifier",
            "Rollbar",
            "RollbarCommon",
            "RollbarCrash",
            "RollbarCrashReport",
            "RollbarDeploys",
            "RollbarAUL",
            "RollbarCocoaLumberjack",
            "RollbarSwift",
            "RollbarPLCrashReporter",
        ),
        composer=(
            "rollbar/rollbar",
            "rollbar/rollbar-laravel",
            "rollbar/rollbar-php-symfony-bundle",
            "rollbar/rollbar-php-symfony3-bundle",
            "rollbar/rollbar-php-wordpress",
            "rollbar/rollbar-magento2",
        ),
        go=("github.com/rollbar/rollbar-go", "github.com/stvp/rollbar"),
        hex=("rollbax",),
        maven=(
            "com.rollbar:rollbar-java",
            "com.rollbar:rollbar-android",
            "com.rollbar:rollbar",
            "com.rollbar:rollbar-api",
            "com.rollbar:rollbar-web",
            "com.rollbar:rollbar-jakarta-web",
            "com.rollbar:rollbar-java-agent",
            "com.rollbar:rollbar-log4j2",
            "com.rollbar:rollbar-logback",
            "com.rollbar:rollbar-okhttp",
            "com.rollbar:rollbar-reactive-streams",
            "com.rollbar:rollbar-reactive-streams-reactor",
            "com.rollbar:rollbar-spring-webmvc",
            "com.rollbar:rollbar-spring6-webmvc",
            "com.rollbar:rollbar-spring-boot-webmvc",
            "com.rollbar:rollbar-spring-boot3-webmvc",
            "com.rollbar:rollbar-struts2",
            "com.rollbar:rollbar-payload",
            "com.rollbar:rollbar-sender",
            "com.rollbar:rollbar-utilities",
        ),
        pub=("rollbar_flutter", "rollbar_dart", "rollbar_common"),
        rubygems=("rollbar", "ratchetio", "resque-rollbar"),
        swiftpm=("github.com/rollbar/rollbar-apple",),
        alternative_to=(ProductKey.ERROR_TRACKING,),
    )

    lists_tables_without_credentials = True  # static endpoint catalog — safe for public docs
    supported_versions = ("1",)
    default_version = "1"
    api_docs_url = "https://docs.rollbar.com/reference"

    @property
    def source_type(self) -> ExternalDataSourceType:
        return ExternalDataSourceType.ROLLBAR

    def get_canonical_descriptions(self) -> CanonicalDescriptions:
        from products.warehouse_sources.sources.rollbar.canonical_descriptions import CANONICAL_DESCRIPTIONS

        return CANONICAL_DESCRIPTIONS

    def get_non_retryable_errors(self) -> dict[str, str | None]:
        return {
            "401 Client Error: Unauthorized for url: https://api.rollbar.com": "Rollbar authentication failed. Please check your project access token.",
            "403 Client Error: Forbidden for url: https://api.rollbar.com": "Rollbar denied access. Please check that your project access token has the read scope.",
        }

    def get_retryable_errors(self) -> set[str]:
        # `_get_session` uses `make_tracked_session`, whose `DEFAULT_RETRY` already retries a
        # dropped connection or read timeout before `fetch`'s own tenacity retry re-raises once
        # that budget is exhausted too. urllib3 wraps that as "... Max retries exceeded with
        # url: ...". `fetch` also retries a 429/5xx response itself, re-raising as
        # "Rollbar API error (retryable): ..." once that budget is exhausted. Temporal then
        # retries the whole activity either way, so the failure is transient and
        # self-recovering, not a bug to report.
        return {"Max retries exceeded with url", "Rollbar API error (retryable)"}

    @property
    def get_source_config(self) -> SourceConfig:
        return SourceConfig(
            name=ExternalDataSourceType.ROLLBAR,
            category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,
            label="Rollbar",
            caption="""Enter your Rollbar project access token to pull your Rollbar error data into the PostHog Data warehouse.

You can find or create a project access token in your Rollbar project under Settings > Project Access Tokens. A token with the `read` scope is sufficient. Each PostHog source connects to one Rollbar project — add one source per project.""",
            iconPath="/static/services/rollbar.png",
            docsUrl="https://posthog.com/docs/cdp/sources/rollbar",
            releaseStatus=ReleaseStatus.GA,
            fields=cast(
                list[FieldType],
                [
                    SourceFieldInputConfig(
                        name="access_token",
                        label="Project access token",
                        type=SourceFieldInputConfigType.PASSWORD,
                        required=True,
                        placeholder="",
                        secret=True,
                    ),
                ],
            ),
        )

    def get_schemas(
        self,
        config: RollbarSourceConfig,
        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)

    def validate_credentials(
        self,
        config: RollbarSourceConfig,
        team_id: int,
        schema_name: Optional[str] = None,
        api_version: str | None = None,
    ) -> tuple[bool, str | None]:
        return validate_rollbar_credentials(config.access_token)

    def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[RollbarResumeConfig]:
        return ResumableSourceManager[RollbarResumeConfig](inputs, RollbarResumeConfig)

    def source_for_pipeline(
        self,
        config: RollbarSourceConfig,
        resumable_source_manager: ResumableSourceManager[RollbarResumeConfig],
        inputs: SourceInputs,
    ) -> SourceResponse:
        return rollbar_source(
            access_token=config.access_token,
            endpoint=inputs.schema_name,
            logger=inputs.logger,
            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,
        )