4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
93 lines
3.1 KiB
Python
93 lines
3.1 KiB
Python
"""PostHog connection settings and config builders."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
from typing import Any
|
|
|
|
from pydantic import Field, field_validator
|
|
|
|
from config.constants.posthog import (
|
|
DEFAULT_POSTHOG_BOUNCE_THRESHOLD,
|
|
DEFAULT_POSTHOG_BOUNCE_WINDOW,
|
|
DEFAULT_POSTHOG_TIMEOUT_SECONDS,
|
|
DEFAULT_POSTHOG_URL,
|
|
)
|
|
from config.strict_config import StrictConfigModel
|
|
|
|
|
|
class PostHogConfig(StrictConfigModel):
|
|
"""Normalized PostHog connection settings."""
|
|
|
|
base_url: str = DEFAULT_POSTHOG_URL
|
|
project_id: str = ""
|
|
personal_api_key: str = ""
|
|
timeout_seconds: float = Field(default=DEFAULT_POSTHOG_TIMEOUT_SECONDS, gt=0)
|
|
bounce_rate_threshold: float = Field(default=DEFAULT_POSTHOG_BOUNCE_THRESHOLD, ge=0.0, le=1.0)
|
|
bounce_rate_window: str = DEFAULT_POSTHOG_BOUNCE_WINDOW
|
|
integration_id: str = ""
|
|
|
|
@field_validator("base_url", mode="before")
|
|
@classmethod
|
|
def _normalize_base_url(cls, value: Any) -> str:
|
|
normalized = str(value or DEFAULT_POSTHOG_URL).strip()
|
|
return normalized or DEFAULT_POSTHOG_URL
|
|
|
|
@field_validator("project_id", mode="before")
|
|
@classmethod
|
|
def _normalize_project_id(cls, value: Any) -> str:
|
|
return str(value or "").strip()
|
|
|
|
@field_validator("personal_api_key", mode="before")
|
|
@classmethod
|
|
def _normalize_personal_api_key(cls, value: Any) -> str:
|
|
return str(value or "").strip()
|
|
|
|
@field_validator("bounce_rate_window", mode="before")
|
|
@classmethod
|
|
def _normalize_bounce_rate_window(cls, value: Any) -> str:
|
|
normalized = str(value or DEFAULT_POSTHOG_BOUNCE_WINDOW).strip()
|
|
normalized = normalized or DEFAULT_POSTHOG_BOUNCE_WINDOW
|
|
if not re.fullmatch(r"\d+[smhdw]", normalized):
|
|
raise ValueError("bounce_rate_window must match <number><unit>, e.g. 24h")
|
|
return normalized
|
|
|
|
@property
|
|
def api_base_url(self) -> str:
|
|
return self.base_url.rstrip("/")
|
|
|
|
@property
|
|
def auth_headers(self) -> dict[str, str]:
|
|
return {
|
|
"Authorization": f"Bearer {self.personal_api_key}",
|
|
"Accept": "application/json",
|
|
}
|
|
|
|
|
|
def build_posthog_config(raw: dict[str, Any] | None) -> PostHogConfig:
|
|
return PostHogConfig.model_validate(raw or {})
|
|
|
|
|
|
def posthog_config_from_env() -> PostHogConfig | None:
|
|
project_id = os.getenv("POSTHOG_PROJECT_ID", "").strip()
|
|
personal_api_key = os.getenv("POSTHOG_PERSONAL_API_KEY", "").strip()
|
|
|
|
if not project_id or not personal_api_key:
|
|
return None
|
|
|
|
return build_posthog_config(
|
|
{
|
|
"base_url": os.getenv("POSTHOG_BASE_URL", DEFAULT_POSTHOG_URL),
|
|
"project_id": project_id,
|
|
"personal_api_key": personal_api_key,
|
|
"timeout_seconds": os.getenv(
|
|
"POSTHOG_TIMEOUT_SECONDS", str(DEFAULT_POSTHOG_TIMEOUT_SECONDS)
|
|
),
|
|
"bounce_rate_threshold": os.getenv(
|
|
"POSTHOG_BOUNCE_THRESHOLD", str(DEFAULT_POSTHOG_BOUNCE_THRESHOLD)
|
|
),
|
|
"bounce_rate_window": os.getenv("POSTHOG_BOUNCE_WINDOW", DEFAULT_POSTHOG_BOUNCE_WINDOW),
|
|
}
|
|
)
|