Skip to content

Commit

Permalink
👌 Update handling stack trace creation comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Jun 16, 2021
1 parent 33c8837 commit a9f74a3
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/core/src/tools/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ export function formatErrorMessage(stack: StackTrace) {
}

/**
Creates a stacktrace starting from the previous call and working down.
- Has to be called at the utmost position of the RUM call stack.
- No internal monitoring should encapsulate the function, that is why we need to use callMonitored inside of it.
Creates a stacktrace without SDK internal frames.
Example:
```javascript
function utmostFunction() {
const handlingStack = createHandlingStackTrace()
callMonitored(() => {})
}
```
Constraints:
- Has to be called at the utmost position of the call stack.
- No internal monitoring should encapsulate the function, that is why we need to use callMonitored inside of it.
*/
export function createHandlingStackTrace(): StackTrace {
const internalFrameToSkip = 2 // Skip the two RUM internal frames in order to keep only the user calls
/**
* Skip the two internal frames:
* - SDK API (console.error, ...)
* - this function
* in order to keep only the user calls
*/
const internalFramesToSkip = 2
const error = new Error()
let stackTrace: StackTrace

Expand All @@ -104,7 +104,7 @@ export function createHandlingStackTrace(): StackTrace {

callMonitored(() => {
stackTrace = computeStackTrace(error)
stackTrace.stack = stackTrace.stack.slice(internalFrameToSkip)
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip)
})

return stackTrace!
Expand Down

0 comments on commit a9f74a3

Please sign in to comment.