Skip to content

Commit 097f67b

Browse files
pelikhanCopilotgh-aw-botCopilot
authored
Align OpenTelemetry GenAI telemetry with current semantic conventions (#79090)
* Initial plan * Align OTel GenAI specification and registry Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Add opt-in GenAI OTel runtime support Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Add GenAI OTel conformance coverage and docs Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Clarify GenAI spec attribute requirements Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Fix OTel compatibility checks Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Stabilize OTel compatibility golden test Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Address OTel review findings Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Isolate OTel tests from shared temp artifacts Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Track main merge and CI repair plan Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Fix OTel conformance and test failures Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Satisfy Go linters for rollout parsing Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Move GenAI conformance helpers under fixtures Keep recognizable test suites discoverable and update conformance paths without changing validation behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Fix current CI regressions Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Clarify deprecated GenAI telemetry migration Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Name GenAI opt-in gen_ai_v1 and preserve failure attribution Propagate inferred agent errors to GenAI spans and duration metrics, and isolate legacy golden mirror mocks from host filesystem state. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Compose typed telemetry registries for GenAI conformance Preserve the pinned GenAI model and advice while registering shipped extensions and resolving core definitions locally. Exercise accepted mixed telemetry and rejected mutations with the actual pinned Weaver. Narrow compatibility exceptions and independently reject unregistered compatibility metrics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent eaacbc6 commit 097f67b

36 files changed

Lines changed: 2140 additions & 110 deletions

‎.changeset/minor-genai-semconv.md‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.github/aw/otel.md‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Resource attributes identify the service and workflow run, for example `service.
2121
| Family | Examples |
2222
|---|---|
2323
| Workflow identity and outcome | `gh-aw.workflow.name`, `gh-aw.job.name`, `gh-aw.run.status`, `gh-aw.agent.conclusion` |
24-
| Model usage | `gen_ai.system`, `gen_ai.request.model`, `gen_ai.response.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` |
24+
| Model usage | `gen_ai.provider.name`, `gen_ai.agent.name`, `gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.response.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` |
2525
| Cost and budget | `gh-aw.aic`, `gh-aw.max_ai_credits`, `gh-aw.max_ai_credits_exceeded` |
2626
| Failures and export health | `gh-aw.error_count`, `exception`, `gh-aw.otlp.export_errors` |
2727
| Routing, firewall, and tools | `gh-aw.model_routing.*`, `gh-aw.firewall.*`, `gh-aw.mcp.*` |
@@ -75,7 +75,7 @@ Choose the owning span first, then the attribute. Missing attributes mean unknow
7575
|---|---|---|
7676
| Agent latency | Span duration of `gh-aw.<job>.agent` | Dedicated agent span, when `agent_cli_start_ms` and `agent_output.json` timing allow it |
7777
| Job wall time | `gh-aw.action_minutes` (minutes) | Conclusion span; computed as `(end - start) / 60000` |
78-
| Tokens | `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.usage.cache_read.input_tokens`, `gen_ai.usage.cache_creation.input_tokens`, `gen_ai.usage.total_tokens` | Dedicated agent span; otherwise the conclusion span of the job that owns usage. `total_tokens` is input plus output only |
78+
| Tokens | `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.usage.cache_read.input_tokens`, `gen_ai.usage.cache_write.input_tokens` | Dedicated agent span; otherwise the conclusion span of the job that owns usage. Compatibility mode also emits `gen_ai.usage.cache_creation.input_tokens` and `gen_ai.usage.total_tokens` |
7979
| AI credits | `gh-aw.aic` (double) | Usage-owning span only; explicit zero is measured, absence is unknown |
8080
| Budget | `gh-aw.max_ai_credits`, `gh-aw.max_ai_credits_exceeded`, `gh-aw.ai_credits_rate_limit_error` | Agent conclusion path |
8181
| Turns | `gh-aw.turns` | Conclusion span, when the engine reports a turn count |
@@ -99,7 +99,7 @@ Source evidence is limited to implementation and tests; this table lists emitter
9999
|---|---|---|---|
100100
| Job setup | `gh-aw.<job>.setup`, `gh-aw.job.setup` | `actions/setup/js/send_otlp_span.cjs` `sendJobSetupSpan` | Signals, Identity |
101101
| Job conclusion | `gh-aw.<job>.conclusion`, `gh-aw.job.conclusion` | `send_otlp_span.cjs` `sendJobConclusionSpan`; `action_conclusion_otlp.cjs` | Identity, Query recipes |
102-
| Agent | `gh-aw.<job>.agent` (dedicated span, `kind` CLIENT) | `send_otlp_span.cjs` `sendJobConclusionSpan` (`hasDedicatedAgentSpan`) | Identity, Query recipes |
102+
| Agent | Compatibility: `gh-aw.<job>.agent` (`CLIENT`); opt-in: `invoke_agent <workflow>` (`INTERNAL`) | `send_otlp_span.cjs` `sendJobConclusionSpan` (`hasDedicatedAgentSpan`) | Identity, Query recipes |
103103
| Exceptions | `exception` events | `send_otlp_span.cjs` `buildSpanEvents` | Signals |
104104
| Graders | `grader.result` events; `gh-aw.graders.*` on the agent conclusion span | `send_otlp_span.cjs` `buildGraderTelemetry`, `selectGraderOutputForJob` | Signals, Identity |
105105
| Evals | `eval.result`, `eval.status` events; `gh-aw.evals.*` | `send_otlp_span.cjs` `buildEvalTelemetry` | Signals |
@@ -112,16 +112,15 @@ Source evidence is limited to implementation and tests; this table lists emitter
112112
| Resource identity | `service.*`, `github.*`, `runner.*`, `deployment.environment`, `gh-aw.*` | `send_otlp_span.cjs` `buildGitHubActionsResourceAttributes`; `pkg/workflow/observability_otlp.go` `otelResourceAttributes` | Identity |
113113
| Attribute names | 200 names | `specs/otel/attributes.tsp`, generated into `actions/setup/js/otel_attributes_generated.cjs` and `pkg/workflow/otel_attributes_generated.go` | Identity |
114114

115-
No OTel metric emitter exists in `actions/`, `pkg/`, `cmd/`, or `scripts/`.
115+
The JavaScript runtime emits `gh_aw.*` metrics and GenAI token counters when metrics are enabled; metric names and compatibility behavior are described in the public OpenTelemetry reference.
116116

117117
## Discrepancies with the specification
118118

119119
These describe current behavior. They do not change the normative specification.
120120

121-
- **Metrics (spec §11.2–11.3):** `gh_aw.*` and `cicd.*` metric instruments are not emitted. Treat all measurements as span attributes or events.
122-
- **Span error type (spec §10.5):** The bare `error.type` key is not emitted. Work-queue spans use the prefixed `gh-aw.work_queue.error.type`. Built-in setup, conclusion, and agent spans use `status.code` and `exception` events.
121+
- **Span error type (spec §10.5):** Built-in agent and agent-conclusion spans emit the low-cardinality `error.type` on failure, timeout, or cancellation. Work-queue spans use the prefixed `gh-aw.work_queue.error.type`.
123122
- **Lifecycle events (spec §10.6):** `gh_aw.job.setup.completed`, `gh_aw.agent.retry`, and related events are not emitted.
124123
- **Outcome spans (spec §13):** The `gh-aw.outcome.*` family appears in the public attribute reference and the spec, but no producer exists in this checkout. The corresponding formal tests in `pkg/workflow/otel_reliability_formal_test.go` are skipped.
125-
- **Aliases not emitted:** `gen_ai.provider.name`, `gen_ai.usage.reasoning.output_tokens`, and `cicd.*` aliases are not emitted.
124+
- **Aliases not emitted:** `gen_ai.usage.reasoning.output_tokens` is not emitted.
126125
- **Local mirror redaction (spec §14.3):** Span payloads from `sendJobSetupSpan`, `sendJobConclusionSpan` (agent and conclusion), and their mirror writes call `appendToOTLPJSONL(payload)` without `sanitizeOTLPPayload`. The wire export (`sendOTLPSpan`) and `logSpan` do sanitize. Source-observed; not confirmed by a runtime test.
127126
- **Validation status:** `specs/otel/attributes.tsp` already defines 200 attribute names, and they match the generated JavaScript and Go constants (verified by comparison). The TypeSpec compiler is not installed (`specs/otel/node_modules` is absent) and no lock installation is performed in this run. Compiler validation of `specs/otel/messages.tsp` is therefore deferred, and no TypeSpec file was created or changed.

‎.github/workflows/cjs.yml‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,74 @@ jobs:
129129
run: |
130130
node --test actions/setup/js/scripts/test_otlp_protobuf.mjs
131131
132+
genai-semconv-conformance:
133+
name: GenAI semantic-convention conformance
134+
needs: [checkout-cache]
135+
runs-on: ubuntu-latest
136+
timeout-minutes: 20
137+
permissions:
138+
contents: read
139+
concurrency:
140+
group: ci-${{ github.ref }}-genai-semconv-conformance
141+
cancel-in-progress: true
142+
steps:
143+
- name: Restore checkout
144+
id: restore-checkout
145+
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
146+
with:
147+
path: .
148+
key: checkout-cjs-${{ github.run_id }}-${{ github.sha }}
149+
- name: Checkout on cache miss
150+
if: steps.restore-checkout.outputs.cache-hit != 'true'
151+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
152+
with:
153+
ref: ${{ github.sha }}
154+
fetch-depth: 2
155+
persist-credentials: false
156+
- name: Set up Node.js
157+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v6
158+
with:
159+
node-version: "24"
160+
- name: Set up Python
161+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
162+
with:
163+
python-version: "3.12"
164+
- name: Checkout semantic-conventions-conformance
165+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
166+
with:
167+
repository: open-telemetry/semantic-conventions-conformance
168+
ref: a4321907b3768c468966538a459130ac6b095bdc
169+
path: semantic-conventions-conformance
170+
persist-credentials: false
171+
- name: Move conformance checkout to runner temp
172+
run: mv "$GITHUB_WORKSPACE/semantic-conventions-conformance" "$RUNNER_TEMP/semantic-conventions-conformance"
173+
- name: Install pinned Weaver
174+
run: |
175+
mkdir -p "$RUNNER_TEMP/weaver"
176+
asset=weaver-x86_64-unknown-linux-gnu.tar.xz
177+
curl --fail --location --proto '=https' --tlsv1.2 \
178+
"https://github.com/open-telemetry/weaver/releases/download/v0.28.0/$asset" \
179+
--output "$RUNNER_TEMP/$asset"
180+
printf '%s %s\n' '9878e2d56ad82ae441b0b527377a4f6001ae19f4af362fb0a4d951884f59ab61' "$RUNNER_TEMP/$asset" | sha256sum --check --strict
181+
tar -xJf "$RUNNER_TEMP/$asset" -C "$RUNNER_TEMP/weaver"
182+
weaver_binary="$(find "$RUNNER_TEMP/weaver" -type f -name weaver -print -quit)"
183+
test -n "$weaver_binary"
184+
chmod +x "$weaver_binary"
185+
echo "$(dirname "$weaver_binary")" >> "$GITHUB_PATH"
186+
- name: Install isolated conformance runner
187+
run: |
188+
python -m venv "$RUNNER_TEMP/otel-conformance-venv"
189+
"$RUNNER_TEMP/otel-conformance-venv/bin/pip" install \
190+
-e "$RUNNER_TEMP/semantic-conventions-conformance/tools/runner" \
191+
-e "$RUNNER_TEMP/semantic-conventions-conformance/tools/gen-ai/mock-server" \
192+
-e "$RUNNER_TEMP/semantic-conventions-conformance/tools/gen-ai/runner"
193+
echo "$RUNNER_TEMP/otel-conformance-venv/bin" >> "$GITHUB_PATH"
194+
- name: Validate GenAI semantic conventions
195+
env:
196+
SEMCONV_CACHE: ${{ runner.temp }}/semconv-cache
197+
OTEL_CONFORMANCE_REPORT_DIR: ${{ runner.temp }}/gh-aw-genai-conformance
198+
run: make validate-otel-conformance
199+
132200
js-tests:
133201
name: JS Tests (shard ${{ matrix.shard }}/8)
134202
needs: [checkout-cache]

‎Makefile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,17 @@ validate-otel-contract:
12031203
@cd actions/setup/js && npm run test:js -- otel_contract.test.cjs send_otlp_span.test.cjs --no-file-parallelism >/dev/null
12041204
@echo "✓ OpenTelemetry compatibility contract validated"
12051205

1206+
OTEL_CONFORMANCE_REPORT_DIR ?= $(if $(TMPDIR),$(TMPDIR),/tmp)/gh-aw-otel-conformance-reports
1207+
.PHONY: validate-otel-conformance
1208+
validate-otel-conformance:
1209+
@command -v otel-conformance >/dev/null || { echo "otel-conformance is required; install the pinned conformance runner packages"; exit 1; }
1210+
@command -v weaver >/dev/null || { echo "Weaver v0.28.0 is required; install it before running conformance"; exit 1; }
1211+
@mkdir -p "$(OTEL_CONFORMANCE_REPORT_DIR)"
1212+
@python actions/setup/js/fixtures/genai/prepare_registry.py "$(OTEL_CONFORMANCE_REPORT_DIR)/registry"
1213+
@python actions/setup/js/scripts/genai_registry.test.py "$(OTEL_CONFORMANCE_REPORT_DIR)/registry"
1214+
@otel-conformance actions/setup/js/fixtures/genai --report-dir "$(OTEL_CONFORMANCE_REPORT_DIR)" --data-file "$(OTEL_CONFORMANCE_REPORT_DIR)/data.json" --var "GH_AW_GENAI_REGISTRY=$(abspath $(OTEL_CONFORMANCE_REPORT_DIR))/registry"
1215+
@node actions/setup/js/fixtures/genai/check_genai_conformance.mjs "$(OTEL_CONFORMANCE_REPORT_DIR)"
1216+
12061217
.PHONY: check-otel-attributes
12071218
check-otel-attributes:
12081219
@npm run check --prefix specs/otel

‎actions/setup/js/check_admission.cjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ async function main(core) {
257257
core.setOutput("trace-id", decision.traceId);
258258
if (decision.endpoints.length) {
259259
const { buildOTLPPayload, buildGitHubActionsResourceAttributes, sendOTLPToAllEndpoints } = require("./send_otlp_span.cjs");
260-
const resourceAttributes = buildGitHubActionsResourceAttributes({ repository: process.env.GITHUB_REPOSITORY || "", runId: process.env.GITHUB_RUN_ID || "", staged: false });
260+
const resourceAttributes = buildGitHubActionsResourceAttributes({ repository: process.env.GITHUB_REPOSITORY || "", runId: process.env.GITHUB_RUN_ID || "", workflowName: process.env.GITHUB_WORKFLOW || "", staged: false });
261261
for (const attempt of decision.attempts) {
262262
const payload = buildOTLPPayload({
263263
...attempt,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"use strict";
2+
3+
const fs = require("node:fs");
4+
const path = require("node:path");
5+
6+
const ghAwDir = "/tmp/gh-aw";
7+
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
8+
const [conclusion, mode] = process.argv.slice(2);
9+
10+
if (!["success", "failure"].includes(conclusion) || !["compat", "latest"].includes(mode) || !endpoint) {
11+
throw new Error("Usage: node agent-run.cjs <success|failure> <compat|latest>");
12+
}
13+
14+
const { sendJobConclusionSpan, sendJobSetupSpan } = require("../../send_otlp_span.cjs");
15+
16+
async function main() {
17+
fs.rmSync(ghAwDir, { recursive: true, force: true });
18+
fs.mkdirSync(ghAwDir, { recursive: true });
19+
const startMs = Date.now() - 1000;
20+
fs.writeFileSync(path.join(ghAwDir, "aw_info.json"), JSON.stringify({ engine_id: "copilot", workflow_name: "OpenTelemetry GenAI Conformance", model: "gpt-4o-mini", cli_version: "test" }));
21+
fs.writeFileSync(path.join(ghAwDir, "agent_usage.json"), JSON.stringify({ input_tokens: 100, output_tokens: 20, cache_read_tokens: 25, cache_write_tokens: 10, input_tokens_include_cache: false }));
22+
fs.writeFileSync(path.join(ghAwDir, "agent_output.json"), JSON.stringify({ items: [], errors: [] }));
23+
fs.writeFileSync(path.join(ghAwDir, "agent_cli_start_ms.txt"), String(startMs));
24+
25+
process.env.GH_AW_AGENT_CONCLUSION = conclusion;
26+
process.env.GH_AW_OTEL_METRICS = "true";
27+
process.env.GH_AW_OTLP_ENDPOINTS = JSON.stringify([{ url: endpoint }]);
28+
process.env.GITHUB_ACTOR = "conformance";
29+
process.env.GITHUB_EVENT_NAME = "workflow_dispatch";
30+
process.env.GITHUB_JOB = "agent";
31+
process.env.GITHUB_REF = "refs/heads/main";
32+
process.env.GITHUB_REF_NAME = "main";
33+
process.env.GITHUB_REPOSITORY = "github/gh-aw";
34+
process.env.GITHUB_RUN_ATTEMPT = "1";
35+
process.env.GITHUB_RUN_ID = "123456789";
36+
process.env.GITHUB_SHA = "0123456789abcdef0123456789abcdef01234567";
37+
process.env.GITHUB_WORKFLOW = "OpenTelemetry GenAI Conformance";
38+
process.env.GH_AW_INFO_WORKFLOW_NAME = "OpenTelemetry GenAI Conformance";
39+
process.env.INPUT_JOB_NAME = "agent";
40+
process.env.OTEL_SERVICE_NAME = "gh-aw";
41+
if (mode === "latest") process.env.OTEL_SEMCONV_STABILITY_OPT_IN = "gen_ai_v1";
42+
else delete process.env.OTEL_SEMCONV_STABILITY_OPT_IN;
43+
44+
try {
45+
const setup = await sendJobSetupSpan({ startMs });
46+
process.env.GITHUB_AW_OTEL_TRACE_ID = setup.traceId;
47+
process.env.GITHUB_AW_OTEL_PARENT_SPAN_ID = setup.spanId;
48+
await sendJobConclusionSpan("gh-aw.agent.conclusion", { startMs });
49+
} finally {
50+
fs.rmSync(ghAwDir, { recursive: true, force: true });
51+
}
52+
}
53+
54+
main().catch(error => {
55+
console.error(error);
56+
process.exitCode = 1;
57+
});
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import assert from "node:assert/strict";
2+
import fs from "node:fs";
3+
import path from "node:path";
4+
5+
const reportDir = process.argv[2];
6+
if (!reportDir) throw new Error("Usage: node check_genai_conformance.mjs <weaver-report-directory>");
7+
8+
const expectedMetricNames = new Set([
9+
"gen_ai.client.inference.usage.input_tokens",
10+
"gen_ai.client.inference.usage.output_tokens",
11+
"gen_ai.client.inference.usage.cache_read.input_tokens",
12+
"gen_ai.client.inference.usage.cache_write.input_tokens",
13+
"gen_ai.invoke_agent.duration",
14+
]);
15+
const observedMetrics = new Set();
16+
const expectedScenarios = ["agent_success_latest", "agent_failure_latest"];
17+
18+
function visitSample(value, parentKey = "") {
19+
if (Array.isArray(value)) {
20+
for (const item of value) visitSample(item, parentKey);
21+
return;
22+
}
23+
if (!value || typeof value !== "object") return;
24+
for (const [key, child] of Object.entries(value)) {
25+
if (key === "live_check_result") continue;
26+
if (typeof child === "string" && expectedMetricNames.has(child) && ["name", "metric_name", "instrument_name", "signal_name"].includes(key)) {
27+
observedMetrics.add(child);
28+
}
29+
if ((key === "metrics" || key === "metric") && child && typeof child === "object") {
30+
collectMetricNames(child);
31+
}
32+
visitSample(child, key);
33+
}
34+
}
35+
36+
function collectMetricNames(value) {
37+
if (Array.isArray(value)) {
38+
for (const item of value) collectMetricNames(item);
39+
return;
40+
}
41+
if (!value || typeof value !== "object") return;
42+
for (const [key, child] of Object.entries(value)) {
43+
if (typeof child === "string" && expectedMetricNames.has(child) && ["name", "metric_name", "instrument_name", "signal_name"].includes(key)) {
44+
observedMetrics.add(child);
45+
}
46+
collectMetricNames(child);
47+
}
48+
}
49+
50+
function collectAdvice(value, findings = []) {
51+
if (Array.isArray(value)) {
52+
for (const item of value) collectAdvice(item, findings);
53+
return findings;
54+
}
55+
if (!value || typeof value !== "object") return findings;
56+
for (const [key, child] of Object.entries(value)) {
57+
if (key === "all_advice" && Array.isArray(child)) findings.push(...child);
58+
collectAdvice(child, findings);
59+
}
60+
return findings;
61+
}
62+
63+
for (const scenario of expectedScenarios) {
64+
const reportPath = path.join(reportDir, `${scenario}.json`);
65+
assert.ok(fs.existsSync(reportPath), `Missing Weaver report for ${scenario}: ${reportPath}`);
66+
const report = JSON.parse(fs.readFileSync(reportPath, "utf8"));
67+
const samples = Array.isArray(report.samples) ? report.samples : [];
68+
assert.ok(samples.length > 0, `Weaver report for ${scenario} contains no samples`);
69+
for (const sample of samples) {
70+
for (const finding of collectAdvice(sample)) {
71+
const context = finding.context || {};
72+
const attribute = context.attribute_key || context.missing_attribute || context.attribute;
73+
const metric = finding.signal_name || context.metric_name || context.metric;
74+
if (finding.id === "missing_attribute" || finding.id === "genai_expected_attribute_missing") {
75+
assert.ok(!String(attribute || "").startsWith("gen_ai."), `${scenario}: missing GenAI attribute ${attribute}`);
76+
}
77+
if (finding.id === "missing_metric") {
78+
assert.ok(!String(metric || "").startsWith("gen_ai."), `${scenario}: missing GenAI metric ${metric}`);
79+
}
80+
}
81+
visitSample(sample);
82+
}
83+
}
84+
85+
for (const name of expectedMetricNames) {
86+
assert.ok(observedMetrics.has(name), `Latest GenAI reports did not observe metric ${name}`);
87+
}
88+
89+
// Weaver's missing_metric advice has no context, so the runner cannot constrain
90+
// that compatibility exception by metric name. Check it on the unfiltered report.
91+
const compatibilityReport = JSON.parse(fs.readFileSync(path.join(reportDir, "agent_success_compat.json"), "utf8"));
92+
assert.ok(compatibilityReport.samples?.length > 0, "Compatibility report contains no samples");
93+
for (const sample of compatibilityReport.samples) {
94+
for (const finding of collectAdvice(sample)) {
95+
if (finding.id === "missing_metric") {
96+
assert.equal(finding.signal_name, "gen_ai.client.token.usage", `Unexpected unregistered compatibility metric ${finding.signal_name}`);
97+
}
98+
}
99+
}
100+
101+
console.log("Latest GenAI semantic-convention reports contain the required attributes and metrics.");

0 commit comments

Comments
 (0)