Skip to content

Commit 525555b

Browse files
committed
fix(debugger): reuse loaded tracer for trace context in devtools client
The devtools worker evaluates an expression on every paused call frame to read the active trace and span IDs. That expression used global.require('dd-trace'), which re-resolves and re-requires the tracer module on each hit. Use globalThis._ddtrace instead, matching the singleton instance installed by bootstrap when the application first loads dd-trace. This avoids duplicate module resolution, works when the bare 'dd-trace' specifier is not resolvable from the paused frame (e.g. sirun benchmarks that load the tracer by path), and removes per-hit require overhead from the hot pause path.
1 parent 6267703 commit 525555b

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

  • packages/dd-trace/src/debugger/devtools_client

packages/dd-trace/src/debugger/devtools_client/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ require('./remote_config')
2323

2424
/** @typedef {import('node:inspector').Debugger.EvaluateOnCallFrameReturnType} EvaluateOnCallFrameResult */
2525

26-
// Expression to run on a call frame of the paused thread to get its active trace and span id.
2726
const templateExpressionSetupCode = `
2827
const $dd_inspect = global.require('node:util').inspect;
2928
const $dd_segmentInspectOptions = {
@@ -34,8 +33,10 @@ const templateExpressionSetupCode = `
3433
breakLength: Infinity
3534
};
3635
`
36+
37+
// Expression to run on a call frame of the paused thread to get its active trace and span id.
3738
const getDDTagsExpression = `(() => {
38-
const context = global.require('dd-trace').scope().active()?.context();
39+
const context = globalThis._ddtrace.scope().active()?.context();
3940
return { trace_id: context?.toTraceId(), span_id: context?.toSpanId() }
4041
})()`
4142

0 commit comments

Comments
 (0)