Skip to content

Commit 3f5b962

Browse files
feat(performance): Adds exclusive time and measurements to spans (#10704)
Adds exclusive_time and measurements as fields to the Span class. Drops measurements from Transactions since it is now inherited from spans.
2 parents e6ea73d + 7156838 commit 3f5b962

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

packages/core/src/tracing/span.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable max-lines */
22
import type {
33
Instrumenter,
4+
Measurements,
45
Primitive,
56
Span as SpanInterface,
67
SpanAttributeValue,
@@ -115,6 +116,9 @@ export class Span implements SpanInterface {
115116
protected _endTime?: number | undefined;
116117
/** Internal keeper of the status */
117118
protected _status?: SpanStatusType | string | undefined;
119+
protected _exclusiveTime?: number;
120+
121+
protected _measurements: Measurements;
118122

119123
private _logMessage?: string;
120124

@@ -159,6 +163,10 @@ export class Span implements SpanInterface {
159163
if (spanContext.endTimestamp) {
160164
this._endTime = spanContext.endTimestamp;
161165
}
166+
if (spanContext.exclusiveTime) {
167+
this._exclusiveTime = spanContext.exclusiveTime;
168+
}
169+
this._measurements = spanContext.measurements ? { ...spanContext.measurements } : {};
162170
}
163171

164172
// This rule conflicts with another eslint rule :(
@@ -626,6 +634,8 @@ export class Span implements SpanInterface {
626634
trace_id: this._traceId,
627635
origin: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,
628636
_metrics_summary: getMetricSummaryJsonForSpan(this),
637+
exclusive_time: this._exclusiveTime,
638+
measurements: Object.keys(this._measurements).length > 0 ? this._measurements : undefined,
629639
});
630640
}
631641

packages/core/src/tracing/transaction.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
Contexts,
44
DynamicSamplingContext,
55
MeasurementUnit,
6-
Measurements,
76
SpanTimeInput,
87
Transaction as TransactionInterface,
98
TransactionContext,
@@ -31,8 +30,6 @@ export class Transaction extends SpanClass implements TransactionInterface {
3130

3231
protected _name: string;
3332

34-
private _measurements: Measurements;
35-
3633
private _contexts: Contexts;
3734

3835
private _trimEnd?: boolean | undefined;
@@ -53,7 +50,6 @@ export class Transaction extends SpanClass implements TransactionInterface {
5350
*/
5451
public constructor(transactionContext: TransactionContext, hub?: Hub) {
5552
super(transactionContext);
56-
this._measurements = {};
5753
this._contexts = {};
5854

5955
// eslint-disable-next-line deprecation/deprecation

packages/types/src/span.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { TraceContext } from './context';
22
import type { Instrumenter } from './instrumenter';
3+
import type { Measurements } from './measurement';
34
import type { Primitive } from './misc';
45
import type { HrTime } from './opentelemetry';
56
import type { Transaction } from './transaction';
@@ -178,6 +179,16 @@ export interface SpanContext {
178179
* The origin of the span, giving context about what created the span.
179180
*/
180181
origin?: SpanOrigin | undefined;
182+
183+
/**
184+
* Exclusive time in milliseconds.
185+
*/
186+
exclusiveTime?: number;
187+
188+
/**
189+
* Measurements of the Span.
190+
*/
191+
measurements?: Measurements;
181192
}
182193

183194
/** Span holding trace_id, span_id */

0 commit comments

Comments
 (0)