Skip to content

Commit 0dc4df8

Browse files
test: kagent compat fixtures, ordered replay, and a daily Weaver check of kagent's registry (#245)
* test(corpus): kagent v1.0.0-alpha9 fixtures and an ordered replay mode * ci: check kagent's telemetry registry daily with Weaver * examples(kubernetes): skip the Claude Code recipe where the runtime writes GenAI spans
1 parent f059a2a commit 0dc4df8

42 files changed

Lines changed: 2489 additions & 9 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: kagent contract policy
2+
3+
# Tests the kagent contract policy against its local registries and negative
4+
# cases when the policy or its tooling changes. It never fetches kagent itself.
5+
on:
6+
pull_request:
7+
branches: [main]
8+
paths:
9+
- "tests/contract/kagent/**"
10+
- ".github/workflows/kagent-contract.yml"
11+
- ".github/workflows/kagent-contract-policy.yml"
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
selftest:
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 20
20+
steps:
21+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
22+
with:
23+
persist-credentials: false
24+
25+
- name: Self test the contract policy
26+
run: tests/contract/kagent/test.sh
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: kagent contract
2+
3+
# Checks every day, with Weaver, that kagent's telemetry registry still has what
4+
# agentevals reads from kagent spans, and keeps one labelled issue up to date
5+
# while it does not. It never runs on pull requests: kagent changes on its own
6+
# schedule. See tests/contract/kagent/.
7+
on:
8+
schedule:
9+
- cron: "23 5 * * *"
10+
workflow_dispatch:
11+
12+
permissions: {}
13+
14+
concurrency:
15+
group: kagent-contract
16+
cancel-in-progress: false
17+
18+
defaults:
19+
run:
20+
shell: bash
21+
22+
env:
23+
ISSUE_LABEL: kagent-contract
24+
25+
jobs:
26+
check:
27+
runs-on: ubuntu-latest
28+
timeout-minutes: 30
29+
permissions:
30+
contents: read
31+
steps:
32+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
33+
with:
34+
persist-credentials: false
35+
36+
- name: Self test the contract policy
37+
run: tests/contract/kagent/test.sh
38+
39+
# The release tag is fetched and used in one step, and check.sh validates it
40+
# before use, so nothing fetched passes through GITHUB_ENV or an expression.
41+
- name: Check kagent main and the newest release
42+
env:
43+
GH_TOKEN: ${{ github.token }}
44+
run: |
45+
release="$(gh release view --repo kagent-dev/kagent --json tagName --jq .tagName)"
46+
tests/contract/kagent/check.sh report.md main "$release"
47+
48+
- name: Summarize
49+
if: always()
50+
continue-on-error: true
51+
run: |
52+
{
53+
if [ -f report.md ]; then cat report.md; fi
54+
echo
55+
echo "## kagent main against the committed snapshot"
56+
echo
57+
tests/contract/kagent/weaver.sh registry diff --v2 --diff-format markdown \
58+
-r "https://github.com/kagent-dev/kagent.git@main[telemetry/registry]" \
59+
--baseline-registry /contract/registries/main-2cc3ffae
60+
} >> "$GITHUB_STEP_SUMMARY"
61+
62+
- name: Upload the report
63+
if: always()
64+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
65+
with:
66+
name: kagent-contract-report
67+
path: report.md
68+
if-no-files-found: ignore
69+
70+
# The issue body is fixed text plus the report, whose fetched content sits in a
71+
# code block without backticks. It is always passed as a file, never through the shell.
72+
report-failure:
73+
needs: check
74+
if: failure()
75+
runs-on: ubuntu-latest
76+
timeout-minutes: 10
77+
permissions:
78+
issues: write
79+
steps:
80+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
81+
continue-on-error: true
82+
with:
83+
name: kagent-contract-report
84+
85+
- name: Open or update the issue
86+
env:
87+
GH_TOKEN: ${{ github.token }}
88+
GH_REPO: ${{ github.repository }}
89+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
90+
run: |
91+
set -euo pipefail
92+
{
93+
echo "The daily kagent contract check failed: $RUN_URL"
94+
echo
95+
if [ -f report.md ]; then
96+
cat report.md
97+
else
98+
echo "The check failed before it wrote a report (for example in the self test). See the run log."
99+
echo
100+
echo "<!-- kagent-contract-report: none -->"
101+
fi
102+
} > body.md
103+
# The report appends its marker last, so the last match is the real one.
104+
marker="$(grep -o 'kagent-contract-report: [0-9a-f]*' body.md | tail -n 1)"
105+
106+
number="$(gh issue list --label "$ISSUE_LABEL" --state open --json number --jq '.[0].number // empty')"
107+
if [ -z "$number" ]; then
108+
gh label create "$ISSUE_LABEL" --color B60205 --force \
109+
--description "The daily check of kagent's telemetry registry failed"
110+
gh issue create --title "kagent telemetry contract check failed" \
111+
--label "$ISSUE_LABEL" --body-file body.md
112+
exit 0
113+
fi
114+
115+
# Only comment when the report changed since the last update. Comments
116+
# from people are ignored, so nobody can hide a change by quoting a marker.
117+
latest="$(gh issue view "$number" --json body,comments \
118+
--jq '([.comments[] | select(.author.login == "github-actions")] | last | .body) // .body')"
119+
if grep -qF "$marker" <<<"$latest"; then
120+
echo "Issue #$number already has this report."
121+
else
122+
gh issue comment "$number" --body-file body.md
123+
fi
124+
125+
close-resolved:
126+
needs: check
127+
if: success()
128+
runs-on: ubuntu-latest
129+
timeout-minutes: 10
130+
permissions:
131+
issues: write
132+
steps:
133+
- name: Close the issue once the check passes again
134+
env:
135+
GH_TOKEN: ${{ github.token }}
136+
GH_REPO: ${{ github.repository }}
137+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
138+
run: |
139+
set -euo pipefail
140+
number="$(gh issue list --label "$ISSUE_LABEL" --state open --json number --jq '.[0].number // empty')"
141+
if [ -n "$number" ]; then
142+
gh issue close "$number" --comment "The kagent contract check passes again: $RUN_URL"
143+
fi

