
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
function-trace
Advanced tools
A tiny universal function profiler and logger for full-stack developers. Trace execution time, monitor function calls, and track errors with zero configuration.
✨ Lightweight - Minimal overhead, perfect for production
⚡ Universal - Works with sync and async functions
📊 Performance Tracking - Automatic execution time measurement
📈 Statistics - Built-in call counts, error tracking, and history
🎨 Beautiful Output - Color-coded console logging
📦 Zero Dependencies - Pure TypeScript, no external packages
🔧 Type-Safe - Full TypeScript support with proper type inference
npm install function-trace
import { trace } from 'function-trace';
// Wrap any function with trace
const add = trace((a: number, b: number) => a + b, { log: true });
const result = add(5, 3);
// Output: [function-trace] anonymous executed in 0.05ms
console.log(add.stats); // { calls: 1, errors: 0, lastTime: 0.05, history: [0.05] }
import { trace } from 'function-trace';
const sum = () => {
return 1 + 2 + 3 + 4 + 5;
};
const tracedSum = trace(sum, { log: true });
tracedSum(); // [function-trace] sum executed in 0.02ms
tracedSum(); // [function-trace] sum executed in 0.01ms
tracedSum(); // [function-trace] sum executed in 0.02ms
console.log(tracedSum.stats);
// {
// calls: 3,
// errors: 0,
// lastTime: 0.02,
// history: [0.02, 0.01, 0.02]
// }
import { trace } from 'function-trace';
const fetchTodo = trace(
async (id: number) => {
const res = await fetch(
`https://jsonplaceholder.typicode.com/todos/${id}`
);
return res.json();
},
{ log: true }
);
await fetchTodo(1);
// [function-trace] fetchTodo executed in 145.32ms
console.log(fetchTodo.stats);
// {
// calls: 1,
// errors: 0,
// lastTime: 145.32,
// history: [145.32]
// }
import { trace } from 'function-trace';
const multiply = (a: number, b: number) => a * b;
const tracedMultiply = trace(multiply, { log: true });
tracedMultiply(3, 4);
// [function-trace] multiply executed in 0.03ms
trace<F>(fn: F, options?: TraceOptions): F & { stats: TraceStats }Wraps a function with performance tracking and returns the wrapped function with stats.
interface TraceOptions {
log?: boolean; // Enable console logging (default: false)
maxHistory?: number; // Number of execution times to keep (default: 50)
color?: boolean; // Enable colored output (default: true)
}
The wrapped function with attached stats property:
interface TraceStats {
calls: number; // Total number of calls
errors: number; // Total number of errors
lastTime: number; // Last execution time in ms
history: number[]; // Array of last N execution times
}
import { trace } from 'function-trace';
const getUserById = trace(
async (userId: string) => {
// Your database query
const user = await db.users.findById(userId);
return user;
},
{ log: true, maxHistory: 100 }
);
// Monitor performance over time
async function handleRequest(userId: string) {
const user = await getUserById(userId);
// Check if query is getting slower
const avgTime =
getUserById.stats.history.reduce((a, b) => a + b, 0) /
getUserById.stats.history.length;
if (avgTime > 100) {
console.warn('Database query is getting slow');
}
return user;
}
import { trace } from 'function-trace';
const apiCall = trace(
async (url: string) => {
const response = await fetch(url);
return response.json();
},
{ log: true, maxHistory: 200 }
);
// Track API performance
console.log(`Total API calls: ${apiCall.stats.calls}`);
console.log(`Failed calls: ${apiCall.stats.errors}`);
console.log(`Last response time: ${apiCall.stats.lastTime}ms`);
import { trace } from 'function-trace';
const criticalOperation = trace(
async () => {
// Some critical operation
},
{ log: true, maxHistory: 50 }
);
async function executeWithAlert() {
await criticalOperation();
const avgTime =
criticalOperation.stats.history.reduce((a, b) => a + b, 0) /
criticalOperation.stats.history.length;
if (avgTime > 1000) {
// Send alert to monitoring service
console.error('⚠️ Operation exceeded SLA threshold');
}
}
log: true during development for instant feedbacklog: false for performance-critical pathsmaxHistory based on your monitoring needsstats.errors to identify failing operationshistory array for performance trendsMIT © Masum Billah
Contributions are welcome! Feel free to submit a Pull Request.
FAQs
Tiny universal function profiler/logger for full-stack developers
We found that function-trace demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.