Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: dd-trace appears to initialize before call to init() #5211

Open
ronjouch opened this issue Feb 5, 2025 · 0 comments
Open

[BUG]: dd-trace appears to initialize before call to init() #5211

ronjouch opened this issue Feb 5, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ronjouch
Copy link

ronjouch commented Feb 5, 2025

Tracer Version(s)

5.33.0, 5.35.0

Node.js Version(s)

22.13.1

Bug Report

Documentation says that there are 2 options to Import and initialize the tracer:

  1. In-JS, const tracer = require('dd-trace').init();
  2. Cmdline flag, node --require dd-trace/init app.js

However, I observe that dd-trace instrumentation is initialized even when I do not call .init(). Is this expected? Am I doing something wrong?

Reproduction Code

With this first listing, I observe that dd-trace instrumentation unexpectedly happens even when DD_TRACE_ENABLED is unset:

const { tracer } = require('dd-trace');
if (process.env.NODE_ENV === 'production' && process.env.DD_TRACE_ENABLED === 'true') {
  tracer.init();
}
export const DD_TRACER = tracer;

However, with this second listing below, I observe that dd-trace instrumentation satisfyingly does not happen when DD_TRACE_ENABLED is unset:

export let DD_TRACER;
if (process.env.NODE_ENV === 'production' && process.env.DD_TRACE_ENABLED === 'true') {
  const { tracer } = require('dd-trace');
  tracer.init();

  DD_TRACER = tracer;
}

It follows that it looks like instrumentation happens at import/require time. But this contradicts your documentation, which says that instrumentation happens at .init() time. Right? Or is it “auto-initialized” because of something I do? Or am I missing something?

Also, regarding “what makes you say that instrumentation happens?” : I believe instrumentation happens because dd-trace causes a crashes in the app test suite (where of course dd-trace shouldn't run, because process.env.NODE_ENV !== 'production') since this change of dd-trace 5.33.0 in packages/datadog-instrumentations/src/aws-sdk.js, where name = name.replaceAll(' ', '') legit crashes on name being undefined (“legit” because dd-trace shouldn't be running when running tests!).

To reformulate, this change made me realize that dd-trace instrumentation was unexpectedly happening when running the tests, and here I am trying to understand why.

Thanks for the halp 🙂.

Error Logs

No response

Tracer Config

No response

Operating System

Debian 6.12.12-1 x86_64

Bundling

No Bundling

@ronjouch ronjouch added the bug Something isn't working label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant