|
| 1 | +# Sampling at New Relic |
| 2 | + |
| 3 | +The New Relic agent supports a robust sampling decision making interface. This is a work-in-progress feature. |
| 4 | + |
| 5 | +## Config |
| 6 | + |
| 7 | +Customers configure how they would like their transactions to be sampled under our `distributed_tracing` section in our config. Remember, sampling will only apply if a customer has `distributed_tracing.enabled` set to `true`. |
| 8 | + |
| 9 | +### Types |
| 10 | + |
| 11 | +- A "sampler mode" refers to the following config sections: `distributed_tracing.sampler`, `distributed_tracing.sampler.full_granularity`, and `distributed_tracing.sampler.partial_granularity`. They are defined by the three sections: `root`, `remote_parent_sampled`, and `remote_parent_not_sampled`. |
| 12 | +- A "sampler section" refers to `root`, `remote_parent_sampled`, or `remote_parent_not_sampled` within a particular sampler mode. The config defined at this section, i.e. `SAMPLER_TYPE: SAMPLER_SUBOPTION?`, describes the sampling decision for that particular scenario within that mode. |
| 13 | + - `root`: This is the main sampler for traces originating from the current service. |
| 14 | + - `remote_parent_sampled`: The sampler for when the upstream service has sampled the trace. |
| 15 | + - `remote_parent_not_sampled`: The sampler for when the upstream service has not sampled the trace. |
| 16 | + |
| 17 | +NOTE: `distributed_tracing.sampler` only exists for backward compatiability and may be deprecated in favor of `distributed_tracing.sampler.full_granularity`. For now, `full_granularity` will take precedence over the old path. |
| 18 | + |
| 19 | +### Full Config in Accordance to Spec |
| 20 | + |
| 21 | +```yaml |
| 22 | +... |
| 23 | +(Serverless DT attributes; they may be defined under distributed_tracing instead) |
| 24 | +account_id: string (unset by default, only set when using Serverless Mode) |
| 25 | +trusted_account_key: string (unset by default, only set when using Serverless Mode) |
| 26 | +primary_application_id: string (unset by default, only set when using Serverless Mode) |
| 27 | +... |
| 28 | +distributed_tracing: |
| 29 | + enabled: boolean (default true) |
| 30 | + exclude_newrelic_header: boolean (default false) |
| 31 | + enable_success_metrics (OPTIONAL): boolean (default true, set to false to disable supportability metrics) |
| 32 | + sampler: (section for sampling config options for different scenarios) |
| 33 | + adaptive_sampling_target (see note on Sampling Target below) |
| 34 | + root: (when the trace originates from the current service) |
| 35 | + ${SAMPLER_TYPE} (See `Sampler Options` below) |
| 36 | + ${SAMPLER_SUBOPTION} |
| 37 | + remote_parent_sampled: (when the upstream service has sampled the trace) |
| 38 | + ${SAMPLER_TYPE} (See `Sampler Options` below) |
| 39 | + ${SAMPLER_SUBOPTION} |
| 40 | + remote_parent_not_sampled: (when the upstream service has not sampled the trace) |
| 41 | + ${SAMPLER_TYPE} |
| 42 | + ${SAMPLER_SUBOPTION} |
| 43 | + full_granularity: |
| 44 | + enabled |
| 45 | + root: (when the trace originates from the current service) |
| 46 | + ${SAMPLER_TYPE} (See `Sampler Options` below) |
| 47 | + ${SAMPLER_SUBOPTION} |
| 48 | + remote_parent_sampled: (when the upstream service has sampled the trace) |
| 49 | + ${SAMPLER_TYPE} (See `Sampler Options` below) |
| 50 | + ${SAMPLER_SUBOPTION} |
| 51 | + remote_parent_not_sampled: (when the upstream service has not sampled the trace) |
| 52 | + ${SAMPLER_TYPE} |
| 53 | + ${SAMPLER_SUBOPTION} |
| 54 | + partial_granularity: |
| 55 | + enabled |
| 56 | + type ("reduced", "essential", "compact") |
| 57 | + root: (when the trace originates from the current service) |
| 58 | + ${SAMPLER_TYPE} (See `Sampler Options` below) |
| 59 | + ${SAMPLER_SUBOPTION} |
| 60 | + remote_parent_sampled: (when the upstream service has sampled the trace) |
| 61 | + ${SAMPLER_TYPE} (See `Sampler Options` below) |
| 62 | + ${SAMPLER_SUBOPTION} |
| 63 | + remote_parent_not_sampled: (when the upstream service has not sampled the trace) |
| 64 | + ${SAMPLER_TYPE} |
| 65 | + ${SAMPLER_SUBOPTION} |
| 66 | +... |
| 67 | +``` |
| 68 | + |
| 69 | +## Solution |
| 70 | + |
| 71 | +There are three sampler modes, each with three sampler sections, resulting in potentially nine different sampling decisions that the agent would have to support. We create a new `Sampler` instance (`AdaptiveSampler`, `AlwaysOnSampler`, `AlwaysOffSampler`, or `TraceIdRatioBasedSampler`, defined in this folder) for each of these sampler modes' sections. |
| 72 | + |
| 73 | +`agent.sampler` would be defined as: |
| 74 | + |
| 75 | +* `agent.sampler.fullGranularity.root` |
| 76 | +* `agent.sampler.fullGranularity.remoteParentSampled` |
| 77 | +* `agent.sampler.fullGranularity.remoteParentNotSampled` |
| 78 | +* `agent.sampler.partialGranularity.root` |
| 79 | +* `agent.sampler.partialGranularity.remoteParentSampled` |
| 80 | +* `agent.sampler.partialGranularity.remoteParentNotSampled` |
| 81 | + |
| 82 | +These fields currently exist (before core tracing was implemented); `agent.sampler.fullGranularity.*` will take precedence over these fields: |
| 83 | + |
| 84 | +* `agent.sampler.root` |
| 85 | +* `agent.sampler.remoteParentSampled` |
| 86 | +* `agent.sampler.remoteParentNotSampled` |
| 87 | + |
| 88 | +These samplers have a `applySamplingDecision({transaction})` function, which `Transaction` calls (in `lib/transaction/index.js`) to update its `sampled` field and therefore its `priority`. |
| 89 | + |
| 90 | +Unlike the other samplers, the `AdaptiveSampler` must share state with other `AdaptiveSamplers` with the same `sampling_target`, which complicates our seperate sampler instances approach. This will be fixed shortly, and this document will be updated to describe that solution. |
0 commit comments