update start time of the context

This commit is contained in:
Yury Semikhatsky 2024-05-13 17:42:02 -07:00
parent 79796dda15
commit 907bf3e7e4
2 changed files with 9 additions and 2 deletions

View file

@ -179,7 +179,12 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
this._allocateNewTraceFile(this._state);
this._fs.mkdir(path.dirname(this._state.traceFile));
const event: trace.TraceEvent = { ...this._contextCreatedEvent, title: options.title, wallTime: Date.now() };
const event: trace.TraceEvent = {
...this._contextCreatedEvent,
title: options.title,
wallTime: Date.now(),
monotonicTime: monotonicTime()
};
this._fs.appendFile(this._state.traceFile, JSON.stringify(event) + '\n');
this._context.instrumentation.addListener(this, this._context);

View file

@ -388,9 +388,11 @@ export class TraceModernizer {
result.push({ ...event, monotonicTime: 0, origin: 'library' });
continue;
}
// Take wall time from the first event.
// Take wall and monotonic time from the first event.
if (!this._contextEntry.wallTime && event.type === 'before')
this._contextEntry.wallTime = event.wallTime;
if (!this._contextEntry.startTime && event.type === 'before')
this._contextEntry.startTime = event.startTime;
result.push(event);
}
return result;