Skip to content

Commit 73b0381

Browse files
authored
feat: Added compact type for partial granularity traces. (#3608)
1 parent c465f4c commit 73b0381

16 files changed

+1406
-633
lines changed

lib/metrics/names.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,23 @@ const DISTRIBUTED_TRACE = {
294294
TRANSPORT: 'TransportDuration'
295295
}
296296

297-
const SPAN_EVENT_PREFIX = 'SpanEvent/'
297+
const PARTIAL_GRANULARITY = '/PartialGranularity'
298+
const DISTRIBUTED_TRACING = 'DistributedTrace'
298299

299-
const PARTIAL_GRANULARITY = 'DistributedTrace/PartialGranularity'
300+
const PARTIAL_TRACE = {
301+
PREFIX: SUPPORTABILITY.NODEJS + PARTIAL_GRANULARITY,
302+
SPAN_PREFIX: SUPPORTABILITY.PREFIX + DISTRIBUTED_TRACING + PARTIAL_GRANULARITY,
303+
INSTRUMENTED: '/Span/Instrumented',
304+
KEPT: '/Span/Kept',
305+
DROPPED: SUPPORTABILITY.NODEJS + PARTIAL_GRANULARITY + '/NrIds/Dropped'
306+
}
300307

308+
const SPAN_EVENT_PREFIX = 'SpanEvent/'
301309
const SPAN_EVENTS = {
302310
SEEN: SUPPORTABILITY.PREFIX + SPAN_EVENT_PREFIX + 'TotalEventsSeen',
303311
SENT: SUPPORTABILITY.PREFIX + SPAN_EVENT_PREFIX + 'TotalEventsSent',
304312
DROPPED: SUPPORTABILITY.PREFIX + SPAN_EVENT_PREFIX + 'Discarded',
305-
LIMIT: SUPPORTABILITY.PREFIX + SPAN_EVENT_PREFIX + 'Limit',
306-
PARTIAL_PREFIX: SUPPORTABILITY.PREFIX + PARTIAL_GRANULARITY,
307-
KEPT: '/Span/Kept',
308-
INSTRUMENTED: '/Span/Instrumented',
313+
LIMIT: SUPPORTABILITY.PREFIX + SPAN_EVENT_PREFIX + 'Limit'
309314
}
310315

311316
const INFINITE_TRACING = {
@@ -408,6 +413,7 @@ module.exports = {
408413
NODEJS,
409414
NORMALIZED: 'NormalizedUri',
410415
OTHER_TRANSACTION,
416+
PARTIAL_TRACE,
411417
POSTGRES,
412418
PRISMA,
413419
QUEUETIME: 'WebFrontend/QueueTime',

lib/spans/helpers.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,10 @@ function addSpanKind({ segment, span }) {
6060
}
6161
}
6262

63-
/**
64-
* Checks if the segment is an entry point.
65-
* An entry point span is defined as the base segment of a transaction.
66-
* @param {object} params to function
67-
* @param {Transaction} params.transaction active transaction
68-
* @param {TraceSegment} params.segment segment that is creating span
69-
* @returns {boolean} true if the segment is an entry point span
70-
*/
71-
function isEntryPoint({ transaction, segment }) {
72-
return transaction?.baseSegment === segment
73-
}
74-
7563
module.exports = {
7664
HTTP_LIBRARY,
7765
CATEGORIES,
7866
SPAN_KIND,
7967
REGEXS,
80-
addSpanKind,
81-
isEntryPoint
68+
addSpanKind
8269
}

lib/spans/span-event-aggregator.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ class SpanEventAggregator extends EventAggregator {
8484
* @param {Transaction} params.transaction active transaction
8585
* @param {string} [params.parentId] GUID of the parent span.
8686
* @param {boolean} params.isRoot if segment is root segment
87+
* @param {boolean} params.isEntry if segment is entry point
8788
*/
88-
addSegment({ segment, transaction, parentId, isRoot }) {
89+
addSegment({ segment, transaction, parentId, isRoot, isEntry }) {
8990
// Check if the priority would be accepted before creating the event object.
9091

9192
if (transaction.priority < this._items.getMinimumPriority()) {
@@ -95,19 +96,11 @@ class SpanEventAggregator extends EventAggregator {
9596
return false
9697
}
9798

98-
const span = SpanEvent.fromSegment({ segment, transaction, parentId, isRoot })
99+
const span = SpanEvent.fromSegment({ segment, transaction, parentId, isRoot, isEntry })
99100

100101
// Do not add span to aggregator if it is part of a partial trace
101-
// We need to reparent spans or in the case of `compact`, associate
102-
// all exit spans dropped to the same entity as `nr.ids` and `nr.durations`
103-
if (transaction.partialType) {
104-
const prefix = `${this._metricNames.PARTIAL_PREFIX}/${transaction.partialType}`
105-
this._metrics.getOrCreateMetric(prefix).incrementCallCount()
106-
this._metrics.getOrCreateMetric(`${prefix}${this._metricNames.INSTRUMENTED}`).incrementCallCount()
107-
transaction.trace.addSpan({ span, id: segment.id, parentId })
108-
if (span) {
109-
this._metrics.getOrCreateMetric(`${prefix}${this._metricNames.KEPT}`).incrementCallCount()
110-
}
102+
if (transaction.partialTrace) {
103+
transaction.partialTrace.addSpan({ span, isEntry })
111104
} else if (span) {
112105
this.add(span, transaction.priority)
113106
}

0 commit comments

Comments
 (0)