How To Use Dynamic Sampling

Dynamic sampling is a cost-savings feature available to customers on our Enterprise plan. Dynamic sampling enables you to control which API calls are logged to Moesif based on customer or API behavior. Moesif intelligently extrapolates metrics for accurate reporting even with multiple sample rates. That means that no matter what rules or sample rates you have set up you can be sure you are still seeing an accurate representation of your data.

Four types of Sample Rates

First, a quick primer on the four kinds of sample rates available and how they are prioritized. The four kinds of sample rates are:

  • Sample API calls for a single user or company
  • Sample API calls based on regex rules on API fields like specific URIs
  • Sample API calls based on user behaviors and demographics
  • Sample API calls globally

Sample rates are prioritized in the above order. This means that if a sample rate set for a specific customer, this will take priority over the sample rate associated with a behavioral cohort that a customer belongs to. A global sample rate has the lowest priority and is by default set to 100% for all customers.

Dynamic Sampling can be found by clicking your User Avatar on the bottom left side navigation and selecting Dynamic Sampling.

Dynamic Sampling Settings Location

The Dynamic Sampling Rules screen is where we can view and configure all of our sampling rule sets.

Dynamic Sampling Rules Page

Sampling API calls for a specific User

To set the sample rate for an individual user, click on + Rule and select New User Rule.

New Rule Pane

Once selected, a modal will appear. Under the Select Cohort heading, click the link that reads user lookup which will bring us to the User Lookup screen.

Selecting User Lookup

Navigating to the User Lookup screen is also possible by selecting Users on the left navigation pane when visible.

On the User Lookup screen, select the user you would like to set a sample rate for. You can create a filter at the top of the page under the Users Where heading to quickly find the user you are looking for or browse the list view at the bottom of the user lookup screen. Click the desired user’s ID to enter their Profile View.

User Lookup Screen

On the Profile View under Sample Rate, select the pencil icon to change the specific user’s sample rate.

User Profile View

Disable the inherit toggle to allow adjustments of the user’s sample rate. Set the desired sample rate and select save.

Set User Sample Rate

The newly set sample rate is displayed on the user’s Profile View.

Sample Rate Set In User View

Sampling API calls for a specific Company

To set the sample rate for an individual company, click on + Rule and select New Company Rule.

New Rule Pane

Once selected, a modal will appear. Under the Select Cohort heading click the link that reads company lookup which will bring us to the Company Lookup screen.

Selecting Company Lookup

Navigating to the Company Lookup screen is also possible by selecting Companies in the left navigation pane when visible.

On the Company Lookup screen, select the company you would like to set a sample rate for. You can create a filter at the top of the page under the Companies Where heading to quickly find the company you are looking for or browse the list view at the bottom of the company lookup screen. Click the desired company’s ID to enter their Profile View.

Company Lookup Screen

On the Profile View under Sample Rate, select the pencil icon to change the specific user’s sample rate.

Company Profile View

Disable the inherit toggle to allow adjustments of the company’s sample rate. Set the desired sample rate and select save.

Set Company Sample Rate

The newly set sample rate is displayed on the company’s Profile View.

Sample Rate Set in Company View

User behavior and demographic sampling

Behavior and demographic sampling rules leverage Saved Cohorts. A saved cohort is a dynamic list of users or companies that match some specific criteria. Saved cohorts can be used to build complex but easy to understand rules that can represent user behaviors or demographics.

On the Dynamic Sampling Rules page, select New User Rule

New User Rule

Once selected, a modal will appear. Under the Select Cohort heading, select an already existing user cohort or + Create New User Cohort.

Select User Cohort

Set your desired sample rate and priority and press save.

Set Rate and Priority

Priority are ordered within user or company cohorts. That means that a user or company cohort sample rule with a lower priority value are taken into account first. User sample rules always take precedence over company sample rules.

Your user sample rate will have been set and is reflected on the Dynamic Sampling Rules page.

Sample Rate Set for User Cohort

Company behavior and demographic sampling

On the Dynamic Sampling Rules page, select New Company Rule

New Company Rule

Once selected, a modal will appear. Under the Select Cohort heading, select an already existing company cohort or + Create New Company Cohort.

Select Company Cohort

Set your desired sample rate and priority and press save.

Set Rate and Priority

Priority are ordered within user or company cohorts. That means that a user or company cohort sample rule with a lower priority value are taken into account first. User sample rules always take precedence over company sample rules.

Your company sample rate will have been set and is reflected on the Dynamic Sampling Rules page.

Sample Rate Set for Company Cohort

Regex Sampling

Regex, or Regular Expressions, can be utilized to create amazingly complex search patterns that can be used against your data within Moesif.

On the Sampling Rules screen, click + Rule and select New Regex Rule.

Set New Regex Rule

Once selected, a modal will appear. Under the Regex Criteria heading, select a field. You have a choice of several options:

  • Request Route
  • Request Verb
  • Request IP
  • GraphQL Operation Name
  • Response Status

Options for Regex

After the desired field is selected, enter your regex criteria rule. You can also select + Regex Criteria to form an even more complex regex sampling rule. Set the rate in which you would like the rule to be sampled at and click save.

Regex Rule

On the sampling rules page we can see that the Regex Sampling Condition has been successfully set.

Regex Rule Set

Global Sample Rules

On the Sampling Rules screen, select Settings to access the global settings that apply across Moesif.

Global Settings Location

Set Global Sample Rate

The global sample rate is used by any user (or company) that doesn’t have its own sample rate nor belongs to any behavioral cohort.

To modify the global sample rate, click on pencil icon.

Global Setting Screen

Enter your desired sample rate and then select save.

Edit Global Sample Rate

The new global sample rate is reflected on the global rules sampling settings screen.

Global Rate Set

Suppress Bot Traffic

Known bot and crawler traffic can be suppressed by toggling the Suppress Bot Traffic button.

Sample Rate Set for User Cohort

Suppress IP Address

An IP address or range of IP addresses can be excluded from data collection. Under Suppress IP Address select Add IP Address.

Suppress IP Location

Enter a name for the address and an IP address and select save.

IP Settings

A range of IP addresses can also be suppressed by utilizing regex. Use this tool to easily create a regex rule that matches a range of IP’s. IP Range

The suppressed IP addresses that have been set are reflected in the UI.

IP Suppression Set

For more in-depth information on how dynamic sampling works, check out our documentation.

Updated: