• /
  • EnglishEspañolFrançais日本語한국어Português
  • Se connecterDémarrer

Configure sampling

|View as Markdown (English)

APM agent samplers control which transactions within a given service your agent sends to New Relic. This page covers sampler types such as adaptive and trace ID ratio based, adaptive sampling targets, and how to configure sampling based on upstream sampling decisions.

Configuration examples in this guide use YAML format (Java agent). For agent-specific syntax and the complete parameter reference, see:

How sampling works

Steps in a sampling decision

A sampling decision happens in five steps:

  1. Request arrives at your service.
  2. Agent checks sampling context: is this a root transaction, or did an upstream service already make a sampling decision?
  3. Agent applies the appropriate sampler based on the context and your configuration.
  4. Agent makes a sampling decision: sample or don't sample.
  5. Agent propagates the decision to downstream services via distributed trace context headers.

Sampler contexts

APM agents use three sampling contexts to handle different trace scenarios. Each context can have its own sampler configuration.

ContextWhen it appliesUse case
RootThe distributed trace originates from the current serviceControl sampling for traces that start from this service
Remote parent sampledAn upstream service already sampled this traceControl tracing for traces the upstream service sampled
Remote parent not sampledAn upstream service decided not to sample this traceControl sampling for traces the upstream service rejected

Sampler types

APM agents provide four sampler types, each appropriate for different scenarios.

Sampler typeHow it worksBest for
AdaptiveTargets a fixed number of traces per minute, regardless of traffic volumeConsistent number of traces regardless of traffic spikes
Trace ID ratio basedSamples a fixed percentage of traces based on trace IDDeterministic sampling across services as a percentage of traffic
Always-onSamples all transactionsComplete trace coverage for a specific context
Always-offSamples no transactionsDisabling sampling entirely for a specific context

Suggested configuration

With so many samplers to choose from, it can be hard to find the right configuration for your service. The best way to find the configuration that works for you is to observe the distribution of traces your service has today, and make small adjustments to work towards the distribution of traces that you want.

We recommend this configuration as a starting point:

distributed_tracing:
sampler:
root:
trace_id_ratio_based:
ratio: 0.1
remote_parent_sampled:
always_on
remote_parent_not_sampled:
always_off

This configuration samples 10% of traces from the root context, all traces from the remote_parent_sampled context, and no traces from the remote_parent_not_sampled context.

For some applications, this configuration is a reasonable starting point for a balanced distribution of traces. For others - for example, those where most traces originate from an upstream service - this configuration may over-prioritize remote_parent_sampled traces and under-prioritize root traces. In that case, try modifying the remote_parent_sampled configuration to capture only a percentage of upstream-sampled traces:

distributed_tracing:
sampler:
root:
trace_id_ratio_based:
ratio: 0.1
remote_parent_sampled:
trace_id_ratio_based:
ratio: 0.2 # Sample 20% of sampled traces originating upstream, instead of all of them
remote_parent_not_sampled:
always_off

What's next

Now that you understand sampling:

Conseil

Sampling configuration can be complex. Start with a single pattern and iterate based on your actual trace volume and needs. Use supportability metrics and trace queries to verify your configuration is working as expected.

Droits d'auteur © 2026 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.