Skip to content

PROD-88323 Preload dd-trace before orka startup - #527

Merged
ChristosLabrou merged 1 commit into
masterfrom
fix-dd-trace-errors
Sep 30, 2026
Merged

ChristosLabrou merged 1 commit into
masterfrom
fix-dd-trace-errors

Conversation

@ChristosLabrou

Copy link
Copy Markdown
Contributor

dd-trace initializes too late in orka. lodash is required at module load in builder.ts and orka.ts, while dd-trace.init() runs only later inside orka(). The tracer then reports that lodash was loaded before it, so the lodash hooks never attach.

The same warning shows up in every service that boots through orka. The fix calls dd-trace.init() in a preload imported before lodash, when DD_SERVICE and DD_ENV are set. The existing tracer.use('koa', …) setup still runs after the config loads. A second init() returns the tracer already created.

@@ -0,0 +1,5 @@
import requireInjected from '../../require-injected';

if (process.env.DD_SERVICE && process.env.DD_ENV) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we are creating a new pre-loader for this? why don't we use the existing initializer? there are some configuration options that should be used like

tracer.use('koa', {
blacklist: config?.datadog?.blacklistedPaths,
blocklist: config?.datadog?.blacklistedPaths,
...config.datadog
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this initializer runs, lodash has already been imported from other imports (eg getLogger also imports lodash).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so datadog should be the first module loaded after diamorphosis, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly this doesn't work. The initializer runs after all imports are resolved. The error is still present even if I moved dd import at the top

@ChristosLabrou
ChristosLabrou merged commit f3ff479 into master Sep 30, 2026
14 checks passed
@ChristosLabrou
ChristosLabrou deleted the fix-dd-trace-errors branch September 30, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants