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:

  • Sample API calls for each user which can also be set based on their behavior and profile
  • Sample API calls for each company which can also be set based on their behavior and profile
  • Sample API calls based on regex rules on API fields like specific URIs
  • Sample API calls globally

Calculation of sampling rules

First Moesif calculates the user and the company sample rate. If both are defined, the user sampling rules always takes precedence over company sample rules. If you create multiple behavioral sampling rules of the same type, you can set a priority level. Lower values mean the rule is higher priority.

Once the user or company sample rate is determined, Moesif will also calculate whether the specific API reguest is sampled by any regex rules. If a given request has both user/company sampling and also regex based sampling, then Moesif takes the minimum between the two.

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.

To learn how to utilize Saved Cohorts, check out our Creating Saved Cohorts Tutorial

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

Using 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

Using Global Sample Rules

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

Global Settings Location

Setting 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

Suppressing Bot Traffic

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

Sample Rate Set for User Cohort

Suppressing IP Addresses

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.

From Moesif

Other

Updated: