: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
feat(aio): trace git branch chip (#124371)
Carlos Marchal4627ca1fca40
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex ca30a186fdec..6b2d973c0a4a 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -9828,10 +9828,18 @@ snapshots:hash: v1.k794b7964.daebccd14686a4ffa02937c8621dc74845153b053e2c5581ac18055fc85c2011.Jwh3UjTBshXuWKYsYsjgLLcwNkROjdAxPLk5xY7oQysscenes-app-ai-observability-trace-view-trace-summary-bar--narrow--light:hash: v1.k794b7964.89c5f822021e4c9c6581b1867d29be28fa87cf638297617fe1dd9f46c87310df.mx9UHOPdDLvPVcF_QQQRTgNGytxi_bTrB_AJBimtWjQ+ scenes-app-ai-observability-trace-view-trace-summary-bar--narrow-with-long-git-branch--dark:+ hash: v1.k794b7964.306fabde159267a2ffad36e356b4db293663b87a2ca8bf9c53575230fe4ccd41.-1ojgmfWHNK7Mv4-rNw_HlYOul55PvTX7utdFjsqDFs+ scenes-app-ai-observability-trace-view-trace-summary-bar--narrow-with-long-git-branch--light:+ hash: v1.k794b7964.5fb48e1a45f5107bcf2b8f8789c2e57cdb60634e0cc954c15a412be778999931.HMWug0zEltmvkTJKOwRL1CZtmoHrUD3OqV3u3EQ4Mmkscenes-app-ai-observability-trace-view-trace-summary-bar--short-id--dark:hash: v1.k794b7964.b0dd60321acfc66eff4b4fe61c0123016d6ef51e83d18e1a33989d71056cf4c4.rhGXCqb0ZHRrzjcvMjSYO0_vKIrG0vZRA9yacMU9g4Ascenes-app-ai-observability-trace-view-trace-summary-bar--short-id--light:hash: v1.k794b7964.bbfc40a18f0a11428e95c34e2783676e785e9e7730f88d7efb397ad11b954fad.A7axwdw43M17lj8qq6VSnmn7SyIXVP2oOIQzdvKA9m8+ scenes-app-ai-observability-trace-view-trace-summary-bar--with-git-branch--dark:+ hash: v1.k794b7964.f48c22bbab5113e9ef6290dad04daae1285be7f8932d41fa8ace16ace664e502.oxJblySth_77826dzwFkmd_PGo7EfwpvdJx8GlFzrgw+ scenes-app-ai-observability-trace-view-trace-summary-bar--with-git-branch--light:+ hash: v1.k794b7964.f6e85ad3ddc7ab047875da5570247b6bab1038c36f5ec2bd3d6be709296f9595.Z2RX9IwREaeGSEESRc0k_qVZIf3cwVzLtss3gO9CGh0scenes-app-ai-observability-trace-view-trace-timeline--agent-run--dark:hash: v1.k794b7964.96ceaef4cd703d36753e7b6071612547f6854073f804a52b50d9c7c6fd6d5718.i6JAjAgngbls2Ro2Z9eLdkQwjEiXw1Zt2Fnz32p1wVsscenes-app-ai-observability-trace-view-trace-timeline--agent-run--light:diff --git a/products/ai_observability/backend/facade/api.py b/products/ai_observability/backend/facade/api.pyindex 13948651a48b..92ccd5920aea 100644--- a/products/ai_observability/backend/facade/api.py+++ b/products/ai_observability/backend/facade/api.py@@ -20,6 +20,7 @@ from ..logic.traces.evaluation_result import EvaluationResultfrom ..logic.traces.evaluation_result_queries import load_evaluation_results, load_output_configsfrom ..logic.traces.evaluation_summary import EvaluationSummaryfrom ..logic.traces.events_fallback import fallback_window+from ..logic.traces.git import GitReffrom ..logic.traces.node import NodeEventfrom ..logic.traces.timeline import TimelineRowfrom ..logic.traces.trace import Trace@@ -147,9 +148,14 @@ def _to_trace(trace: Trace) -> contracts.Trace:thread_node_ids=trace.thread_node_ids,default_node_id=trace.default_node_id,node_ids_by_alias=trace.node_ids_by_alias,+ git=_to_git(trace.git) if trace.git is not None else None,)+def _to_git(ref: GitRef) -> contracts.TraceGit:+ return contracts.TraceGit(branch=ref.branch, repo=ref.repo)++def _to_node_detail(node_id: str, event: NodeEvent) -> contracts.TraceNodeDetail:keys = event.io_keysmetadata = event.metadatadiff --git a/products/ai_observability/backend/facade/contracts.py b/products/ai_observability/backend/facade/contracts.pyindex daea30090afd..bad7344392e8 100644--- a/products/ai_observability/backend/facade/contracts.py+++ b/products/ai_observability/backend/facade/contracts.py@@ -53,6 +53,11 @@ class TracePerson(Contract):label: str+class TraceGit(Contract):+ branch: str = Field(description="The git branch checked out when the trace ran.")+ repo: str | None = Field(description="The repository as owner/name, or null when the branch's event has none.")++class Trace(Contract):id: strname: str | None@@ -68,6 +73,10 @@ class Trace(Contract):thread_node_ids: list[str]default_node_id: strnode_ids_by_alias: dict[str, str]+ git: TraceGit | None = Field(+ description="The branch the trace's work ran on: the latest stamped branch other than main or master, else "+ "the first stamp. Null when no event carries a branch."+ )class TraceNodeIOKeys(Contract):diff --git a/products/ai_observability/backend/logic/traces/git.py b/products/ai_observability/backend/logic/traces/git.pynew file mode 100644index 000000000000..4ca5606cdac7--- /dev/null+++ b/products/ai_observability/backend/logic/traces/git.py@@ -0,0 +1,36 @@+from collections.abc import Iterable+from datetime import datetime+from typing import TYPE_CHECKING, Self++from posthog.dataclasses import frozen++if TYPE_CHECKING:+ from .trace_queries import TraceEventRow++# The repo's real default branch is not known here, so these two names stand in for it.+_DEFAULT_BRANCHES = frozenset({"main", "master"})+++def _stamp_order(row: "TraceEventRow") -> tuple[datetime, str]:+ # Ties break on the uuid so every read of the same rows picks the same event.+ return (row.timestamp, row.uuid)+++@frozen+class GitRef:+ branch: str+ repo: str | None+ seen_at: datetime++ @classmethod+ def from_rows(cls, rows: Iterable["TraceEventRow"]) -> Self | None:+ """The branch the trace's work ran on. A coding agent often starts on the default branch and creates the+ feature branch during the trace, so the latest stamp on another branch wins. A trace that never leaves the+ default branch keeps its first stamp."""+ stamped = [row for row in rows if row.git_branch]+ feature = [row for row in stamped if row.git_branch not in _DEFAULT_BRANCHES]+ row = max(feature, key=_stamp_order) if feature else min(stamped, key=_stamp_order, default=None)+ if row is None or row.git_branch is None:+ return None+ # The repo comes from the branch's own event, so a branch is never paired with another event's repo.+ return cls(branch=row.git_branch, repo=row.git_repo, seen_at=row.timestamp)diff --git a/products/ai_observability/backend/logic/traces/trace.py b/products/ai_observability/backend/logic/traces/trace.pyindex 1d8e34535269..8eb0fdb96655 100644--- a/products/ai_observability/backend/logic/traces/trace.py+++ b/products/ai_observability/backend/logic/traces/trace.py@@ -3,6 +3,7 @@ from datetime import datetimefrom functools import cached_propertyfrom .event import TraceEvent+from .git import GitReffrom .thread import pick_user_visible_generationfrom .timeline import Timelinefrom .trace_queries import PersonRow, TraceEventRow@@ -85,6 +86,10 @@ class Trace:aliases.setdefault(alias, event.id)return aliases+ @cached_property+ def git(self) -> GitRef | None:+ return GitRef.from_rows(event.row for event in self.events)+@propertydef person_label(self) -> str | None:if self.person is None or not self.person.distinct_id:diff --git a/products/ai_observability/backend/logic/traces/trace_queries.py b/products/ai_observability/backend/logic/traces/trace_queries.pyindex fb87916d6559..aeadaaff5a65 100644--- a/products/ai_observability/backend/logic/traces/trace_queries.py+++ b/products/ai_observability/backend/logic/traces/trace_queries.py@@ -60,6 +60,8 @@ class TraceEventRow:is_error: boolerror_is_truthy: boolingestion_source: str | None+ git_branch: str | None+ git_repo: str | None@frozen@@ -130,6 +132,8 @@ _SELECTED: dict[str, ast.Expr] = {# The native error column extracts $ai_error as a string, which loses the JSON type that decides truthiness."error_raw": _raw_property("$ai_error"),"ingestion_source": ast.Field(chain=["properties", "$ai_ingestion_source"]),+ "git_branch": ast.Field(chain=["properties", "$ai_git_branch"]),+ "git_repo": ast.Field(chain=["properties", "$ai_git_repo"]),}@@ -322,6 +326,8 @@ def _trace_event_row(values: Sequence[Any]) -> TraceEventRow:is_error=read_flag(raw["is_error"]),error_is_truthy=is_truthy_json(raw["error_raw"]),ingestion_source=read_text(raw["ingestion_source"]),+ git_branch=read_text(raw["git_branch"]),+ git_repo=read_text(raw["git_repo"]),)diff --git a/products/ai_observability/backend/tests/logic/traces/rows.py b/products/ai_observability/backend/tests/logic/traces/rows.pyindex 0174326b5e1b..e90e9bf3fd01 100644--- a/products/ai_observability/backend/tests/logic/traces/rows.py+++ b/products/ai_observability/backend/tests/logic/traces/rows.py@@ -34,6 +34,8 @@ def make_row(**overrides: Any) -> TraceEventRow:"is_error": False,"error_is_truthy": False,"ingestion_source": None,+ "git_branch": None,+ "git_repo": None,}return TraceEventRow(**{**fields, **overrides})diff --git a/products/ai_observability/backend/tests/logic/traces/test_git.py b/products/ai_observability/backend/tests/logic/traces/test_git.pynew file mode 100644index 000000000000..0ddf79937e6f--- /dev/null+++ b/products/ai_observability/backend/tests/logic/traces/test_git.py@@ -0,0 +1,63 @@+from datetime import datetime, timedelta++from parameterized import parameterized++from products.ai_observability.backend.logic.traces.git import GitRef+from products.ai_observability.backend.logic.traces.trace_queries import TraceEventRow++from .rows import T0, make_row++T1 = T0 + timedelta(seconds=30)+++def _row(uuid: str, timestamp: datetime, branch: str | None = None, repo: str | None = None) -> TraceEventRow:+ return make_row(uuid=uuid, timestamp=timestamp, git_branch=branch, git_repo=repo)+++ [+ ("no stamp", [_row("a", T0)], None),+ (+ "the latest stamped event wins",+ [_row("a", T0, "main"), _row("b", T1, "feat/rag", "acme/app")],+ GitRef(branch="feat/rag", repo="acme/app", seen_at=T1),+ ),+ (+ "input order does not matter",+ [_row("b", T1, "feat/rag", "acme/app"), _row("a", T0, "main")],+ GitRef(branch="feat/rag", repo="acme/app", seen_at=T1),+ ),+ (+ "a repo without a branch is no stamp",+ [_row("a", T0, "feat/rag"), _row("b", T1, None, "acme/other")],+ GitRef(branch="feat/rag", repo=None, seen_at=T0),+ ),+ (+ "the repo comes from the branch's own event",+ [_row("a", T0, "feat/one", "acme/app"), _row("b", T1, "feat/two")],+ GitRef(branch="feat/two", repo=None, seen_at=T1),+ ),+ (+ "equal timestamps pick the greater uuid",+ [_row("b", T0, "feat/b"), _row("a", T0, "feat/a")],+ GitRef(branch="feat/b", repo=None, seen_at=T0),+ ),+ (+ "equal timestamps in the other order",+ [_row("a", T0, "feat/a"), _row("b", T0, "feat/b")],+ GitRef(branch="feat/b", repo=None, seen_at=T0),+ ),+ (+ "a later default branch keeps the feature branch",+ [_row("a", T0, "feat/rag"), _row("b", T1, "main")],+ GitRef(branch="feat/rag", repo=None, seen_at=T0),+ ),+ (+ "only default branches, the earliest stamp wins",+ [_row("b", T1, "master", "acme/later"), _row("a", T0, "main", "acme/first")],+ GitRef(branch="main", repo="acme/first", seen_at=T0),+ ),+ ]+)+def test_from_rows(_name: str, rows: list[TraceEventRow], expected: GitRef | None) -> None:+ assert GitRef.from_rows(rows) == expecteddiff --git a/products/ai_observability/backend/tests/logic/traces/test_trace_queries.py b/products/ai_observability/backend/tests/logic/traces/test_trace_queries.pyindex aa133f67436a..f4e16b4d69ea 100644--- a/products/ai_observability/backend/tests/logic/traces/test_trace_queries.py+++ b/products/ai_observability/backend/tests/logic/traces/test_trace_queries.py@@ -110,15 +110,28 @@ class TestLoadTrace(TraceEventsMixin, ClickhouseTestMixin, BaseTest):assert loaded.rows[0].latency == 1.0assert [row.uuid for row in loaded.rows if row.error_is_truthy] == [uuids[0]]- def test_ingested_error_and_token_values_read_like_the_legacy_view(self) -> None:- self._ingest("00000000-0000-0000-0000-000000000001", {"$ai_error": "", "$ai_input_tokens": {"total": 7}})- self._ingest("00000000-0000-0000-0000-000000000002", {"$ai_error": {"message": "boom"}, "$ai_input_tokens": 3})+ def test_ingested_values_read_like_the_legacy_view(self) -> None:+ self._ingest(+ "00000000-0000-0000-0000-000000000001",+ {"$ai_error": "", "$ai_input_tokens": {"total": 7}, "$ai_git_branch": ""},+ )+ self._ingest(+ "00000000-0000-0000-0000-000000000002",+ {+ "$ai_error": {"message": "boom"},+ "$ai_input_tokens": 3,+ "$ai_git_branch": "feat/rag",+ "$ai_git_repo": "acme/app",+ },+ )rows = load_trace(self.team, None, "trace-1", None).rows- assert sorted((row.uuid, row.error_is_truthy, row.input_tokens) for row in rows) == [- ("00000000-0000-0000-0000-000000000001", False, 7),- ("00000000-0000-0000-0000-000000000002", True, 3),+ assert sorted(+ (row.uuid, row.error_is_truthy, row.input_tokens, row.git_branch, row.git_repo) for row in rows+ ) == [+ ("00000000-0000-0000-0000-000000000001", False, 7, None, None),+ ("00000000-0000-0000-0000-000000000002", True, 3, "feat/rag", "acme/app"),]def test_person_comes_from_the_trace_event_distinct_id(self) -> None:@@ -209,7 +222,11 @@ class TestLoadTraceNode(TraceEventsMixin, ClickhouseTestMixin, BaseTest):class TestEventsFallback(TraceEventsMixin, ClickhouseTestMixin, BaseTest):@parameterized.expand([("with a hint", T0), ("without a hint", None)])def test_falls_back_to_events(self, _name: str, timestamp_hint: datetime | None) -> None:- old_span: dict[str, object] = {"$ai_span_name": "old", "$ai_error": {"message": "boom"}}+ old_span: dict[str, object] = {+ "$ai_span_name": "old",+ "$ai_error": {"message": "boom"},+ "$ai_git_branch": "feat/rag",+ }clean_span: dict[str, object] = {"$ai_error": "", "$ai_input_tokens": {"total": 7}}bulk_create_events([@@ -220,9 +237,11 @@ class TestEventsFallback(TraceEventsMixin, ClickhouseTestMixin, BaseTest):loaded = load_trace(self.team, None, "trace-1", timestamp_hint)- assert sorted((row.uuid, row.span_name, row.error_is_truthy, row.input_tokens) for row in loaded.rows) == [- ("00000000-0000-0000-0000-000000000001", "old", True, None),- ("00000000-0000-0000-0000-000000000002", None, False, 7),+ assert sorted(+ (row.uuid, row.span_name, row.error_is_truthy, row.input_tokens, row.git_branch) for row in loaded.rows+ ) == [+ ("00000000-0000-0000-0000-000000000001", "old", True, None, "feat/rag"),+ ("00000000-0000-0000-0000-000000000002", None, False, 7, None),]def test_hint_bounds_the_fallback_window(self) -> None:diff --git a/products/ai_observability/backend/tests/test_contracts.py b/products/ai_observability/backend/tests/test_contracts.pyindex f7a8499904ef..6e9d39b87a5f 100644--- a/products/ai_observability/backend/tests/test_contracts.py+++ b/products/ai_observability/backend/tests/test_contracts.py@@ -31,6 +31,7 @@ def test_trace_dumps_declared_fields_in_camel_case_and_every_field_is_required_ithread_node_ids=[],default_node_id="trace-1",node_ids_by_alias={},+ git=None,)dumped = trace.model_dump(mode="json", by_alias=True)@@ -50,6 +51,7 @@ def test_trace_dumps_declared_fields_in_camel_case_and_every_field_is_required_i"threadNodeIds","defaultNodeId","nodeIdsByAlias",+ "git",}assert dumped["totals"]["cacheWriteTokens"] is Noneassert dumped["person"] == {"distinctId": "user-1", "label": "[email protected]"}diff --git a/products/ai_observability/backend/tests/test_trace_views.py b/products/ai_observability/backend/tests/test_trace_views.pyindex e0c7141cdbe9..1df634c22cbd 100644--- a/products/ai_observability/backend/tests/test_trace_views.py+++ b/products/ai_observability/backend/tests/test_trace_views.py@@ -31,7 +31,7 @@ QUESTION = [{"role": "user", "content": "Why did my invoice go up?"}]ANSWER = [{"role": "assistant", "content": "Two seats were added."}]-def _create_trace(team: Team, trace_id: str = "trace-1") -> None:+def _create_trace(team: Team, trace_id: str = "trace-1", *, extra_properties: dict[str, object] | None = None) -> None:bulk_create_ai_events([{@@ -40,7 +40,12 @@ def _create_trace(team: Team, trace_id: str = "trace-1") -> None:"distinct_id": "user-1","team": team,"timestamp": T0,- "properties": {"$ai_trace_id": trace_id, "$ai_parent_id": trace_id, "$ai_input_tokens": 3},+ "properties": {+ "$ai_trace_id": trace_id,+ "$ai_parent_id": trace_id,+ "$ai_input_tokens": 3,+ **(extra_properties or {}),+ },}])@@ -102,6 +107,22 @@ def _create_evaluation_result(team: Team) -> None:)+def _restrict_property(test: APIBaseTest, name: str) -> None:+ test.organization.available_product_features = [+ {"key": AvailableFeature.PROPERTY_ACCESS_CONTROL, "name": AvailableFeature.PROPERTY_ACCESS_CONTROL}+ ]+ test.organization.save()+ definition = PropertyDefinition.objects.create(+ team=test.team, name=name, property_type="String", type=PropertyDefinition.Type.EVENT+ )+ PropertyAccessControl.objects.create(+ team=test.team,+ property_definition=definition,+ organization_member=test.organization_membership,+ access_level=PropertyAccessLevel.NONE.value,+ )++def _encode(trace_id: str) -> str:return base64.urlsafe_b64encode(trace_id.encode()).decode().rstrip("=")@@ -125,6 +146,21 @@ class TestTraceViewSet(ClickhouseTestMixin, APIBaseTest):assert body["defaultNodeId"] == "00000000-0000-0000-0000-000000000001"assert body["nodeIdsByAlias"] == {}+ @parameterized.expand(+ [+ ("visible", False, {"branch": "feat/rag", "repo": "acme/app"}),+ ("restricted for the viewer", True, None),+ ]+ )+ def test_returns_the_git_branch_unless_the_viewer_may_not_read_it(+ self, _name: str, restricted: bool, expected: dict[str, str] | None+ ) -> None:+ if restricted:+ _restrict_property(self, "$ai_git_branch")+ _create_trace(self.team, extra_properties={"$ai_git_branch": "feat/rag", "$ai_git_repo": "acme/app"})++ assert self.client.get(self._url(_encode("trace-1"))).json()["git"] == expected+@parameterized.expand([("unknown trace", False), ("another team's trace", True)])def test_not_found(self, _name: str, other_team_owns_it: bool) -> None:if other_team_owns_it:@@ -241,19 +277,7 @@ class TestTraceNodeView(ClickhouseTestMixin, APIBaseTest):assert self.client.get(url).status_code == 400def test_masks_properties_the_viewer_may_not_read(self) -> None:- self.organization.available_product_features = [- {"key": AvailableFeature.PROPERTY_ACCESS_CONTROL, "name": AvailableFeature.PROPERTY_ACCESS_CONTROL}- ]- self.organization.save()- definition = PropertyDefinition.objects.create(- team=self.team, name="secret_plan", property_type="String", type=PropertyDefinition.Type.EVENT- )- PropertyAccessControl.objects.create(- team=self.team,- property_definition=definition,- organization_member=self.organization_membership,- access_level=PropertyAccessLevel.NONE.value,- )+ _restrict_property(self, "secret_plan")_create_node_trace(self.team, extra_properties={"secret_plan": "enterprise"})properties = self.client.get(self._url("trace-1", _encode(GENERATION))).json()["event"]["properties"]@@ -304,22 +328,7 @@ class TestTraceEvaluationsView(ClickhouseTestMixin, APIBaseTest):assert self.client.get(self._url("trace-1")).status_code == 400def test_masks_properties_the_viewer_may_not_read(self) -> None:- self.organization.available_product_features = [- {"key": AvailableFeature.PROPERTY_ACCESS_CONTROL, "name": AvailableFeature.PROPERTY_ACCESS_CONTROL}- ]- self.organization.save()- definition = PropertyDefinition.objects.create(- team=self.team,- name="$ai_evaluation_reasoning",- property_type="String",- type=PropertyDefinition.Type.EVENT,- )- PropertyAccessControl.objects.create(- team=self.team,- property_definition=definition,- organization_member=self.organization_membership,- access_level=PropertyAccessLevel.NONE.value,- )+ _restrict_property(self, "$ai_evaluation_reasoning")_create_evaluation_result(self.team)result = self.client.get(self._url(_encode("trace-1"))).json()["results"][0]diff --git a/products/ai_observability/frontend/generated/api.schemas.ts b/products/ai_observability/frontend/generated/api.schemas.tsindex 64bcebb8c7ec..90cf96fabb03 100644--- a/products/ai_observability/frontend/generated/api.schemas.ts+++ b/products/ai_observability/frontend/generated/api.schemas.ts@@ -1405,6 +1405,13 @@ export interface TraceTimelineRowApi {hasError: boolean}+export interface TraceGitApi {+ /** The git branch checked out when the trace ran. */+ branch: string+ /** The repository as owner/name, or null when the branch's event has none. */+ repo: string | null+}+export interface TraceApi {id: stringname: string | null@@ -1420,6 +1427,8 @@ export interface TraceApi {threadNodeIds: string[]defaultNodeId: stringnodeIdsByAlias: TraceApiNodeIdsByAlias+ /** The branch the trace's work ran on: the latest stamped branch other than main or master, else the first stamp. Null when no event carries a branch. */+ git: TraceGitApi | null}export type TraceEvaluationResultOutcomeEnumApi =diff --git a/products/ai_observability/frontend/redesign/trace/TraceScene.tsx b/products/ai_observability/frontend/redesign/trace/TraceScene.tsxindex f3121745c200..a84837623e22 100644--- a/products/ai_observability/frontend/redesign/trace/TraceScene.tsx+++ b/products/ai_observability/frontend/redesign/trace/TraceScene.tsx@@ -21,6 +21,7 @@ type ReadyValues = Pick<| 'timeline'| 'evalsChip'| 'evalOutcomesByNode'+ | 'gitBranch'>interface ReadyActions {@@ -42,6 +43,7 @@ function toReadyProps(values: ReadyValues, actions: ReadyActions): TraceViewReadsummary: {...values.summary,evals: values.evalsChip ? { chip: values.evalsChip, onClick: actions.showFailingEvals } : null,+ git: values.gitBranch,},mode: values.mode,onModeChange: actions.setMode,@@ -86,6 +88,7 @@ export function TraceScene(): JSX.Element {timeline,evalsChip,evalOutcomesByNode,+ gitBranch,} = useValues(logic)const actions = useActions(logic)@@ -106,6 +109,7 @@ export function TraceScene(): JSX.Element {timeline,evalsChip,evalOutcomesByNode,+ gitBranch,},actions)diff --git a/products/ai_observability/frontend/redesign/trace/adapter/testFixtures.ts b/products/ai_observability/frontend/redesign/trace/adapter/testFixtures.tsindex dc35d8d2ac2c..a58568c5470e 100644--- a/products/ai_observability/frontend/redesign/trace/adapter/testFixtures.ts+++ b/products/ai_observability/frontend/redesign/trace/adapter/testFixtures.ts@@ -122,6 +122,7 @@ export function makeTraceResource(overrides: Partial<TraceApi> = {}): TraceApi {threadNodeIds: ['gen-2'],defaultNodeId: 'trace-1',nodeIdsByAlias: {},+ git: null,...overrides,}}diff --git a/products/ai_observability/frontend/redesign/trace/adapter/traceSceneWiring.test.tsx b/products/ai_observability/frontend/redesign/trace/adapter/traceSceneWiring.test.tsxindex cf5c67df3997..f621ec78e0b1 100644--- a/products/ai_observability/frontend/redesign/trace/adapter/traceSceneWiring.test.tsx+++ b/products/ai_observability/frontend/redesign/trace/adapter/traceSceneWiring.test.tsx@@ -148,6 +148,20 @@ describe('TraceScene', () => {expect(await findByText('Cites a source')).toBeTruthy()})+ it('shows the trace git branch in the summary bar', async () => {+ useMocks({+ get: {+ [TRACE_URL]: () => [+ 200,+ makeTraceResource({ defaultNodeId: 'gen-2', git: { branch: 'feat/rag', repo: 'acme/app' } }),+ ],+ },+ })+ const { findByText } = renderNewView()++ expect(await findByText('feat/rag')).toBeTruthy()+ })+it.each([true, false])('offers add to dataset on the step only when datasets are on (%s)', async (enabled) => {const { findByText, queryByText } = renderNewView({ [DATASETS_FLAG]: enabled })diff --git a/products/ai_observability/frontend/redesign/trace/adapter/traceViewAdapterLogic.ts b/products/ai_observability/frontend/redesign/trace/adapter/traceViewAdapterLogic.tsindex 1531b950a4b8..acd4e8703975 100644--- a/products/ai_observability/frontend/redesign/trace/adapter/traceViewAdapterLogic.ts+++ b/products/ai_observability/frontend/redesign/trace/adapter/traceViewAdapterLogic.ts@@ -8,7 +8,13 @@ import { teamLogic } from 'scenes/teamLogic'import { aiObservabilityTraceLogic } from '../../../aiObservabilityTraceLogic'import type { SaveToDatasetButtonProps } from '../../../datasets/SaveToDatasetButton'-import type { TraceEvaluationResultsApi, TraceNodeApi, TraceTimelineRowApi } from '../../../generated/api.schemas'+import type {+ TraceApi,+ TraceEvaluationResultsApi,+ TraceNodeApi,+ TraceTimelineRowApi,+} from '../../../generated/api.schemas'+import { GitBranchChipProps } from '../components/GitBranchChip'import { TraceHeaderProps } from '../components/TraceHeader'import { TraceSummaryBarProps } from '../components/TraceSummaryBar'import { TraceViewStatus, traceViewLogic } from '../traceViewLogic'@@ -60,6 +66,7 @@ export interface traceViewAdapterLogicValues {rows: TraceTimelineRowApi[]totalMs: number} // traceViewLogic+ trace: TraceApi | null // traceViewLogictraceHasError: boolean // traceViewLogictraceName: string // traceViewLogictree: TraceNodeApi[] // traceViewLogic@@ -70,6 +77,7 @@ export interface traceViewAdapterLogicValues {detailTab: NodeDetailTabevalOutcomesByNode: Record<string, EvalRollupOutcome>evalsChip: EvalsChipData | null+ gitBranch: GitBranchChipProps | nullheader: TraceHeaderPropsmode: TraceModeselectedNodeId: string@@ -99,11 +107,11 @@ export interface traceViewAdapterLogicActions {trigger: import('../types').NodeLoadTrigger} // traceViewLogicloadTraceSuccess: (- trace: import('../../../generated/api.schemas').TraceApi,+ trace: TraceApi,payload?: any) => {payload?: any- trace: import('../../../generated/api.schemas').TraceApi+ trace: TraceApi} // traceViewLogicprefetchNode: (id: string) => {id: string@@ -180,6 +188,7 @@ export interface traceViewAdapterLogicMeta {) => ConversationStateevalsChip: (evaluationResults: TraceEvaluationResultsApi | null) => EvalsChipData | nullevalOutcomesByNode: (evaluationResults: TraceEvaluationResultsApi | null) => Record<string, EvalRollupOutcome>+ gitBranch: (trace: TraceApi | null) => GitBranchChipProps | nullcanViewInThread: (selectedNodeId: string, threadNodeIds: string[], traceId: string) => boolean}}@@ -219,6 +228,7 @@ export const traceViewAdapterLogic = kea<traceViewAdapterLogicType>(['nodeIdsByAlias','evaluationResults','evaluationResultsFailed',+ 'trace',],aiObservabilityTraceLogic,['eventId', 'initialTab', 'olderTraceId', 'olderTimestamp', 'newerTraceId', 'newerTimestamp'],@@ -397,6 +407,7 @@ export const traceViewAdapterLogic = kea<traceViewAdapterLogicType>([(evaluationResults: TraceEvaluationResultsApi | null): Record<string, EvalRollupOutcome> =>evaluationResults ? toEvalOutcomesByNode(evaluationResults.summary) : {},],+ gitBranch: [(s) => [s.trace], (trace: TraceApi | null): GitBranchChipProps | null => trace?.git ?? null],canViewInThread: [(s, p) => [s.selectedNodeId, s.threadNodeIds, p.traceId],(selectedNodeId: string, threadNodeIds: string[], traceId: string): boolean =>diff --git a/products/ai_observability/frontend/redesign/trace/components/GitBranchChip.tsx b/products/ai_observability/frontend/redesign/trace/components/GitBranchChip.tsxnew file mode 100644index 000000000000..239c7601e102--- /dev/null+++ b/products/ai_observability/frontend/redesign/trace/components/GitBranchChip.tsx@@ -0,0 +1,16 @@+import { IconGitBranch } from '@posthog/icons'+import { LemonTag, Tooltip } from '@posthog/lemon-ui'++import type { TraceGitApi } from '../../../generated/api.schemas'++export type GitBranchChipProps = TraceGitApi++export function GitBranchChip({ branch, repo }: GitBranchChipProps): JSX.Element {+ return (+ <Tooltip title={repo ? `Git branch ${branch} in ${repo}` : `Git branch ${branch}`}>+ <LemonTag icon={<IconGitBranch />} weight="normal" data-attr="trace-view-git-branch-chip">+ <span className="block max-w-60 truncate font-mono">{branch}</span>+ </LemonTag>+ </Tooltip>+ )+}diff --git a/products/ai_observability/frontend/redesign/trace/components/TraceSummaryBar.stories.tsx b/products/ai_observability/frontend/redesign/trace/components/TraceSummaryBar.stories.tsxindex 2307d269dddf..3ddd01f9445d 100644--- a/products/ai_observability/frontend/redesign/trace/components/TraceSummaryBar.stories.tsx+++ b/products/ai_observability/frontend/redesign/trace/components/TraceSummaryBar.stories.tsx@@ -25,3 +25,14 @@ export const Anonymous: Story = { ...wide, args: { person: null } }export const ShortId: Story = { ...wide, args: { traceId: 'notes-run-42' } }export const LongSlugId: Story = { ...wide, args: { traceId: 'support-chat-session-2026-09-01-weekly-billing-review' } }export const Narrow: Story = { decorators: [withWidth(420)] }++export const WithGitBranch: Story = {+ ...wide,+ args: { git: { branch: 'feat/billing-answers', repo: 'acme/support-bot' } },+}+export const NarrowWithLongGitBranch: Story = {+ decorators: [withWidth(420)],+ args: {+ git: { branch: 'carol/feat-answer-billing-questions-with-invoice-history-and-seat-changes', repo: null },+ },+}diff --git a/products/ai_observability/frontend/redesign/trace/components/TraceSummaryBar.tsx b/products/ai_observability/frontend/redesign/trace/components/TraceSummaryBar.tsxindex 6aca2369127a..5e7c6489761b 100644--- a/products/ai_observability/frontend/redesign/trace/components/TraceSummaryBar.tsx+++ b/products/ai_observability/frontend/redesign/trace/components/TraceSummaryBar.tsx@@ -5,6 +5,7 @@ import { TZLabel } from 'lib/components/TZLabel'import type { TraceNodeStatsApi } from '../../../generated/api.schemas'import { LabeledLink } from '../types'import { EvalsChip, EvalsChipProps } from './EvalsChip'+import { GitBranchChip, GitBranchChipProps } from './GitBranchChip'import { NodeStatsLine } from './NodeStatsLine'import { PersonChip } from './PersonChip'import { TraceIdChip } from './TraceIdChip'@@ -15,6 +16,7 @@ export interface TraceSummaryBarProps {person: LabeledLink | nulltotals: TraceNodeStatsApievals?: EvalsChipProps | null+ git?: GitBranchChipProps | null}export function TraceSummaryBar({@@ -23,6 +25,7 @@ export function TraceSummaryBar({person,totals,evals = null,+ git = null,}: TraceSummaryBarProps): JSX.Element {return (<div className="@container">@@ -39,6 +42,7 @@ export function TraceSummaryBar({</LemonTag>{person ? <PersonChip person={person} /> : null}{evals ? <EvalsChip {...evals} /> : null}+ {git ? <GitBranchChip {...git} /> : null}</div><NodeStatsLine stats={totals} className="@2xl:ml-auto" /></div>diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 7e90413379fa..006788236614 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -121010,6 +121010,13 @@ export namespace Schemas {hasError: boolean;}+ export interface TraceGit {+ /** The git branch checked out when the trace ran. */+ branch: string;+ /** The repository as owner/name, or null when the branch's event has none. */+ repo: string | null;+ }+export interface Trace {id: string;name: string | null;@@ -121025,6 +121032,8 @@ export namespace Schemas {threadNodeIds: string[];defaultNodeId: string;nodeIdsByAlias: TraceNodeIdsByAlias;+ /** The branch the trace's work ran on: the latest stamped branch other than main or master, else the first stamp. Null when no event carries a branch. */+ git: TraceGit | null;}export type TraceEvaluationResultOutcomeEnum = typeof TraceEvaluationResultOutcomeEnum[keyof typeof TraceEvaluationResultOutcomeEnum];