‎examples/kubernetes/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ kagent agents --> OTel Collector --> agentevals (UI on :8001)
88
+---- scores -----+
99
```
1010

11-
Tested with kagent main at `46fdd3d7` (chart `v1.0.0-alpha3-82`, `v1alpha3` agents on Substrate), Claude Code 2.1.285, Collector contrib 0.162.0, and `claude-haiku-4-5` for both agents.
11+
Tested with kagent `46fdd3d7` (`v1.0.0-alpha9` plus a UI only commit, `v1alpha3` agents on Substrate), Claude Code 2.1.285, Collector contrib 0.162.0, and `claude-haiku-4-5` for both agents.
1212

1313
## Set it up
1414

@@ -133,7 +133,7 @@ The `transform/claude_code` processor in `otel-collector.yaml` fills the gap for
133133
* `claude_code.tool` becomes `execute_tool`, with `gen_ai.tool.name` taken from `tool_name` (minus the `mcp__<server>__` prefix)
134134
* `claude_code.llm_request` becomes `chat`, with the model and token usage, cache reads and writes included
135135

136-
Recheck it when you upgrade the harness, since those names can change. Drop it once the harness emits GenAI spans itself, or calls get counted twice.
136+
Recheck it when you upgrade the harness, since those names can change. The recipe is for kagent releases whose Claude runtime does not write its own GenAI spans, and it skips processes that do (their resource has `kagent.genai.producer`), so calls are never counted twice.
137137

138138
Still missing with this version:
139139

‎examples/kubernetes/otel-collector.yaml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# are printed by the debug exporter (kubectl logs deploy/otel-collector).
55
#
66
# transform/claude_code is a workaround for Claude Code native telemetry, checked with
7-
# Claude Code 2.1.285 (kagent Claude harness). Remove it once the producer emits GenAI
8-
# execute_tool and chat spans itself, or both would be counted.
7+
# Claude Code 2.1.285 (kagent Claude harness). It skips processes whose resource has
8+
# kagent.genai.producer, where the runtime writes its own chat and execute_tool spans.
99
apiVersion: v1
1010
kind: ConfigMap
1111
metadata:
@@ -31,8 +31,9 @@ data:
3131
error_mode: ignore
3232
trace_statements:
3333
- context: span
34+
# One condition on purpose: entries of this list are ORed.
3435
conditions:
35-
- instrumentation_scope.name == "com.anthropic.claude_code.tracing"
36+
- instrumentation_scope.name == "com.anthropic.claude_code.tracing" and resource.attributes["kagent.genai.producer"] == nil
3637
statements:
3738
- set(span.attributes["gen_ai.operation.name"], "execute_tool") where span.name == "claude_code.tool"
3839
- set(span.attributes["gen_ai.tool.name"], span.attributes["tool_name"]) where span.name == "claude_code.tool"

‎tests/contract/kagent/README.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# kagent telemetry contract
2+
3+
What agentevals reads from kagent spans, checked with [Weaver](https://github.com/open-telemetry/weaver) against kagent's telemetry registry every day by `.github/workflows/kagent-contract.yml`. A failure opens or updates one issue labelled `kagent-contract`; it never fails a pull request.
4+
5+
| Path | What |
6+
|---|---|
7+
| `policy/agentevals.rego` | The contract: the attributes agentevals needs per upstream span group type, and the requirement levels that must not drop. A Weaver `after_resolution` policy that only reports violations. |
8+
| `registries/<name>/` | Copies of kagent's `telemetry/registry` at fixed commits. They must pass. `main-2cc3ffae` is also the baseline for the daily `weaver registry diff`. |
9+
| `testdata/<finding id>/` | Registries that must fail with that finding. |
10+
| `weaver.sh` | Runs the pinned Weaver image, locked down. |
11+
| `test.sh` | The self test: registries pass, testdata fails with its finding. |
12+
| `check.sh` | Checks kagent refs (`main` or a release tag) and writes the report. |
13+
14+
Groups are matched by the upstream type they refine (`gen_ai.invoke_agent.internal`, `gen_ai.client.inference`, `gen_ai.execute_tool.internal`), never by kagent ids. Weaver resolves kagent's pinned upstream semantic conventions, so a group kagent only imports is checked too. When kagent adds its own refinement of a type, that refinement is checked instead.
15+
16+
Run it locally (needs Docker, `jq` and network):
17+
18+
```bash
19+
tests/contract/kagent/test.sh
20+
tests/contract/kagent/check.sh report.md main v1.0.0-alpha9
21+
```
22+
23+
When kagent changes:
24+
25+
* A new requirement need goes into `contract` in the policy, with a `testdata/<finding id>/` case if it adds a finding.
26+
* To track a new release, copy its `telemetry/registry` into `registries/<tag>/`.
27+
* If kagent moves to a Weaver release the pinned image cannot read, the report shows Weaver's error. Bump `WEAVER_IMAGE` in `weaver.sh` by digest.

‎tests/contract/kagent/check.sh‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
3+
# Checks kagent's registry at each given ref (main or a release tag) against
4+
# the agentevals contract and writes a Markdown report. Exits 1 if any ref
5+
# fails. Weaver's exit code is the result; the report lists its findings.
6+
#
7+
# tests/contract/kagent/check.sh <report.md> main v1.0.0-alpha9
8+
9+
set -o errexit -o nounset -o pipefail
10+
11+
KAGENT_GIT="https://github.com/kagent-dev/kagent.git"
12+
REF_PATTERN='^(main|v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?)$'
13+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14+
15+
report="$1"
16+
shift
17+
18+
body="$(mktemp)"
19+
failed=0
20+
for ref in "$@"; do
21+
if [[ ! "${ref}" =~ ${REF_PATTERN} ]]; then
22+
echo "refusing kagent ref, expected main or a release tag" >&2
23+
exit 2
24+
fi
25+
if output="$("${HERE}/weaver.sh" registry check -r "${KAGENT_GIT}@${ref}[telemetry/registry]" \
26+
--v2 --policy /contract/policy --diagnostic-format json 2>&1)"; then
27+
printf "## \`kagent@%s\`: ok\n\n" "${ref}" >>"${body}"
28+
continue
29+
fi
30+
failed=1
31+
{
32+
echo "## \`kagent@${ref}\`: failed"
33+
echo
34+
echo '```text'
35+
# Weaver's JSON diagnostics without warnings: policy findings and errors.
36+
# Backticks are dropped so fetched names cannot end the code block.
37+
sed -n '/^\[$/,/^\]$/p' <<<"${output}" | jq -r '.[]
38+
| select(.diagnostic.severity != "Warning")
39+
| if .error.type == "policy_violation"
40+
then "\(.error.violation.id): \(.error.violation.message)"
41+
else .diagnostic.message // "unknown error" end' 2>/dev/null | tr -d '`' \
42+
|| echo "Weaver produced no diagnostics."
43+
echo '```'
44+
echo
45+
} >>"${body}"
46+
done
47+
48+
{
49+
echo "# kagent telemetry contract"
50+
echo
51+
echo "kagent's telemetry registry checked against what agentevals reads (\`tests/contract/kagent/policy/agentevals.rego\`)."
52+
echo
53+
cat "${body}"
54+
echo
55+
echo "<!-- kagent-contract-report: $(sha256sum "${body}" | cut -d' ' -f1) -->"
56+
} >"${report}"
57+
rm -f "${body}"
58+
cat "${report}"
59+
exit "${failed}"

0 commit comments

Comments
 (0)