Skip to content

Commit bea0d4f

Browse files
committed
refactor(profiling): scope the OTEP-4947 start-up probe ids to the probe
canInstallContext() runs exactly once per process, so holding its two ids at module scope kept them live for the process lifetime to save an allocation that never repeats. As locals they are collectable as soon as the probe returns.
1 parent b0dd1b6 commit bea0d4f

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

packages/dd-trace/src/otel-thread-ctx.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,6 @@ function missingApiMember (ns) {
256256
}
257257
}
258258

259-
// Zero-filled ids for the probe below. A record is only ever readable while it is
260-
// installed, and an all-zero trace id identifies nothing.
261-
const PROBE_TRACE_ID = new Uint8Array(16)
262-
const PROBE_SPAN_ID = new Uint8Array(8)
263-
264259
// Install and detach one throwaway context, to establish that this process can
265260
// actually do it before any span depends on it.
266261
//
@@ -275,7 +270,10 @@ const PROBE_SPAN_ID = new Uint8Array(8)
275270
// declining to start is still an option.
276271
function canInstallContext (ns) {
277272
try {
278-
const probe = new ns.ThreadContext(PROBE_TRACE_ID, PROBE_SPAN_ID)
273+
// Zero-filled ids: the record is only readable while it is installed, which
274+
// is for the length of this function, and an all-zero trace id identifies
275+
// nothing.
276+
const probe = new ns.ThreadContext(new Uint8Array(16), new Uint8Array(8))
279277
probe.enter()
280278
ns.clearContext()
281279
return true

0 commit comments

Comments
 (0)