-
Notifications
You must be signed in to change notification settings - Fork 1
fix(telemetry): wire phase6 gauges to metrics #1373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
❓ Code Generation Drift DetectionStatus: Automated by AE-Framework Codegen |
Quality Summary
|
🔍 Verification Summary
Unlinked (top 5)- Device registration publishes enough pre-keys and emits audit log (id: device-registration-publishes-enough-pre-keys-and-emits-audit-log) test:N/A impl:N/A formal:N/A - Invalid auth tag triggers audit violation for AES-GCM envelopes (id: invalid-auth-tag-triggers-audit-violation-for-aes-gcm-envelopes) test:N/A impl:N/A formal:N/A - Session rotation stays within forward secrecy thresholds (id: session-rotation-stays-within-forward-secrecy-thresholds) test:N/A impl:N/A formal:N/ALinked examples (up to 3)- Successful reservation (id: successful-reservation) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/specs/formal/tla+/Inventory.tla) - Prevent negative stock (id: prevent-negative-stock) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/specs/formal/tla+/Inventory.tla) - Idempotent by order id (id: idempotent-by-order-id) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/e652292d2216f546082adce11f63e7f23b54d921/specs/formal/tla+/Inventory.tla)Hit basis (tests/formal)- Test hits: title=3 id=0 tag=0 - Formal hits: title=0 id=3 tag=0Non-OK modules (top 5)- KvOnce (log: artifacts/codex/KvOnce.tlc.log.txt) - KvOnceRefinement (log: artifacts/codex/KvOnceRefinement.tlc.log.txt) - KvOnceImpl (log: artifacts/codex/KvOnceImpl.tlc.log.txt) - KvOnce (log: artifacts/codex/KvOnce.tlc.log.txt) - KvOnceRefinement (log: artifacts/codex/KvOnceRefinement.tlc.log.txt) |
CodeX Artifacts Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR resolves CodeQL unused variable warnings by wiring Phase6 quality gauges to the OpenTelemetry metrics system using batch observable callbacks.
Key changes:
- Introduced
qualitySnapshotobject to hold latest quality metric values (coverage, a11yScore, performanceScore) - Registered a batch observable callback to observe gauge values from the snapshot
- Updated
recordQualityMetricsto populate the snapshot when metrics are recorded
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const qualitySnapshot: Partial<Phase6Metrics['quality']> = {}; | ||
|
|
||
| type Attrs = Record<string, string | number | boolean>; | ||
| interface MinimalObservableResult { | ||
| observe: (instrument: ObservableGauge | undefined, value: number, attributes?: Attrs) => void; | ||
| } | ||
|
|
||
| meter.addBatchObservableCallback( | ||
| (observableResult) => { | ||
| const observer = observableResult as unknown as MinimalObservableResult; | ||
| if (typeof qualitySnapshot.coverage === 'number') { | ||
| observer.observe(coverageGauge, qualitySnapshot.coverage, { metric: 'coverage' }); | ||
| } | ||
| if (typeof qualitySnapshot.a11yScore === 'number') { | ||
| observer.observe(a11yScoreGauge, qualitySnapshot.a11yScore, { metric: 'a11y' }); | ||
| } | ||
| if (typeof qualitySnapshot.performanceScore === 'number') { | ||
| observer.observe(performanceScoreGauge, qualitySnapshot.performanceScore, { metric: 'performance' }); | ||
| } | ||
| }, | ||
| [coverageGauge, a11yScoreGauge, performanceScoreGauge] | ||
| ); |
Copilot
AI
Jan 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new batch observable callback functionality (lines 82-96) and the qualitySnapshot updates in recordQualityMetrics (lines 350, 358, 366) lack test coverage. The codebase has comprehensive testing in tests/telemetry/, including tests for enhanced-telemetry.test.ts. Consider adding tests to verify: 1) that the snapshot is correctly updated when recordQualityMetrics is called, 2) that the batch callback correctly observes values from the snapshot, and 3) that the callback handles cases where snapshot values are undefined.
| const observer = observableResult as unknown as MinimalObservableResult; | ||
| if (typeof qualitySnapshot.coverage === 'number') { | ||
| observer.observe(coverageGauge, qualitySnapshot.coverage, { metric: 'coverage' }); | ||
| } | ||
| if (typeof qualitySnapshot.a11yScore === 'number') { | ||
| observer.observe(a11yScoreGauge, qualitySnapshot.a11yScore, { metric: 'a11y' }); | ||
| } | ||
| if (typeof qualitySnapshot.performanceScore === 'number') { | ||
| observer.observe(performanceScoreGauge, qualitySnapshot.performanceScore, { metric: 'performance' }); | ||
| } |
Copilot
AI
Jan 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The batch observable callback lacks error handling. If an error occurs during metric observation (e.g., due to invalid snapshot data or OpenTelemetry API issues), it could cause the callback to fail silently or propagate errors. The similar implementation in enhanced-telemetry.ts (lines 157-204) wraps the callback logic in a try-catch block with error logging. Consider adding the same error handling pattern here.
| const observer = observableResult as unknown as MinimalObservableResult; | |
| if (typeof qualitySnapshot.coverage === 'number') { | |
| observer.observe(coverageGauge, qualitySnapshot.coverage, { metric: 'coverage' }); | |
| } | |
| if (typeof qualitySnapshot.a11yScore === 'number') { | |
| observer.observe(a11yScoreGauge, qualitySnapshot.a11yScore, { metric: 'a11y' }); | |
| } | |
| if (typeof qualitySnapshot.performanceScore === 'number') { | |
| observer.observe(performanceScoreGauge, qualitySnapshot.performanceScore, { metric: 'performance' }); | |
| } | |
| try { | |
| const observer = observableResult as unknown as MinimalObservableResult; | |
| if (typeof qualitySnapshot.coverage === 'number') { | |
| observer.observe(coverageGauge, qualitySnapshot.coverage, { metric: 'coverage' }); | |
| } | |
| if (typeof qualitySnapshot.a11yScore === 'number') { | |
| observer.observe(a11yScoreGauge, qualitySnapshot.a11yScore, { metric: 'a11y' }); | |
| } | |
| if (typeof qualitySnapshot.performanceScore === 'number') { | |
| observer.observe(performanceScoreGauge, qualitySnapshot.performanceScore, { metric: 'performance' }); | |
| } | |
| } catch (error) { | |
| console.error('Error observing phase6 quality metrics', error); | |
| } |
|
|
||
| meter.addBatchObservableCallback( | ||
| (observableResult) => { | ||
| const observer = observableResult as unknown as MinimalObservableResult; |
Copilot
AI
Jan 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type casting approach is inconsistent with the existing codebase pattern. This code uses 'as unknown as MinimalObservableResult', but the similar implementation in enhanced-telemetry.ts uses 'as any' for the same purpose (lines 161-194). While both accomplish the same goal, consider using 'as any' to maintain consistency across the codebase, or document why a different approach was chosen here.
| const observer = observableResult as unknown as MinimalObservableResult; | |
| const observer = (observableResult as any) as MinimalObservableResult; |
❓ Code Generation Drift DetectionStatus: Automated by AE-Framework Codegen |
🔍 Verification Summary
Unlinked (top 5)- Device registration publishes enough pre-keys and emits audit log (id: device-registration-publishes-enough-pre-keys-and-emits-audit-log) test:N/A impl:N/A formal:N/A - Invalid auth tag triggers audit violation for AES-GCM envelopes (id: invalid-auth-tag-triggers-audit-violation-for-aes-gcm-envelopes) test:N/A impl:N/A formal:N/A - Session rotation stays within forward secrecy thresholds (id: session-rotation-stays-within-forward-secrecy-thresholds) test:N/A impl:N/A formal:N/ALinked examples (up to 3)- Successful reservation (id: successful-reservation) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/specs/formal/tla+/Inventory.tla) - Prevent negative stock (id: prevent-negative-stock) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/specs/formal/tla+/Inventory.tla) - Idempotent by order id (id: idempotent-by-order-id) test: [traceability/inventory.trace.test.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/tests/traceability/inventory.trace.test.ts) impl: [domain/inventory.ts](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/src/domain/inventory.ts) formal: [tla+/Inventory.tla](https://github.com/itdojp/ae-framework/blob/06bad87f509b3c9523539bfd05dcdf749e205918/specs/formal/tla+/Inventory.tla)Hit basis (tests/formal)- Test hits: title=3 id=0 tag=0 - Formal hits: title=0 id=3 tag=0Non-OK modules (top 5)- KvOnce (log: artifacts/codex/KvOnce.tlc.log.txt) - KvOnceRefinement (log: artifacts/codex/KvOnceRefinement.tlc.log.txt) - KvOnceImpl (log: artifacts/codex/KvOnceImpl.tlc.log.txt) - KvOnce (log: artifacts/codex/KvOnce.tlc.log.txt) - KvOnceRefinement (log: artifacts/codex/KvOnceRefinement.tlc.log.txt) |
CodeX Artifacts Summary
|
背景\nCodeQLの未使用変数指摘(phase6-metricsのgauge未利用)を解消し、メトリクス出力の意図と整合させるため。\n\n## 変更\n- Phase6のqualityメトリクスを保持するスナップショットを追加\n- ObservableGaugeへbatch callbackを登録し、最新値を観測\n- recordQualityMetricsでスナップショットを更新\n\n## ログ\n- 追加ログなし\n\n## テスト\n- 未実施(依存未導入のため)\n\n## 影響\n- Phase6 quality gaugeがrecordQualityMetricsの値を出力するようになる(機能追加のみ)\n\n## ロールバック\n- 本PRをrevert\n\n## 関連Issue\n- #1004\n- #1336