Automatically instruments source code to collect runtime information such as function calls, branch decisions, variable values, and execution traces while preserving original program semantics. Use when users need to: (1) Add logging or tracing to code for debugging, (2) Collect runtime execution data for analysis, (3) Monitor function calls and control flow, (4) Track variable values during execution, (5) Generate execution traces for testing or profiling. Supports Python, Java, JavaScript, and C/C++ with configurable instrumentation levels.
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill code-instrumentation-generator
Automatically instrument source code to collect runtime information while preserving program semantics.
Follow these steps to instrument code:
Understand the code structure and identify instrumentation points:
Choose appropriate instrumentation based on requirements:
Instrumentation levels:
Configuration options:
Add instrumentation hooks at identified points:
Function instrumentation:
Branch instrumentation:
Variable instrumentation:
Verify that instrumentation doesn't change program behavior:
Provide instrumented code and documentation:
# Original code
def calculate_sum(a, b):
result = a + b
return result
# Instrumented code
import logging
logging.basicConfig(level=logging.INFO)
def calculate_sum(a, b):
# Function entry instrumentation
logging.info(f"ENTER calculate_sum(a={a}, b={b})")
result = a + b
# Variable instrumentation
logging.info(f"VAR result={result}")
# Function exit instrumentation
logging.info(f"EXIT calculate_sum() -> {result}")
return result
// Original code
public int calculateSum(int a, int b) {
int result = a + b;
return result;
}
// Instrumented code
public int calculateSum(int a, int b) {
// Function entry instrumentation
System.out.println("ENTER calculateSum(a=" + a + ", b=" + b + ")");
int result = a + b;
// Variable instrumentation
System.out.println("VAR result=" + result);
// Function exit instrumentation
System.out.println("EXIT calculateSum() -> " + result);
return result;
}
// Original code
function calculateSum(a, b) {
const result = a + b;
return result;
}
// Instrumented code
function calculateSum(a, b) {
// Function entry instrumentation
console.log(`ENTER calculateSum(a=${a}, b=${b})`);
const result = a + b;
// Variable instrumentation
console.log(`VAR result=${result}`);
// Function exit instrumentation
console.log(`EXIT calculateSum() -> ${result}`);
return result;
}
// Original code
int calculate_sum(int a, int b) {
int result = a + b;
return result;
}
// Instrumented code
#include <stdio.h>
int calculate_sum(int a, int b) {
// Function entry instrumentation
printf("ENTER calculate_sum(a=%d, b=%d)\n", a, b);
int result = a + b;
// Variable instrumentation
printf("VAR result=%d\n", result);
// Function exit instrumentation
printf("EXIT calculate_sum() -> %d\n", result);
return result;
}
# Original code
def check_value(x):
if x > 0:
return "positive"
else:
return "non-positive"
# Instrumented code
def check_value(x):
logging.info(f"ENTER check_value(x={x})")
# Branch instrumentation
if x > 0:
logging.info("BRANCH if(x > 0) -> TRUE")
result = "positive"
else:
logging.info("BRANCH if(x > 0) -> FALSE")
result = "non-positive"
logging.info(f"EXIT check_value() -> {result}")
return result
Generate a configuration file to control instrumentation:
# instrumentation_config.py
INSTRUMENTATION_ENABLED = True
INSTRUMENT_FUNCTIONS = True
INSTRUMENT_BRANCHES = True
INSTRUMENT_VARIABLES = False
LOG_LEVEL = "INFO"
OUTPUT_FORMAT = "text" # or "json", "csv"
# Instrumented code with configuration
import instrumentation_config as config
def calculate_sum(a, b):
if config.INSTRUMENT_FUNCTIONS:
logging.info(f"ENTER calculate_sum(a={a}, b={b})")
result = a + b
if config.INSTRUMENT_VARIABLES:
logging.info(f"VAR result={result}")
if config.INSTRUMENT_FUNCTIONS:
logging.info(f"EXIT calculate_sum() -> {result}")
return result
## Instrumentation Report
**File**: calculator.py
**Instrumentation Date**: 2024-02-17
**Configuration**: Function-level + Branch-level
### Instrumented Functions
1. **calculate_sum(a, b)**
- Entry probe: Line 3
- Exit probe: Line 8
- Captures: Parameters (a, b), return value
2. **check_value(x)**
- Entry probe: Line 11
- Branch probe: Line 14 (if x > 0)
- Exit probe: Line 19
- Captures: Parameter (x), branch decision, return value
### Instrumentation Statistics
- Total functions instrumented: 2
- Total branches instrumented: 1
- Total variables instrumented: 0
- Estimated overhead: <5%
### Usage
Run the instrumented code normally. Instrumentation output will be written to:
- Console (stdout)
- Log file: instrumentation.log (if configured)
# Only instrument specific functions
INSTRUMENTED_FUNCTIONS = ["calculate_sum", "process_data"]
def should_instrument(func_name):
return func_name in INSTRUMENTED_FUNCTIONS
# Apply instrumentation conditionally
if should_instrument("calculate_sum"):
# Add instrumentation
pass
import time
def calculate_sum(a, b):
start_time = time.time()
logging.info(f"ENTER calculate_sum(a={a}, b={b})")
result = a + b
elapsed = time.time() - start_time
logging.info(f"EXIT calculate_sum() -> {result} [time={elapsed:.6f}s]")
return result
import json
import time
def calculate_sum(a, b):
entry_event = {
"type": "function_entry",
"function": "calculate_sum",
"params": {"a": a, "b": b},
"timestamp": time.time()
}
print(json.dumps(entry_event))
result = a + b
exit_event = {
"type": "function_exit",
"function": "calculate_sum",
"return_value": result,
"timestamp": time.time()
}
print(json.dumps(exit_event))
return result
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
Take arabelatso/code-instrumentation-generator from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.