@@ -1029,35 +1029,13 @@ function acceptTraceContextPayload(traceparentHeader, tracestateHeader, transpor
10291029 }
10301030
10311031 // Decide sampling from w3c data
1032+ let sampler = null
10321033 if ( traceparent . isSampled === true ) {
1033- applySamplingStrategy ( { transaction : this , tracestate, sampler : this . agent . remoteParentSampledSampler } )
1034+ sampler = this . agent . remoteParentSampledSampler
1035+ sampler . applySamplingDecision ( { transaction : this , tracestate } )
10341036 } else if ( traceparent . isSampled === false ) {
1035- applySamplingStrategy ( { transaction : this , tracestate, sampler : this . agent . remoteParentNotSampledSampler } )
1036- }
1037- }
1038-
1039- /**
1040- * Updates the transaction's `sampled` and `priority` properties
1041- * based on the given sampling configuration.
1042- *
1043- * @param {* } params Function parameters.
1044- * @param {Transaction } params.transaction The transaction to update.
1045- * @param {Tracestate } [params.tracestate] A tracestate object with embedded New Relic intrinsics.
1046- * @param {object } params.sampler The sampler to use, e.g. AdaptiveSampler or TraceIdRatioBasedSampler.
1047- */
1048- function applySamplingStrategy ( { transaction, tracestate = null , sampler } ) {
1049- if ( sampler ?. toString ( ) !== 'AdaptiveSampler' ) {
1050- sampler . applySamplingDecision ( transaction )
1051- } else {
1052- // This case is if we're coming from the deprecated newrelic header logic
1053- // and we don't want to override the sampled and priority values
1054- if ( ! tracestate ) {
1055- return
1056- }
1057-
1058- // Explicitly set sampled and priority from tracestate intrinsics if available
1059- transaction . sampled = tracestate ?. intrinsics ? tracestate . isSampled : null
1060- transaction . priority = tracestate ?. intrinsics ? tracestate . priority : null
1037+ sampler = this . agent . remoteParentNotSampledSampler
1038+ sampler . applySamplingDecision ( { transaction : this , tracestate } )
10611039 }
10621040}
10631041
@@ -1164,10 +1142,16 @@ const _dtDefineAttrsFromTraceData = function _dtDefineAttrsFromTraceData(data, t
11641142 // Even though New Relic headers are deprecated,
11651143 // we still have to apply our sampling decision on top
11661144 // of the priority and sampled values we receive.
1145+ // However, this only applies if the sampler is NOT
1146+ // the default sampler (adaptive). In that case,
1147+ // we leave it alone.
1148+ let sampler
11671149 if ( data ?. sa ) {
1168- applySamplingStrategy ( { transaction : this , sampler : this . agent . remoteParentSampledSampler } )
1150+ sampler = this . agent . remoteParentSampledSampler
1151+ if ( sampler . toString ( ) !== 'AdaptiveSampler' ) sampler . applySamplingDecision ( { transaction : this } )
11691152 } else {
1170- applySamplingStrategy ( { transaction : this , sampler : this . agent . remoteParentNotSampledSampler } )
1153+ sampler = this . agent . remoteParentNotSampledSampler
1154+ if ( sampler . toString ( ) !== 'AdaptiveSampler' ) sampler . applySamplingDecision ( { transaction : this } )
11711155 }
11721156 }
11731157
@@ -1384,7 +1368,7 @@ Transaction.prototype.isSampled = function isSampled() {
13841368Transaction . prototype . _calculatePriority = function _calculatePriority ( ) {
13851369 if ( this . priority === null ) {
13861370 const sampler = this . agent . transactionSampler
1387- sampler . applySamplingDecision ( this )
1371+ sampler . applySamplingDecision ( { transaction : this } )
13881372 }
13891373}
13901374
0 commit comments