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.

feat(evals): tag eval events with the run configuration (#113642)

Lucas Faria0b78a9975018
diff --git a/docs/internal/ai-offline-evaluation-reporting.md b/docs/internal/ai-offline-evaluation-reporting.md
index e99fc4500be2..118cbe5e1846 100644
--- a/docs/internal/ai-offline-evaluation-reporting.md
+++ b/docs/internal/ai-offline-evaluation-reporting.md
@@ -19,7 +19,7 @@ Ordinary PostHog SDK clients and trace clients retain their existing `TEST` and
## Result contents and scope
Each event contains the existing experiment, case, and metric properties, including input, output, and expected values when available.
-Result reporting uses the existing event schema.
+Each event also carries the run's configuration: `agent_model`, `trials`, `git_sha`, `git_dirty`, and for sandboxed runs `agent_runtime`, `skill_delivery`, and `reasoning_effort`.
## Postgres experiment ingestion
diff --git a/products/posthog_ai/eval_harness/README.md b/products/posthog_ai/eval_harness/README.md
index c83f10db66b3..7e3af9d0e964 100644
--- a/products/posthog_ai/eval_harness/README.md
+++ b/products/posthog_ai/eval_harness/README.md
@@ -102,7 +102,7 @@ The experiment metadata records `skill_delivery`; compare the shared `expected_s
`--agent-runtime codex` runs the same agent-server with OpenAI's Codex harness instead of Claude, defaulting the model to `gpt-5.5`.
It requires `LLM_GATEWAY_OPENAI_API_KEY` in the environment (checked by preflight), which the harness's LLM gateway uses to proxy the agent's OpenAI calls.
-Experiment names don't change with the runtime or skill delivery. Each Braintrust experiment records `agent_runtime`, `agent_model`, and `skill_delivery` in its metadata, so compare cross-run scores within one runtime and delivery mode.
+Experiment names don't change with the runtime or skill delivery. Each Braintrust experiment and every PostHog event records `agent_model`, `trials`, `git_sha` and `git_dirty`. Sandboxed runs add `agent_runtime`, `skill_delivery` and `reasoning_effort`, so compare cross-run scores within one runtime and delivery mode.
## Providers
diff --git a/products/posthog_ai/eval_harness/base.py b/products/posthog_ai/eval_harness/base.py
index 52dd89d6454c..56d2d15e7442 100644
--- a/products/posthog_ai/eval_harness/base.py
+++ b/products/posthog_ai/eval_harness/base.py
@@ -24,7 +24,7 @@ from .log_parser import describe_tool_use
from .log_sink import append_case_scores, build_case_dir, write_case_logs
from .runner import AgentNeverRanError, EvalCaseResult, agent_never_ran, run_eval_case
from .scorers import ExitCodeZero, wrap_scorers
-from .trace_events import emit_evaluation_events, emit_trace_events, emit_trace_root
+from .trace_events import RunMetadata, emit_evaluation_events, emit_trace_events, emit_trace_root
if TYPE_CHECKING:
from .harness.context import EvalContext
@@ -182,6 +182,7 @@ class _BaseEvalRun:
experiment_name,
self.agent_trace_id_lookup,
trace_namespace=self.trace_namespace,
+ run_metadata=self._experiment_metadata(),
)
else:
self.active_scorers = list(scorers)
@@ -221,8 +222,14 @@ class _BaseEvalRun:
def _project_name(self) -> str:
return self.experiment_name
- def _experiment_metadata(self) -> dict[str, Any]:
- return {"agent_model": self.ctx.agent_model}
+ def _experiment_metadata(self) -> RunMetadata:
+ """The run's configuration, sent to the engine and stamped on every PostHog event."""
+ return {
+ "agent_model": self.ctx.agent_model,
+ "trials": self.ctx.trials,
+ "git_sha": self.ctx.git_sha,
+ "git_dirty": self.ctx.git_dirty,
+ }
async def _task(self, input: dict[str, Any], hooks: CaseHooks) -> dict[str, Any] | None:
case_started = time.monotonic()
@@ -276,6 +283,7 @@ class _BaseEvalRun:
result.results,
namespace=self.trace_namespace,
scorer_traces=self.scorer_traces,
+ run_metadata=self._experiment_metadata(),
)
await asyncio.to_thread(evaluation_client.flush)
await self.ctx.reporter.record_posthog_evaluations_url(self.experiment_name, self.experiment_id)
@@ -305,6 +313,7 @@ class _BaseEvalRun:
artifacts_summary=meta.get("artifacts_summary"),
scores=eval_result.scores,
token_usage=meta.get("token_usage"),
+ run_metadata=self._experiment_metadata(),
)
await asyncio.to_thread(self.posthog_client.flush)
except Exception:
@@ -515,6 +524,7 @@ class _SandboxedEvalRun(_BaseEvalRun):
case_name=eval_case.name,
parsed=parsed,
namespace=self.trace_namespace,
+ run_metadata=self._experiment_metadata(),
)
# Store metadata for emit_trace_root (called after scoring)
self.case_trace_meta[eval_case.name] = {
@@ -579,11 +589,12 @@ class _SandboxedEvalRun(_BaseEvalRun):
def _project_name(self) -> str:
return f"sandboxed-agent-{self.experiment_name}" if self.is_public else self.experiment_name
- def _experiment_metadata(self) -> dict[str, Any]:
+ def _experiment_metadata(self) -> RunMetadata:
return {
- "agent_model": self.ctx.agent_model,
+ **super()._experiment_metadata(),
"agent_runtime": self.ctx.agent_runtime,
"skill_delivery": self.ctx.skill_delivery,
+ "reasoning_effort": self.ctx.reasoning_effort,
}
diff --git a/products/posthog_ai/eval_harness/harness/context.py b/products/posthog_ai/eval_harness/harness/context.py
index 7020504ce35a..53b72d45e26e 100644
--- a/products/posthog_ai/eval_harness/harness/context.py
+++ b/products/posthog_ai/eval_harness/harness/context.py
@@ -81,3 +81,9 @@ class EvalContext:
trials: int
"""Times each case runs. Agents are stochastic, so N runs per case measure
the variance a single run can't reveal."""
+
+ git_sha: str | None
+ """Commit under test; ``None`` when unknown."""
+
+ git_dirty: bool | None
+ """Whether tracked files differed from ``git_sha``; ``None`` when unknown."""
diff --git a/products/posthog_ai/eval_harness/harness/lifecycle.py b/products/posthog_ai/eval_harness/harness/lifecycle.py
index 08604a50f744..24277422d01a 100644
--- a/products/posthog_ai/eval_harness/harness/lifecycle.py
+++ b/products/posthog_ai/eval_harness/harness/lifecycle.py
@@ -1,9 +1,11 @@
from __future__ import annotations
+import os
import time
import atexit
import asyncio
import logging
+import subprocess
from collections.abc import Sequence
from contextlib import AsyncExitStack, ExitStack
from dataclasses import replace
@@ -37,7 +39,7 @@ from .cli import (
)
from .context import EvalContext
from .demo_data import SandboxedDemoData, ensure_demo_ready
-from .discovery import MULTI_TURN_MODULE_MARKER, EvalSuite, discover_suites
+from .discovery import MULTI_TURN_MODULE_MARKER, REPO_ROOT, EvalSuite, discover_suites
from .django_env import EvalDatabase
from .env_preflight import validate_eval_env
from .kernel_sandboxes import reclaim_kernels
@@ -87,6 +89,25 @@ def eval_feature_enabled(
return key not in FORCED_OFF_FEATURE_FLAGS
+def _git(*args: str) -> str | None:
+ """Stdout of a git command run in the checkout under test; ``None`` when git fails."""
+ # GIT_DIR, GIT_WORK_TREE and friends would point git away from REPO_ROOT.
+ env = {key: value for key, value in os.environ.items() if not key.startswith("GIT_")}
+ try:
+ result = subprocess.run(
+ ["git", *args], cwd=REPO_ROOT, env=env, check=True, capture_output=True, text=True, timeout=10
+ )
+ except (OSError, subprocess.SubprocessError):
+ return None
+ return result.stdout.strip()
+
+
+def _worktree_dirty() -> bool | None:
+ """Whether tracked files differ from ``HEAD``; ``None`` when git can't tell."""
+ status = _git("status", "--porcelain", "--untracked-files=no")
+ return None if status is None else bool(status)
+
+
class SandboxedEvalHarness:
"""Boots the shared eval infrastructure once, then runs every selected suite concurrently.
@@ -108,6 +129,9 @@ class SandboxedEvalHarness:
self._posthog_client: Posthog | None = None
self._posthog_evaluation_client: Posthog | None = None
self._demo_data: SandboxedDemoData | None = None
+ # Read before asyncio.run so the git subprocesses never block the event loop.
+ self._git_sha = _git("rev-parse", "HEAD")
+ self._git_dirty = _worktree_dirty()
def run(self) -> int:
# Discover before anything is provisioned: a typo'd selector should cost a
@@ -403,6 +427,8 @@ class SandboxedEvalHarness:
engine=self._engine,
per_case_timeout_seconds=self.options.per_case_timeout_seconds,
trials=self.options.trials,
+ git_sha=self._git_sha,
+ git_dirty=self._git_dirty,
)
async def _run_suite(self, suite: EvalSuite, ctx: EvalContext) -> SuiteRunResult:
diff --git a/products/posthog_ai/eval_harness/scorers/tracing.py b/products/posthog_ai/eval_harness/scorers/tracing.py
index 14eaf290b906..3d150380a010 100644
--- a/products/posthog_ai/eval_harness/scorers/tracing.py
+++ b/products/posthog_ai/eval_harness/scorers/tracing.py
@@ -20,7 +20,7 @@ from django.conf import settings
from posthoganalytics import Posthog
-from ..trace_events import DISTINCT_ID
+from ..trace_events import DISTINCT_ID, RunMetadata
from .contract import AsyncOnlyScorerMixin, Scorer
# Context var for injecting per-scorer-invocation trace properties
@@ -43,6 +43,7 @@ def _build_posthog_kwargs() -> dict[str, Any]:
"posthog_distinct_id": DISTINCT_ID,
"posthog_trace_id": trace_id,
"posthog_properties": {
+ **ctx["run_metadata"],
"$ai_trace_id": trace_id,
"$ai_parent_id": trace_id,
"$ai_span_name": "Scorer",
@@ -199,6 +200,7 @@ class TracedScorer(AsyncOnlyScorerMixin, Scorer):
distinct_id=DISTINCT_ID,
event="$ai_span",
properties={
+ **self._eval_metadata["run_metadata"],
"$ai_trace_id": agent_trace_id,
"$ai_span_id": str(uuid.uuid4()),
"$ai_parent_id": agent_trace_id,
@@ -223,6 +225,7 @@ def wrap_scorers(
agent_trace_id_lookup: dict[str, str],
*,
trace_namespace: str,
+ run_metadata: RunMetadata,
) -> tuple[list[Any], dict[tuple[str, str], str]]:
"""Wrap scorers with tracing.
@@ -238,6 +241,7 @@ def wrap_scorers(
eval_metadata = {
"experiment_id": experiment_id,
"experiment_name": f"{trace_namespace}/{experiment_name}",
+ "run_metadata": run_metadata,
}
wrapped = [
TracedScorer(
diff --git a/products/posthog_ai/eval_harness/test/test_one_shot_runner.py b/products/posthog_ai/eval_harness/test/test_one_shot_runner.py
index 97b7e5c0e8e6..a4cde07e09fa 100644
--- a/products/posthog_ai/eval_harness/test/test_one_shot_runner.py
+++ b/products/posthog_ai/eval_harness/test/test_one_shot_runner.py
@@ -85,6 +85,8 @@ def _build_ctx(timeout_seconds: int = 30, one_shot_slots: int = 2, case_filter:
engine=resolve_engine(),
per_case_timeout_seconds=timeout_seconds,
trials=1,
+ git_sha=None,
+ git_dirty=None,
)
@@ -206,7 +208,6 @@ def test_run_routes_through_the_engine(
monkeypatch.setenv("OPENAI_API_KEY", "test-key")
monkeypatch.setenv("ANTHROPIC_API_KEY", "test-key")
engine = _StubEngine(canned)
- harness = SandboxedEvalHarness(parse_args(["--agent-model", "claude-test"]))
reporter = _StubReporter()
with (
@@ -215,7 +216,12 @@ def test_run_routes_through_the_engine(
) as create_client,
patch("posthoganalytics.client.batch_post") as batch_post,
patch("products.posthog_ai.eval_harness.harness.lifecycle.atexit.register"),
+ patch(
+ "products.posthog_ai.eval_harness.harness.lifecycle._git",
+ side_effect=lambda *args: "abc123" if args[0] == "rev-parse" else "",
+ ),
):
+ harness = SandboxedEvalHarness(parse_args(["--agent-model", "claude-test"]))
with harness._stack:
harness._bootstrap(frozenset())
ctx = harness._build_context(frozenset(), reporter) # type: ignore[arg-type]
@@ -253,7 +259,12 @@ def test_run_routes_through_the_engine(
for experiment in engine.calls:
assert experiment.project_name == "one-shot-test"
assert [case.input["name"] for case in experiment.cases] == ["c1", "c2"]
- assert experiment.metadata == {"agent_model": "claude-test"}
+ assert experiment.metadata == {
+ "agent_model": "claude-test",
+ "trials": 1,
+ "git_sha": "abc123",
+ "git_dirty": False,
+ }
assert experiment.no_send_logs == no_send_logs
assert reporter.started == [("one-shot-test", 2)] * 2
assert reporter.summaries == [("one-shot-test", canned.summary, 0)] * 2
diff --git a/products/posthog_ai/eval_harness/test/test_trace_events.py b/products/posthog_ai/eval_harness/test/test_trace_events.py
index e877e479f175..2879d0c5a499 100644
--- a/products/posthog_ai/eval_harness/test/test_trace_events.py
+++ b/products/posthog_ai/eval_harness/test/test_trace_events.py
@@ -1,16 +1,31 @@
from __future__ import annotations
+from collections.abc import Callable
from typing import Any, cast
from parameterized import parameterized
from posthoganalytics import Posthog
+from products.posthog_ai.eval_harness.acp_log import GenerationDescriptor, ParsedLog, SpanDescriptor
from products.posthog_ai.eval_harness.base import _SandboxedEvalRun
from products.posthog_ai.eval_harness.engines.types import CaseResult
from products.posthog_ai.eval_harness.one_shot import _OneShotEvalRun
-from products.posthog_ai.eval_harness.trace_events import emit_evaluation_events, emit_trace_root
+from products.posthog_ai.eval_harness.scorers.contract import Score, Scorer
+from products.posthog_ai.eval_harness.scorers.tracing import (
+ TracedClients,
+ TracedScorer,
+ _build_posthog_kwargs,
+ _scorer_context,
+)
+from products.posthog_ai.eval_harness.trace_events import (
+ RunMetadata,
+ emit_evaluation_events,
+ emit_trace_events,
+ emit_trace_root,
+)
NAMESPACES = [(_SandboxedEvalRun.trace_namespace,), (_OneShotEvalRun.trace_namespace,)]
+RUN_METADATA: RunMetadata = {"agent_model": "claude-test", "trials": 3, "git_sha": "abc123", "git_dirty": False}
class _CapturingClient:
@@ -26,7 +41,9 @@ def test_evaluation_events_carry_the_run_namespace(namespace: str) -> None:
client = _CapturingClient()
result = CaseResult(input={"name": "case-1"}, output={}, scores={"a_scorer": 1.0})
- emit_evaluation_events(cast(Posthog, client), "exp-1", "my-suite", [result], namespace=namespace)
+ emit_evaluation_events(
+ cast(Posthog, client), "exp-1", "my-suite", [result], namespace=namespace, run_metadata=RUN_METADATA
+ )
properties = client.calls[0]["properties"]
assert properties["$ai_experiment_name"] == f"{namespace}/my-suite"
@@ -47,11 +64,112 @@ def test_trace_root_carries_the_run_namespace(namespace: str) -> None:
prompt="hello",
duration=1.0,
first_timestamp="",
+ run_metadata=RUN_METADATA,
)
properties = client.calls[0]["properties"]
assert properties["$ai_experiment_name"] == f"{namespace}/my-suite"
+def _evaluation_properties(run_metadata: RunMetadata) -> dict[str, Any]:
+ client = _CapturingClient()
+ result = CaseResult(input={"name": "case-1"}, output={}, scores={"a_scorer": 1.0})
+ emit_evaluation_events(
+ cast(Posthog, client), "exp-1", "my-suite", [result], namespace="ns", run_metadata=run_metadata
+ )
+ return client.calls[0]["properties"]
+
+
+def _trace_root_properties(run_metadata: RunMetadata) -> dict[str, Any]:
+ client = _CapturingClient()
+ emit_trace_root(
+ cast(Posthog, client),
+ trace_id="trace-1",
+ experiment_id="exp-1",
+ experiment_name="my-suite",
+ case_name="case-1",
+ namespace="ns",
+ run_metadata=run_metadata,
+ prompt="hello",
+ duration=1.0,
+ first_timestamp="",
+ )
+ return client.calls[0]["properties"]
+
+
+def _parsed_event_properties(event: str) -> Callable[[RunMetadata], dict[str, Any]]:
+ def properties(run_metadata: RunMetadata) -> dict[str, Any]:
+ client = _CapturingClient()
+ parsed = ParsedLog(
+ generations=[GenerationDescriptor()],
+ spans=[SpanDescriptor(span_id="span-1", span_name="tool")],
+ )
+ emit_trace_events(
+ cast(Posthog, client),
+ "trace-1",
+ "exp-1",
+ "my-suite",
+ "case-1",
+ parsed,
+ namespace="ns",
+ run_metadata=run_metadata,
+ )
+ return next(call["properties"] for call in client.calls if call["event"] == event)
+
+ return properties
+
+
+class _StubScorer:
+ def _name(self) -> str:
+ return "stub"
+
+
+def _scorer_span_properties(run_metadata: RunMetadata) -> dict[str, Any]:
+ client = _CapturingClient()
+ scorer = TracedScorer(
+ cast(Scorer, _StubScorer()),
+ cast(TracedClients, None),
+ {"experiment_id": "exp-1", "experiment_name": "ns/my-suite", "run_metadata": run_metadata},
+ {},
+ posthog_client=cast(Posthog, client),
+ agent_trace_id_lookup={"case-1": "trace-1"},
+ )
+ scorer._emit_scorer_span("case-1", Score(name="stub", score=1.0))
+ return client.calls[0]["properties"]
+
+
+def _judge_generation_properties(run_metadata: RunMetadata) -> dict[str, Any]:
+ token = _scorer_context.set(
+ {
+ "trace_id": "trace-1",
+ "experiment_id": "exp-1",
+ "experiment_name": "ns/my-suite",
+ "run_metadata": run_metadata,
+ }
+ )
+ try:
+ return _build_posthog_kwargs()["posthog_properties"]
+ finally:
+ _scorer_context.reset(token)
+
+
+ [
+ ("evaluation", _evaluation_properties),
+ ("trace_root", _trace_root_properties),
+ ("agent_generation", _parsed_event_properties("$ai_generation")),
+ ("agent_span", _parsed_event_properties("$ai_span")),
+ ("scorer_span", _scorer_span_properties),
+ ("judge_generation", _judge_generation_properties),
+ ]
+)
+def test_every_event_carries_the_run_metadata(
+ _name: str, event_properties: Callable[[RunMetadata], dict[str, Any]]
+) -> None:
+ properties = event_properties(RUN_METADATA)
+
+ assert {key: properties[key] for key in RUN_METADATA} == RUN_METADATA
+
+
def test_the_two_run_kinds_label_themselves_differently() -> None:
assert _SandboxedEvalRun.trace_namespace != _OneShotEvalRun.trace_namespace
diff --git a/products/posthog_ai/eval_harness/test/test_worktree_dirty.py b/products/posthog_ai/eval_harness/test/test_worktree_dirty.py
new file mode 100644
index 000000000000..ec8f966b0a95
--- /dev/null
+++ b/products/posthog_ai/eval_harness/test/test_worktree_dirty.py
@@ -0,0 +1,25 @@
+import subprocess
+
+from unittest.mock import patch
+
+from parameterized import parameterized
+
+from products.posthog_ai.eval_harness.harness.lifecycle import _worktree_dirty
+
+
+ [
+ ("clean", subprocess.CompletedProcess([], 0, stdout=""), False),
+ ("modified", subprocess.CompletedProcess([], 0, stdout=" M products/x.py\n"), True),
+ ("git_failed", subprocess.CalledProcessError(128, "git"), None),
+ ("git_slow", subprocess.TimeoutExpired("git", 10), None),
+ ("git_missing", FileNotFoundError("git"), None),
+ ]
+)
+def test_worktree_dirty(_name: str, outcome: object, expected: bool | None) -> None:
+ with patch("products.posthog_ai.eval_harness.harness.lifecycle.subprocess.run") as run:
+ if isinstance(outcome, BaseException):
+ run.side_effect = outcome
+ else:
+ run.return_value = outcome
+ assert _worktree_dirty() is expected
diff --git a/products/posthog_ai/eval_harness/trace_events.py b/products/posthog_ai/eval_harness/trace_events.py
index 5e2273a32be0..cda59292d878 100644
--- a/products/posthog_ai/eval_harness/trace_events.py
+++ b/products/posthog_ai/eval_harness/trace_events.py
@@ -20,6 +20,8 @@ from .engines.types import CaseResult
logger = logging.getLogger(__name__)
+type RunMetadata = dict[str, str | int | bool | None]
+
DISTINCT_ID = "llma_eval"
DEFAULT_MODEL = "claude-sonnet-4-20250514"
DEFAULT_PROVIDER = "anthropic"
@@ -49,16 +51,20 @@ class TraceEventEmitter:
experiment_name: str,
case_name: str,
namespace: str,
+ *,
+ run_metadata: RunMetadata,
):
self._client = client
self._trace_id = trace_id
self._experiment_id = experiment_id
self._formatted_experiment_name = f"{namespace}/{experiment_name}"
self._case_name = case_name
+ self._run_metadata = run_metadata
@property
def _eval_metadata(self) -> dict[str, Any]:
return {
+ **self._run_metadata,
"ai_product": "evals",
"$ai_experiment_id": self._experiment_id,
"$ai_experiment_name": self._formatted_experiment_name,
@@ -91,13 +97,13 @@ class TraceEventEmitter:
gen_end = _parse_iso_timestamp(gen.end_ts) or _parse_iso_timestamp(gen.timestamp)
properties: dict[str, Any] = {
+ **self._eval_metadata,
"$ai_trace_id": self._trace_id,
"$ai_span_id": str(uuid.uuid4()),
"$ai_parent_id": self._trace_id,
"$ai_model": model,
"$ai_provider": DEFAULT_PROVIDER,
"$ai_input": gen.input_messages,
- **self._eval_metadata,
}
if gen.output_content:
properties["$ai_output_choices"] = [
@@ -169,12 +175,12 @@ class TraceEventEmitter:
distinct_id=DISTINCT_ID,
event="$ai_span",
properties={
+ **self._eval_metadata,
"$ai_trace_id": self._trace_id,
"$ai_span_id": span.span_id,
"$ai_parent_id": self._trace_id,
"$ai_span_name": span.span_name,
"$ai_output_state": span.content,
- **self._eval_metadata,
},
**capture_kwargs,
)
@@ -206,10 +212,10 @@ class TraceEventEmitter:
output_state["artifacts"] = artifacts_summary
properties: dict[str, Any] = {
+ **self._eval_metadata,
"$ai_trace_id": self._trace_id,
"$ai_trace_name": trace_name,
"$ai_latency": duration,
- **self._eval_metadata,
}
if prompt:
properties["$ai_input_state"] = {"prompt": prompt}
@@ -242,12 +248,15 @@ def emit_trace_events(
parsed: ParsedLog,
*,
namespace: str,
+ run_metadata: RunMetadata,
) -> None:
"""Emit one ``$ai_generation`` per turn, plus ``$ai_span`` events.
Thin wrapper over ``TraceEventEmitter.emit_parsed_events``.
"""
- TraceEventEmitter(client, trace_id, experiment_id, experiment_name, case_name, namespace).emit_parsed_events(parsed)
+ TraceEventEmitter(
+ client, trace_id, experiment_id, experiment_name, case_name, namespace, run_metadata=run_metadata
+ ).emit_parsed_events(parsed)
def emit_trace_root(
@@ -258,6 +267,7 @@ def emit_trace_root(
case_name: str,
*,
namespace: str,
+ run_metadata: RunMetadata,
prompt: str,
duration: float,
first_timestamp: str,
@@ -267,7 +277,9 @@ def emit_trace_root(
token_usage: dict[str, int] | None = None,
) -> None:
"""Thin wrapper over ``TraceEventEmitter.emit_root``."""
- TraceEventEmitter(client, trace_id, experiment_id, experiment_name, case_name, namespace).emit_root(
+ TraceEventEmitter(
+ client, trace_id, experiment_id, experiment_name, case_name, namespace, run_metadata=run_metadata
+ ).emit_root(
prompt=prompt,
duration=duration,
first_timestamp=first_timestamp,
@@ -285,6 +297,7 @@ def emit_evaluation_events(
eval_results: list[CaseResult],
*,
namespace: str,
+ run_metadata: RunMetadata,
scorer_traces: dict[tuple[str, str], str] | None = None,
) -> None:
"""Emit ``$ai_evaluation`` events for each scorer result in each eval case.
@@ -313,6 +326,7 @@ def emit_evaluation_events(
trace_id = scorer_trace_id or agent_trace_id
properties: dict[str, Any] = {
+ **run_metadata,
"$ai_eval_source": namespace,
"$ai_evaluation_type": "offline",
"$ai_experiment_id": experiment_id,