Skip to content

Commit 75f07ce

Browse files
committed
doc: Document trimming of transaction end time
1 parent fe1c9b9 commit 75f07ce

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

packages/apm/src/span.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,13 @@ export class Span implements SpanInterface, SpanContext {
253253
}
254254

255255
/**
256-
* Sets the finish timestamp on the current span
256+
* Sets the finish timestamp on the current span.
257+
* @param trimEnd If true, sets the end timestamp of the transaction to the highest timestamp of child spans, trimming
258+
* the duration of the transaction span. This is useful to discard extra time in the transaction span that is not
259+
* accounted for in child spans, like what happens in the idle transaction Tracing integration, where we finish the
260+
* transaction after a given "idle time" and we don't want this "idle time" to be part of the transaction.
257261
*/
258-
public finish(useLastSpanTimestamp: boolean = false): string | undefined {
262+
public finish(trimEnd: boolean = false): string | undefined {
259263
// This transaction is already finished, so we should not flush it again.
260264
if (this.timestamp !== undefined) {
261265
return undefined;
@@ -286,12 +290,7 @@ export class Span implements SpanInterface, SpanContext {
286290

287291
const finishedSpans = this.spanRecorder ? this.spanRecorder.finishedSpans.filter(s => s !== this) : [];
288292

289-
// The reason we do `useLastSpanTimestamp` is that if we use the Tracing integration with an idle transaction.
290-
// The idea is that after e.g. 500ms idle time, we finish the transaction
291-
// But we don't want the "idle time" taking into account for the end timestamp of the transaction
292-
// instead we search for the timestamp of the last finished span and change the end timestamp to the same
293-
// timestamp of the last finished span
294-
if (useLastSpanTimestamp && finishedSpans.length > 0) {
293+
if (trimEnd && finishedSpans.length > 0) {
295294
this.timestamp = finishedSpans.reduce((prev: Span, current: Span) => {
296295
if (prev.timestamp && current.timestamp) {
297296
return prev.timestamp > current.timestamp ? prev : current;

0 commit comments

Comments
 (0)