Skip to content

Conversation

@amychisholm03
Copy link
Contributor

@amychisholm03 amychisholm03 commented Nov 19, 2025

Description

Fixes some sampling-related bugs by better encapsulating remote_parent_sampled and remote_parent_not_sampled sampling decisions with agent.sampler.remoteParentSampled and agent.sampler.remoteParentNotSampled. Also, replaces agent.transactionSampler with agent.sampler.root, so quite a few tests were modified to account for this.

Introduces the concept of a Sampler interface with exposes applySamplingDecision, which updates a given Transaction's priority and sampled flags.

How to Test

npm run unit
npm run integration

Related Issues

Precursor for core tracing and TraceIdRatioBasedSampler work.

@amychisholm03 amychisholm03 changed the title refactor: Break samplers into classes; introduce the concept of agent.sampler.* refactor: Break samplers into classes and store them on agent.sampler.* Nov 19, 2025
@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 94.51220% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.49%. Comparing base (47ed964) to head (7d0d13b).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
lib/transaction/index.js 83.33% 5 Missing ⚠️
lib/agent.js 81.81% 2 Missing ⚠️
lib/samplers/sampler.js 90.90% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3527      +/-   ##
==========================================
+ Coverage   81.48%   89.49%   +8.01%     
==========================================
  Files         411      425      +14     
  Lines       54553    55903    +1350     
  Branches        1        1              
==========================================
+ Hits        44455    50033    +5578     
+ Misses      10098     5870    -4228     
Flag Coverage Δ
integration-tests-cjs-20.x 73.93% <93.29%> (?)
integration-tests-esm-20.x 52.65% <60.36%> (+0.06%) ⬆️
integration-tests-esm-22.x 52.69% <60.36%> (?)
versioned-tests-20.x 81.06% <80.48%> (-0.32%) ⬇️
versioned-tests-22.x 81.07% <80.48%> (?)

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.

* `agent.sampler.partial_granularity.remote_parent_sampled`
* `agent.sampler.partial_granularity.remote_parent_not_sampled`

Will be deprecated, `full_granularity` takes precedence:
Copy link
Contributor

Choose a reason for hiding this comment

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

This hasn't been decided yet. The spec says to use both but agent.sampler.full_granularity.* takes precedence over agent.sampler.*.

Copy link
Contributor Author

@amychisholm03 amychisholm03 Nov 20, 2025

Choose a reason for hiding this comment

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

When I mean "deprecated", I'm referring to the agent.sampler.root, agent.sampler.remoteParentSampled, and agent.sampler.remoteParentNotSampled fields on the agent, not the config. In the future, it will be agent.sampler.fullGranularity.root, etc., which assumes the precedence logic of sampler.fullGranularity > sampler handled by the config initialization.

```javascript
...
// Decide sampling from w3c data
let full_sampler = null
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make these camel case since that's the preferred way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is more pseudo-codey than anything else, but I can make that change

})
this.config.on('sampling_target', function updateSamplingTarget(target) {
self.transactionSampler.samplingTarget = target
self.sampler.root.samplingTarget = target
Copy link
Contributor

Choose a reason for hiding this comment

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

So the transactionSampler is always the root sampler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it was.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though this updateSamplingTarget function does reveal another thing we will have to resolve with the sharing of AdaptiveSampler states, but that's out of scope for this PR.

@amychisholm03 amychisholm03 merged commit ad63441 into newrelic:main Nov 20, 2025
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 Nov 20, 2025
@amychisholm03 amychisholm03 added this to the Node.js Core tracing milestone Nov 20, 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.

2 participants