Skip to content

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.

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).

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

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

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)

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)

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

Track test execution time:

{
"metrics": {
"test-time": {
"$ref": "test-time",
"command": "command-that-outputs-test-duration-ms"
}
}
}
  • Unit: Duration

Track the number of direct dependencies:

{
"metrics": {
"deps": {
"$ref": "dependencies-count",
"command": "jq '.dependencies | length' package.json"
}
}
}
  • Unit: Integer

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"
}
}
}
  • 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)

Choose the right unit for proper formatting:

UnitExampleUse Case
percent85.5%Coverage, ratios
integer1,234Counts, LOC
bytes1.5 MBFile sizes, bundles
duration1m 30sBuild/test time
decimal3.14Generic numbers

For templates with default commands, reference them directly:

{
"metrics": {
"loc": { "$ref": "loc" }
}
}

The object key (loc) becomes the metric ID.

Customize how metrics appear in reports:

{
"metrics": {
"test-coverage": {
"$ref": "coverage",
"name": "Test Coverage",
"command": "@collect coverage-lcov ./coverage/lcov.info"
}
}
}

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.

Built-in collectors run faster than shell commands because they execute in-process.

Count lines of code using the SCC tool:

Terminal window
@collect loc ./src
@collect loc . --language TypeScript
@collect loc ./app --language "PHP,JavaScript"

Calculate total file size (supports glob patterns):

Terminal window
@collect size ./dist
@collect size ./dist/**/*.js
@collect size ./build/*.wasm

Extract coverage from LCOV format:

Terminal window
@collect coverage-lcov ./coverage/lcov.info
@collect coverage-lcov ./coverage/lcov.info --type branch
@collect coverage-lcov ./coverage/lcov.info --type function

Options:

  • --type <line|branch|function> - Coverage type to extract (default: line)

Extract coverage from Cobertura XML format:

Terminal window
@collect coverage-cobertura ./coverage/coverage.xml
@collect coverage-cobertura ./coverage/coverage.xml --type branch
@collect coverage-cobertura ./coverage/coverage.xml --type function

Options:

  • --type <line|branch|function> - Coverage type to extract (default: line)
{
"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"
}
}
}
{
"metrics": {
"loc": {
"$ref": "loc",
"command": "@collect loc ./src --language PHP"
},
"coverage": {
"$ref": "coverage",
"command": "@collect coverage-cobertura ./coverage/coverage.xml"
}
}
}
{
"metrics": {
"loc": {
"$ref": "loc",
"command": "@collect loc . --language Go"
},
"binary-size": {
"$ref": "size",
"command": "@collect size ./bin/app"
}
}
}

Check your configuration before pushing to CI:

Terminal window
bunx unentropy verify

This validates:

  • JSON syntax
  • Required fields present
  • Valid metric references
  • Unit types correct

Verify all metrics collect successfully:

Terminal window
bunx unentropy test

Example 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:

Terminal window
bunx unentropy test --verbose

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 --verbose to see the exact command being run
  • Check file paths in commands match your project structure

Problem: Error: Unknown metric template "xyz"

Solution: Check the metric reference against the built-in metrics list. Use bunx unentropy verify to validate configuration.

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"
}
}
}