Metrics
Unentropy helps you track code metrics that matter to your project. Use built-in metrics for common indicators like coverage and bundle size, or define custom metrics specific to your domain.
Built-in Metrics
Section titled “Built-in Metrics”Unentropy includes pre-configured metric templates that work out of the box. Reference them with minimal configuration:
{ "metrics": { "loc": { "$ref": "loc" }, "coverage": { "$ref": "coverage", "command": "@collect coverage-lcov ./coverage/lcov.info" } }}This will generate reports with two metrics: lines of code (calculated from the whole repository) and test coverage (you need to run tests first with appropriate flags).
Coverage Metrics
Section titled “Coverage Metrics”Test Coverage
Section titled “Test Coverage”Track overall test coverage percentage across your codebase:
{ "metrics": { "coverage": { "$ref": "coverage", "command": "@collect coverage-lcov ./coverage/lcov.info" } }}- Unit: Percent (displays as
87.5%) - Note: Requires coverage report generation before metric collection
Branch and Function Coverage
Section titled “Branch and Function Coverage”Track branch or function coverage using the --type option:
{ "metrics": { "branch-coverage": { "$ref": "coverage", "name": "Branch Coverage", "command": "@collect coverage-lcov ./coverage/lcov.info --type branch" }, "func-coverage": { "$ref": "coverage", "name": "Function Coverage", "command": "@collect coverage-lcov ./coverage/lcov.info --type function" } }}- Unit: Percent
- Available types:
line(default),branch,function
Code Size Metrics
Section titled “Code Size Metrics”Lines of Code
Section titled “Lines of Code”Count lines of code in your project:
{ "metrics": { "loc": { "$ref": "loc" } }}This uses the default command @collect loc . which counts all lines in your project.
Customize the path or language:
{ "metrics": { "src-loc": { "$ref": "loc", "command": "@collect loc ./src --language TypeScript" } }}- Unit: Integer (displays as
4,521)
Bundle Size
Section titled “Bundle Size”Track production build artifact size:
{ "metrics": { "bundle": { "$ref": "size", "command": "@collect size ./dist" } }}Supports glob patterns for specific files:
{ "metrics": { "js-bundle": { "$ref": "size", "command": "@collect size ./dist/**/*.js" } }}- Unit: Bytes (auto-scales to KB, MB, GB)
Performance Metrics
Section titled “Performance Metrics”Build Time
Section titled “Build Time”Track how long your builds take:
{ "metrics": { "build-time": { "$ref": "build-time", "command": "command-that-outputs-milliseconds" } }}- Unit: Duration (auto-scales to ms, s, m, h)
- Note: No default command - too project-specific
Test Suite Duration
Section titled “Test Suite Duration”Track test execution time:
{ "metrics": { "test-time": { "$ref": "test-time", "command": "command-that-outputs-test-duration-ms" } }}- Unit: Duration
Dependency Metrics
Section titled “Dependency Metrics”Dependency Count
Section titled “Dependency Count”Track the number of direct dependencies:
{ "metrics": { "deps": { "$ref": "dependencies-count", "command": "jq '.dependencies | length' package.json" } }}- Unit: Integer
Custom Metrics
Section titled “Custom Metrics”Define metrics specific to your project needs. Any metric without $ref is a custom metric:
{ "metrics": { "api-endpoints": { "type": "numeric", "name": "API Endpoints", "description": "Number of exported API functions", "unit": "integer", "command": "grep -r 'export.*function' src/api | wc -l" } }}Custom Metric Properties
Section titled “Custom Metric Properties”- type:
numeric(required) - name: Display name in reports (required)
- description: What this metric tracks (optional)
- unit: How to format values (optional, see Unit Types)
- command: Shell command that outputs the metric value (required)
Unit Types
Section titled “Unit Types”Choose the right unit for proper formatting:
| Unit | Example | Use Case |
|---|---|---|
percent | 85.5% | Coverage, ratios |
integer | 1,234 | Counts, LOC |
bytes | 1.5 MB | File sizes, bundles |
duration | 1m 30s | Build/test time |
decimal | 3.14 | Generic numbers |
Using Metric Templates
Section titled “Using Metric Templates”Minimal Configuration
Section titled “Minimal Configuration”For templates with default commands, reference them directly:
{ "metrics": { "loc": { "$ref": "loc" } }}The object key (loc) becomes the metric ID.
Override Display Name
Section titled “Override Display Name”Customize how metrics appear in reports:
{ "metrics": { "test-coverage": { "$ref": "coverage", "name": "Test Coverage", "command": "@collect coverage-lcov ./coverage/lcov.info" } }}Multiple Variations
Section titled “Multiple Variations”Track the same type of metric for different paths:
{ "metrics": { "src-loc": { "$ref": "loc", "name": "Source Code Lines", "command": "@collect loc ./src" }, "test-loc": { "$ref": "loc", "name": "Test Code Lines", "command": "@collect loc ./tests" } }}Each gets a unique ID from its object key.
The @collect Shortcut
Section titled “The @collect Shortcut”Built-in collectors run faster than shell commands because they execute in-process.
Available Collectors
Section titled “Available Collectors”@collect loc <path>
Section titled “@collect loc <path>”Count lines of code using the SCC tool:
@collect loc ./src@collect loc . --language TypeScript@collect loc ./app --language "PHP,JavaScript"@collect size <path>
Section titled “@collect size <path>”Calculate total file size (supports glob patterns):
@collect size ./dist@collect size ./dist/**/*.js@collect size ./build/*.wasm@collect coverage-lcov <path>
Section titled “@collect coverage-lcov <path>”Extract coverage from LCOV format:
@collect coverage-lcov ./coverage/lcov.info@collect coverage-lcov ./coverage/lcov.info --type branch@collect coverage-lcov ./coverage/lcov.info --type functionOptions:
--type <line|branch|function>- Coverage type to extract (default:line)
@collect coverage-cobertura <path>
Section titled “@collect coverage-cobertura <path>”Extract coverage from Cobertura XML format:
@collect coverage-cobertura ./coverage/coverage.xml@collect coverage-cobertura ./coverage/coverage.xml --type branch@collect coverage-cobertura ./coverage/coverage.xml --type functionOptions:
--type <line|branch|function>- Coverage type to extract (default:line)
Example Configurations
Section titled “Example Configurations”JavaScript/TypeScript Project
Section titled “JavaScript/TypeScript Project”{ "metrics": { "loc": { "$ref": "loc", "command": "@collect loc ./src --language TypeScript" }, "coverage": { "$ref": "coverage", "command": "@collect coverage-lcov ./coverage/lcov.info" }, "bundle": { "$ref": "size", "command": "@collect size ./dist/**/*.js" } }}PHP Project
Section titled “PHP Project”{ "metrics": { "loc": { "$ref": "loc", "command": "@collect loc ./src --language PHP" }, "coverage": { "$ref": "coverage", "command": "@collect coverage-cobertura ./coverage/coverage.xml" } }}Go Project
Section titled “Go Project”{ "metrics": { "loc": { "$ref": "loc", "command": "@collect loc . --language Go" }, "binary-size": { "$ref": "size", "command": "@collect size ./bin/app" } }}Validating Configuration
Section titled “Validating Configuration”Check your configuration before pushing to CI:
bunx unentropy verifyThis validates:
- JSON syntax
- Required fields present
- Valid metric references
- Unit types correct
Testing Metric Collection
Section titled “Testing Metric Collection”Verify all metrics collect successfully:
bunx unentropy testExample output:
✓ Config schema valid
Collecting metrics:
✓ loc (integer) 4,521 0.8s ✓ coverage (percent) 87.3% 2.1s ✓ bundle (bytes) 240 KB 0.2s
All 3 metrics collected successfully.Use --verbose to see the exact commands being run:
bunx unentropy test --verboseTroubleshooting
Section titled “Troubleshooting”Metric Collection Fails
Section titled “Metric Collection Fails”Problem: Metric collection returns an error
Solutions:
- For coverage metrics: Run tests with coverage before collecting (
bun test --coverage) - For size metrics: Ensure build artifacts exist before collection
- Use
bunx unentropy test --verboseto see the exact command being run - Check file paths in commands match your project structure
Invalid Metric Reference
Section titled “Invalid Metric Reference”Problem: Error: Unknown metric template "xyz"
Solution: Check the metric reference against the built-in metrics list. Use bunx unentropy verify to validate configuration.
Missing Command
Section titled “Missing Command”Problem: Error: Metric requires a command
Solution: Some templates (like build-time) don’t have default commands. You must provide one:
{ "metrics": { "build-time": { "$ref": "build-time", "command": "your-build-time-command" } }}Related Resources
Section titled “Related Resources”- Configuration Reference - Complete config schema
- Quality Gates Guide - Set thresholds for metrics
- CLI Commands Reference - Test and verify commands