Skip to content

Conversation

@bizob2828
Copy link
Member

Description

The Node.js agent instrumented setTimeout and setInterval. This was done many years ago to propagate async context through timers. When we introduced an async context manager based on AsyncLocalStorage this instrumentation isn't necessary. On top of that, not only did we propagate context but we created segments/spans for these actions. This caused a lot of unncessary segments/spans to show that a setTimeout or setInterval was called. This PR disables the timers instrumentation by default. Aside from creating useless segments/spans, it typically spammed the debug+ level logger because a lot of 3rd party libraries and applications rely on setTimeout and setInterval to drive internals. You would see a lot of not recording setTimeout setInterval because it was not in an active transaction. Now, durations of child instrumented actions will be accounted for in the actual functions and not in the setTimeout or setInterval. However, if customers still want this level of observability, they can re-enable the instrumentation via config.instrumentation.timers.enabled to true or NEW_RELIC_INSTRUMENTATION_TIMERS_ENABLED to true.

Note: I had to open a branch of @newrelic/apollo-server-plugin to fix segment trees without timers. That PR will fail until we release the agent.

Related Issues

Closes #3084

disable `timers.setTimeout` and `timers.setInterval` by default.
jsumners-nr
jsumners-nr previously approved these changes Oct 8, 2025
Copy link
Contributor

@jsumners-nr jsumners-nr left a comment

Choose a reason for hiding this comment

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

🎉

@codecov
Copy link

codecov bot commented Oct 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.61%. Comparing base (5ae02c7) to head (1d990e4).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3414      +/-   ##
==========================================
- Coverage   97.73%   97.61%   -0.13%     
==========================================
  Files         393      398       +5     
  Lines       54014    54191     +177     
  Branches        1        1              
==========================================
+ Hits        52792    52896     +104     
- Misses       1222     1295      +73     
Flag Coverage Δ
integration-tests-cjs-20.x 74.04% <100.00%> (-0.06%) ⬇️
integration-tests-cjs-22.x 74.07% <100.00%> (-0.06%) ⬇️
integration-tests-cjs-24.x 74.76% <100.00%> (-0.07%) ⬇️
integration-tests-esm-20.x 51.60% <100.00%> (+0.05%) ⬆️
integration-tests-esm-22.x 51.66% <100.00%> (+0.05%) ⬆️
integration-tests-esm-24.x 52.90% <100.00%> (+0.04%) ⬆️
unit-tests-20.x 88.31% <100.00%> (-0.15%) ⬇️
unit-tests-22.x 88.33% <100.00%> (-0.14%) ⬇️
unit-tests-24.x 88.37% <100.00%> (-0.14%) ⬇️
versioned-tests-20.x 80.85% <100.00%> (-0.32%) ⬇️
versioned-tests-22.x 80.86% <100.00%> (-0.32%) ⬇️
versioned-tests-24.x 80.80% <100.00%> (-0.32%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bizob2828 bizob2828 merged commit b925d3d into newrelic:main Oct 8, 2025
24 of 25 checks passed
@github-project-automation github-project-automation bot moved this from Needs PR Review to Done: Issues recently completed in Node.js Engineering Board Oct 8, 2025
@bizob2828 bizob2828 deleted the default-timers-to-off branch October 8, 2025 16:35
@github-actions github-actions bot mentioned this pull request Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done: Issues recently completed

Development

Successfully merging this pull request may close these issues.

Disable setTimeout and setInterval instrumentation by default

2 participants