Skip to content

Commit 0639e97

Browse files
Adds exclusive time and measurements to spans
1 parent 74b0f11 commit 0639e97

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

packages/core/src/semanticAttributes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ export const SEMANTIC_ATTRIBUTE_SENTRY_OP = 'sentry.op';
1919
* Use this attribute to represent the origin of a span.
2020
*/
2121
export const SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'sentry.origin';
22+
23+
/**
24+
* Use this attribute to represent measurements of a span.
25+
*/
26+
export const SEMANTIC_ATTRIBUTE_MEASUREMENTS = 'measurements';

packages/core/src/tracing/span.ts

Lines changed: 12 additions & 1 deletion
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,
@@ -17,7 +18,11 @@ import { dropUndefinedKeys, logger, timestampInSeconds, uuid4 } from '@sentry/ut
1718

1819
import { DEBUG_BUILD } from '../debug-build';
1920
import { getMetricSummaryJsonForSpan } from '../metrics/metric-summary';
20-
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes';
21+
import {
22+
SEMANTIC_ATTRIBUTE_MEASUREMENTS,
23+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
24+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
25+
} from '../semanticAttributes';
2126
import { getRootSpan } from '../utils/getRootSpan';
2227
import {
2328
TRACE_FLAG_NONE,
@@ -115,6 +120,7 @@ export class Span implements SpanInterface {
115120
protected _endTime?: number;
116121
/** Internal keeper of the status */
117122
protected _status?: SpanStatusType | string;
123+
protected _exclusiveTime?: number;
118124

119125
private _logMessage?: string;
120126

@@ -159,6 +165,9 @@ export class Span implements SpanInterface {
159165
if (spanContext.endTimestamp) {
160166
this._endTime = spanContext.endTimestamp;
161167
}
168+
if (spanContext.exclusiveTime) {
169+
this._exclusiveTime = spanContext.exclusiveTime;
170+
}
162171
}
163172

164173
// This rule conflicts with another eslint rule :(
@@ -626,6 +635,8 @@ export class Span implements SpanInterface {
626635
trace_id: this._traceId,
627636
origin: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,
628637
_metrics_summary: getMetricSummaryJsonForSpan(this),
638+
exclusive_time: this._exclusiveTime,
639+
measurements: this._attributes[SEMANTIC_ATTRIBUTE_MEASUREMENTS] as Measurements | undefined,
629640
});
630641
}
631642

packages/types/src/span.ts

Lines changed: 8 additions & 1 deletion
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';
@@ -21,7 +22,8 @@ export type SpanAttributeValue =
2122
| boolean
2223
| Array<null | undefined | string>
2324
| Array<null | undefined | number>
24-
| Array<null | undefined | boolean>;
25+
| Array<null | undefined | boolean>
26+
| Measurements;
2527

2628
export type SpanAttributes = Partial<{
2729
'sentry.origin': string;
@@ -178,6 +180,11 @@ export interface SpanContext {
178180
* The origin of the span, giving context about what created the span.
179181
*/
180182
origin?: SpanOrigin;
183+
184+
/**
185+
* Exclusive time in milliseconds.
186+
*/
187+
exclusiveTime?: number;
181188
}
182189

183190
/** Span holding trace_id, span_id */

0 commit comments

Comments
 (0)