Skip to content

Commit 2cbc50e

Browse files
committed
refactor(stats): pass trace-root flag directly
1 parent 209c780 commit 2cbc50e

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

packages/dd-trace/src/span_stats.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,9 @@ class SpanBuckets extends Map {
155155
#includeTraceRoot
156156

157157
/**
158-
* @param {object} [options]
159-
* @param {boolean} [options.includeTraceRoot]
158+
* @param {boolean} [includeTraceRoot]
160159
*/
161-
constructor ({ includeTraceRoot = false } = {}) {
160+
constructor (includeTraceRoot = false) {
162161
super()
163162
this.#includeTraceRoot = includeTraceRoot
164163
}
@@ -181,20 +180,19 @@ class SpanBuckets extends Map {
181180
}
182181

183182
class TimeBuckets extends Map {
184-
#spanBucketOptions
183+
#includeTraceRoot
185184

186185
/**
187-
* @param {object} [spanBucketOptions]
188-
* @param {boolean} [spanBucketOptions.includeTraceRoot]
186+
* @param {boolean} [includeTraceRoot]
189187
*/
190-
constructor (spanBucketOptions) {
188+
constructor (includeTraceRoot = false) {
191189
super()
192-
this.#spanBucketOptions = spanBucketOptions
190+
this.#includeTraceRoot = includeTraceRoot
193191
}
194192

195193
forTime (time) {
196194
if (!this.has(time)) {
197-
this.set(time, new SpanBuckets(this.#spanBucketOptions))
195+
this.set(time, new SpanBuckets(this.#includeTraceRoot))
198196
}
199197

200198
return this.get(time)
@@ -221,7 +219,7 @@ class SpanStatsProcessor {
221219
const intervalMs = otlpExporter ? (flushIntervalMs ?? 10_000) : interval * 1e3
222220
this.interval = intervalMs / 1e3
223221
this.bucketSizeNs = intervalMs * 1e6
224-
this.buckets = new TimeBuckets({ includeTraceRoot: Boolean(otlpExporter) })
222+
this.buckets = new TimeBuckets(Boolean(otlpExporter))
225223
this.hostname = os.hostname()
226224
this.enabled = enabled
227225
this.otlpExporter = otlpExporter || null

packages/dd-trace/test/opentelemetry/metrics/otlp_span_stats_transformer.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ function makeTopLevelSpan (overrides = {}) {
4141
return makeSpan({ metrics: { [TOP_LEVEL_KEY]: 1 }, ...overrides })
4242
}
4343

44-
function makeBucket (spans, options) {
45-
const bucket = new SpanBuckets(options)
44+
function makeBucket (spans, includeTraceRoot) {
45+
const bucket = new SpanBuckets(includeTraceRoot)
4646
for (const span of spans) {
4747
bucket.forSpan(span).record(span)
4848
}
4949
return bucket
5050
}
5151

52-
function makeDrained (timeNs, spans, options) {
53-
return [{ timeNs, bucket: makeBucket(spans, options) }]
52+
function makeDrained (timeNs, spans, includeTraceRoot) {
53+
return [{ timeNs, bucket: makeBucket(spans, includeTraceRoot) }]
5454
}
5555

5656
/**
@@ -108,7 +108,7 @@ describe('OtlpStatsTransformer', () => {
108108
},
109109
})
110110
const payload = JSON.parse(transformer.transform(
111-
makeDrained(12340000000000, [span], { includeTraceRoot: true }),
111+
makeDrained(12340000000000, [span], true),
112112
BUCKET_SIZE_NS
113113
))
114114
const dataPoint = dataPointsOf(payload)[0]
@@ -179,7 +179,7 @@ describe('OtlpStatsTransformer', () => {
179179
makeSpan({ parent_id: { equals: () => false } }),
180180
]
181181
const payload = JSON.parse(transformer.transform(
182-
makeDrained(12340000000000, spans, { includeTraceRoot: true }),
182+
makeDrained(12340000000000, spans, true),
183183
BUCKET_SIZE_NS
184184
))
185185
const points = dataPointsOf(payload)
@@ -191,7 +191,7 @@ describe('OtlpStatsTransformer', () => {
191191
})
192192

193193
it('omits datadog.is_trace_root when its value is unknown', () => {
194-
const drained = makeDrained(12340000000000, [makeSpan()], { includeTraceRoot: true })
194+
const drained = makeDrained(12340000000000, [makeSpan()], true)
195195

196196
const payload = JSON.parse(transformer.transform(drained, BUCKET_SIZE_NS))
197197

packages/dd-trace/test/span_stats.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ describe('SpanBuckets', () => {
371371
const rootSpan = { ...basicSpan, parent_id: { equals: rootIdEquals } }
372372
const childSpan = { ...basicSpan, parent_id: { equals: childIdEquals } }
373373
const legacyBuckets = new SpanBuckets()
374-
const otlpBuckets = new SpanBuckets({ includeTraceRoot: true })
374+
const otlpBuckets = new SpanBuckets(true)
375375

376376
legacyBuckets.forSpan(rootSpan)
377377
legacyBuckets.forSpan(childSpan)
@@ -391,7 +391,7 @@ describe('SpanBuckets', () => {
391391

392392
it('should leave trace-root unknown when parent_id is missing or null', () => {
393393
for (const parentId of [undefined, null]) {
394-
const otlpBuckets = new SpanBuckets({ includeTraceRoot: true })
394+
const otlpBuckets = new SpanBuckets(true)
395395

396396
otlpBuckets.forSpan({ ...basicSpan, parent_id: parentId })
397397

0 commit comments

Comments
 (0)