Skip to content

Commit

Permalink
Update stack trace limit for local change error (#22221)
Browse files Browse the repository at this point in the history
Investigating leaky ops issues based on stack traces for
`DDSCreatedInSummarizer`, `DataStoreCreatedInSummarizer`, and
`DataStoreMessageSubmittedInSummarizer` and realize stack traces are
limited to 10 for browsers other than Safari. Therefore, increase the
limit in this PR to help the investigation.
  • Loading branch information
msbaitest authored Aug 16, 2024
1 parent bcfda79 commit 425111e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/runtime/container-runtime/src/dataStoreContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ export abstract class FluidDataStoreContext
eventName,
type,
isSummaryInProgress: this.summarizerNode.isSummaryInProgress?.(),
stack: generateStack(),
stack: generateStack(30),
});
this.localChangesTelemetryCount--;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/datastore/src/dataStoreRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ export class FluidDataStoreRuntime
fluidDataStoreId: this.id,
fluidDataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
}),
stack: generateStack(),
stack: generateStack(30),
});
this.localChangesTelemetryCount--;
}
Expand Down
15 changes: 12 additions & 3 deletions packages/utils/telemetry-utils/src/errorLogging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,36 +181,45 @@ let stackPopulatedOnCreation: boolean | undefined;
* stack property is not accessed.
* For such cases it's better to not read stack property right away, but rather delay it until / if it's needed
* Some browsers will populate stack right away, others require throwing Error, so we do auto-detection on the fly.
* @param stackTraceLimit - stack trace limit for an error
* @returns Error object that has stack populated.
*
* @internal
*/
export function generateErrorWithStack(): Error {
export function generateErrorWithStack(stackTraceLimit?: number): Error {
const ErrorConfig = Error as unknown as { stackTraceLimit: number };
const originalStackTraceLimit = ErrorConfig.stackTraceLimit;
if (stackTraceLimit !== undefined) {
ErrorConfig.stackTraceLimit = stackTraceLimit;
}
const err = new Error("<<generated stack>>");

if (stackPopulatedOnCreation === undefined) {
stackPopulatedOnCreation = err.stack !== undefined;
}

if (stackPopulatedOnCreation) {
ErrorConfig.stackTraceLimit = originalStackTraceLimit;
return err;
}

try {
throw err;
} catch (error) {
ErrorConfig.stackTraceLimit = originalStackTraceLimit;
return error as Error;
}
}

/**
* Generate a stack at this callsite as if an error were thrown from here.
* @param stackTraceLimit - stack trace limit for an error
* @returns the callstack (does not throw)
*
* @internal
*/
export function generateStack(): string | undefined {
return generateErrorWithStack().stack;
export function generateStack(stackTraceLimit?: number): string | undefined {
return generateErrorWithStack(stackTraceLimit).stack;
}

/**
Expand Down

0 comments on commit 425111e

Please sign in to comment.