Callstack Tracking Overview
Automatic Collection
Automatic callstack trackingon Naite.t() calls
Call Path
Function call sequenceFile location info
Debugging Support
Identify problem locationTrace root cause
Viewer Integration
Visualize in VSCodeClick to navigate
What is a Callstack?
A callstack is a data structure that tracks the order of function calls during program execution. Naite automatically collects the callstack at the point ofNaite.t() calls, allowing you to pinpoint exactly where logs were recorded.
Why is Callstack Important?
In complex applications, a single operation executes through multiple functions. When problems occur, knowing the path through which functions were called makes debugging much easier.- Limitations of console.log
- Naite's Solution
Basic Structure
The callstack information collected by Naite is as follows:Callstack Example
Callstack Example
createUser(line 15): Location whereNaite.t()was actually calledtest(line 42): Test code calledcreateUserrunWithMockContext: Sonamuβs Context wrapper (ends here)
How Callstack Collection Works
extractCallStack() Behavior
Naite uses JavaScriptβsError object to collect callstacks.
1
Create Error Object
Get current callstack as string with
new Error().stack.2
Remove Unnecessary Frames
Exclude
Error, extractCallStack, Naite.t frames (slice(3)).3
Parse
Parse each line into
StackFrame objects.4
End at Context Boundary
Cut at
runWithContext when encountered. Beyond that is Vitest internal code which is not meaningful.parseStackFrame() Logic
Parses two callstack formats:- Format 1: With Function Name
- Format 2: Anonymous Function
- Special Case: node:internal
Why End at runWithContext: Naite keeps only meaningful callstacks.
runWithContext is
Sonamuβs Context boundary, and above it is Vitestβs internal code which doesnβt help with
debugging.Practical Debugging Scenarios
1. Tracing Call Paths
Track only specific paths in complex function call chains.2. Finding Error Locations
Find the exact location when an error occurs.Value of Error Tracking
Value of Error Tracking
Regular This tells you the error occurred at line 78 in
console.log or console.error only shows the error message. But with Naiteβs callstack:- Exact File and Line: Exact code location where error occurred
- Call Path: Which functions were called leading to the error
- VSCode Integration: Navigate to code location with one click
- Context: Saved along with data at the time of error
validateUser:validateUser, which was called from line 45 in createUser, which was started from line 12 in the test.3. Analyzing Complex Call Chains
Analyze complex chains called in A β B β C β D order.4. Using fromFunction()
Filter only logs called from a specific function.- direct (Direct Call)
- indirect (Indirect Call)
- both (All, default)
Checks only the first frame of the callstack (
stack[0]).VSCode Viewer Integration
Naite Viewer visually displays callstack information and allows you to navigate to code locations with a single click.Callstack Visualization
When you click each log in Naite Viewer, it displays like this:Viewer Screen Example
Viewer Screen Example
- Click each frame to have VSCode editor navigate to the exact line in that file
- Immediately see code context
- Reduces debugging time
Practical Usage Examples
1
Check Logs in Viewer
After running tests, find suspicious logs in Naite Viewer.
2
Check Callstack
Click the log to view its callstack. Understand which functions it went through.
3
Navigate to Code Location
Click each frame in the callstack to view the actual code.
4
Identify and Fix Problem
Follow the callstack to find and fix the root cause.
Advanced Patterns
1. Finding Performance Bottlenecks
Combine callstack and timing information to find performance bottlenecks.2. Debugging Syncer
Track Syncerβs complex template generation process.3. Detecting Infinite Loops
Monitor the depth of recursive functions.4. Conditional Logging
Enable detailed logging only under certain conditions.Callstack Limitations
Ends at runWithContext
Naite stops callstack collection when it encountersrunWithContext or runWithMockContext.
runWithContextis Sonamuβs Context boundary- Above it is Vitest internal code (meaningless)
- Keep only meaningful callstack for better readability
node:internal Paths
Node.js internal paths have lineNumber set to 0:Anonymous Functions
Arrow functions and anonymous functions havefunctionName as null:
Best Practices
1
Log at Meaningful Locations
2
Log on Error Situations
3
Use Explicit Function Names
4
Utilize VSCode Viewer
Keep Naite Viewer open during local development and check callstacks by clicking logs. Navigating directly to code locations significantly speeds up debugging.
Cautions
Next Steps
Naite Viewer
Visually check callstacks with VSCode Extension.
Querying Logs
Filter logs from specific functions with fromFunction().
Recording Logs
Learn effective logging strategies.
What is Naite?
Return to Naite overview.