Skip to content

Commit

Permalink
fix(spans): Allow zero exclusive time for INP spans (#11408)
Browse files Browse the repository at this point in the history
Allows exclusive time for spans to be 0, including inp spans.
  • Loading branch information
edwardgou-sentry committed Apr 3, 2024
1 parent 7dae9f6 commit 9bfadb5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/tracing/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class Span implements SpanInterface {
if (spanContext.endTimestamp) {
this._endTime = spanContext.endTimestamp;
}
if (spanContext.exclusiveTime) {
if (spanContext.exclusiveTime !== undefined) {
this._exclusiveTime = spanContext.exclusiveTime;
}
this._measurements = spanContext.measurements ? { ...spanContext.measurements } : {};
Expand Down
15 changes: 15 additions & 0 deletions packages/core/test/lib/tracing/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ describe('span', () => {
expect(span.name).toEqual('new name');
expect(span.description).toEqual('new name');
});

it('allows exclusiveTime to be set', () => {
const span = new Span({ name: 'span name', exclusiveTime: 100 });
expect(spanToJSON(span).exclusive_time).toEqual(100);
});

it('allows exclusiveTime to be zero', () => {
const span = new Span({ name: 'span name', exclusiveTime: 0 });
expect(spanToJSON(span).exclusive_time).toEqual(0);
});

it('drops undefined exclusiveTime', () => {
const span = new Span({ name: 'span name', exclusiveTime: undefined });
expect(Object.keys(spanToJSON(span)).includes('exclusive_time')).toBe(false);
});
});
/* eslint-enable deprecation/deprecation */

Expand Down
1 change: 1 addition & 0 deletions packages/types/src/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface SpanJSON {
trace_id: string;
origin?: SpanOrigin;
_metrics_summary?: Record<string, Array<MetricSummary>>;
exclusive_time?: number;
}

// These are aligned with OpenTelemetry trace flags
Expand Down

0 comments on commit 9bfadb5

Please sign in to comment.