Skip to content

Commit cb0c864

Browse files
szegedisabrenner
authored andcommitted
Emit span IDs in profiles as 64-bit numbers instead of as strings. (#6281)
This significantly reduces the maximum memory use of profile serializations.
1 parent 459aa90 commit cb0c864

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

integration-tests/profiler/profiler.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ describe('profiler', () => {
389389
for (const label of sample.label) {
390390
switch (label.key) {
391391
case tsKey: ts = label.num; break
392-
case spanKey: spanId = label.str; break
393-
case rootSpanKey: rootSpanId = label.str; break
392+
case spanKey: spanId = label.num; break
393+
case rootSpanKey: rootSpanId = label.num; break
394394
case endpointKey: endpoint = label.str; break
395395
case threadNameKey: threadName = label.str; break
396396
case threadIdKey: threadId = label.str; break

packages/dd-trace/src/opentracing/span_context.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class DatadogSpanContext {
5959
return this._spanId.toString(10)
6060
}
6161

62+
toBigIntSpanId () {
63+
return this._spanId.toBigInt()
64+
}
65+
6266
toTraceparent () {
6367
const flags = this._sampling.priority >= AUTO_KEEP ? '01' : '00'
6468
const traceId = this.toTraceId(true)

packages/dd-trace/src/profiling/profilers/event_plugins/event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class EventPlugin extends TracingPlugin {
5252
}
5353

5454
const context = (ctx.currentStore?.span || this.activeSpan)?.context()
55-
event._ddSpanId = context?.toSpanId()
56-
event._ddRootSpanId = context?._trace.started[0]?.context().toSpanId() || event._ddSpanId
55+
event._ddSpanId = context?.toBigIntSpanId()
56+
event._ddRootSpanId = context?._trace.started[0]?.context().toBigIntSpanId() || event._ddSpanId
5757

5858
this.#eventHandler(this.extendEvent(event, ctx))
5959
}

packages/dd-trace/src/profiling/profilers/events.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,11 @@ class EventSerializer {
273273
new Label({ key: this.timestampLabelKey, num: dateOffset + BigInt(Math.round(endTime * MS_TO_NS)) })
274274
]
275275
if (_ddSpanId) {
276-
label.push(labelFromStr(this.stringTable, this.spanIdKey, _ddSpanId))
276+
label.push(
277+
new Label({ key: this.spanIdKey, num: _ddSpanId }))
277278
}
278279
if (_ddRootSpanId) {
279-
label.push(labelFromStr(this.stringTable, this.rootSpanIdKey, _ddRootSpanId))
280+
label.push(new Label({ key: this.rootSpanIdKey, num: _ddRootSpanId }))
280281
}
281282

282283
const sampleInput = {

packages/dd-trace/src/profiling/profilers/wall.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ class NativeWallProfiler {
215215

216216
_updateContext (context) {
217217
if (context.spanId !== null && typeof context.spanId === 'object') {
218-
context.spanId = context.spanId.toString(10)
218+
context.spanId = context.spanId.toBigInt()
219219
}
220220
if (context.rootSpanId !== null && typeof context.rootSpanId === 'object') {
221-
context.rootSpanId = context.rootSpanId.toString(10)
221+
context.rootSpanId = context.rootSpanId.toBigInt()
222222
}
223223
if (context.webTags !== undefined && context.endpoint === undefined) {
224224
// endpoint may not be determined yet, but keep it as fallback

packages/dd-trace/test/profiling/profilers/events.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('profilers/events', () => {
1717
// Set up a mock span to simulate tracing context
1818
const span = {
1919
context: () => ({
20-
toSpanId: () => '1234',
20+
toBigIntSpanId: () => 1234n,
2121
_trace: {
2222
started: [span]
2323
}

0 commit comments

Comments
 (0)