: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
chore(ci): dual-emit per-test traces to second project (#72910)
Raúl Negrón-Oterod0305ffcc589
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex e6dd1c991206..1e346ed5508c 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -33,7 +33,8 @@# dependency-result table — depot-exempt for the same reason as the other uploads.# - report-test-timings: canonical emits per-test OTLP spans from the uploaded JUnit. The shadow# strips artifact uploads (above) and posts no telemetry, so the whole job is depot-exempt —-# changes confined to it (script deps, the reporter's availability guard) need no depot bump.+# changes confined to it (script deps, the reporter's availability guard, emission secret+# plumbing such as dual-project tokens) need no depot bump.# - OpenAPI types: the check-openapi-types job is folded into check-migrations as a# check-only step (drift still fails the run); only its auto-commit side effect is dropped# - events_json variants: the shadow never doubles the matrix (no RUN_NEW_EVENTS_SCHEMAdiff --git a/.github/scripts/report_test_timings.py b/.github/scripts/report_test_timings.pyindex 4a0d33addb6c..0790bc39707e 100644--- a/.github/scripts/report_test_timings.py+++ b/.github/scripts/report_test_timings.py@@ -39,7 +39,7 @@ import hashlibimport loggingimport secretsimport argparse-from collections.abc import Callable+from collections.abc import Callable, Mappingfrom dataclasses import dataclassfrom datetime import UTC, datetime, timedeltafrom functools import cache@@ -552,6 +552,16 @@ def _emit_shard_span(tracer: trace.Tracer, shard: Shard, root_name: str, owner_o# ---------- CLI ----------+# Each token receives an identical copy of the spans (trace IDs are deterministic) —+# transitional dual emission while CI telemetry moves projects.+TOKEN_ENV_VARS = ("POSTHOG_DEVEX_PROJECT_API_TOKEN", "POSTHOG_CI_TRACES_EXTRA_TOKEN")+++def emission_tokens(env: Mapping[str, str]) -> list[str]:+ """Distinct project API tokens to emit to, in ``TOKEN_ENV_VARS`` order."""+ tokens = (env.get(var, "") for var in TOKEN_ENV_VARS)+ return list(dict.fromkeys(token for token in tokens if token))+def parse_args(argv: list[str]) -> argparse.Namespace:parser = argparse.ArgumentParser(description=__doc__.splitlines()[0] if __doc__ else "")@@ -611,16 +621,18 @@ def main(argv: list[str] | None = None) -> int:)return 0- token = os.environ.get("POSTHOG_DEVEX_PROJECT_API_TOKEN", "")- if not token:- logger.warning("POSTHOG_DEVEX_PROJECT_API_TOKEN not set; skipping emit")+ tokens = emission_tokens(os.environ)+ if not tokens:+ logger.warning("none of %s set; skipping emit", ", ".join(TOKEN_ENV_VARS))return 0- try:- emit_traces(shards, args.otlp_endpoint, token)- logger.info("emitted %d testcase spans to %s", post_filter, args.otlp_endpoint)- except Exception:- logger.exception("failed to emit traces")+ for token in tokens:+ # Per-token isolation: one project's ingest failing must not block the other's.+ try:+ emit_traces(shards, args.otlp_endpoint, token)+ logger.info("emitted %d testcase spans to %s", post_filter, args.otlp_endpoint)+ except Exception:+ logger.exception("failed to emit traces")return 0diff --git a/.github/scripts/test_report_test_timings.py b/.github/scripts/test_report_test_timings.pyindex b467b8f4b47a..f8f147374c12 100644--- a/.github/scripts/test_report_test_timings.py+++ b/.github/scripts/test_report_test_timings.py@@ -535,3 +535,18 @@ def test_job_trace_key_distinguishes_jobs() -> None:assert key(_artifact("backend", "core", 1)) != key(_artifact("backend", "core", 2))assert key(_artifact("backend", "core", 1)) != key(_artifact("backend", "temporal", 1))assert key(_artifact("backend", "core", 1)) == key(_artifact("backend", "core", 1))+++ "env,expected",+ [+ ({"POSTHOG_DEVEX_PROJECT_API_TOKEN": "phc_a", "POSTHOG_CI_TRACES_EXTRA_TOKEN": "phc_b"}, ["phc_a", "phc_b"]),+ ({"POSTHOG_DEVEX_PROJECT_API_TOKEN": "phc_a", "POSTHOG_CI_TRACES_EXTRA_TOKEN": "phc_a"}, ["phc_a"]),+ ({"POSTHOG_DEVEX_PROJECT_API_TOKEN": "phc_a"}, ["phc_a"]),+ ({"POSTHOG_CI_TRACES_EXTRA_TOKEN": "phc_b"}, ["phc_b"]),+ ({"POSTHOG_DEVEX_PROJECT_API_TOKEN": "", "POSTHOG_CI_TRACES_EXTRA_TOKEN": ""}, []),+ ({}, []),+ ],+)+def test_emission_tokens(env: dict[str, str], expected: list[str]) -> None:+ assert report_test_timings.emission_tokens(env) == expecteddiff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 8afe1483c2f0..73517f3e3a89 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -3555,6 +3555,8 @@ jobs:continue-on-error: trueenv:POSTHOG_DEVEX_PROJECT_API_TOKEN: ${{ secrets.POSTHOG_DEVEX_PROJECT_API_TOKEN }}+ # dual emission while per-test traces migrate to the project behind POSTHOG_API_TOKEN+ POSTHOG_CI_TRACES_EXTRA_TOKEN: ${{ secrets.POSTHOG_API_TOKEN }}POSTHOG_OTLP_TRACES_ENDPOINT: ${{ vars.POSTHOG_OTLP_TRACES_ENDPOINT || 'https://us.i.posthog.com/i/v1/traces' }}run: |uv run --script .github/scripts/report_test_timings.py \