promotedai / ios-metrics-sdk

iOS client library for Promoted.ai metrics tracking.
MIT License
7 stars 1 forks source link

Diagnostics sampling #166

Closed yunapotamus closed 2 years ago

yunapotamus commented 2 years ago

Implement diagnostics sampling. This causes a percentage of randomly sampled clients to send all diagnostics. This random sampling is done entirely on the client and does not require Remote Config.

Sampling is controlled via a ClientConfig property called diagnosticsSamplingPercentage. A value of 0 disables diagnostic sampling for all clients. For example, setting this value to 5 will cause a random 5% across all users to be cohorted into sending diagnostics.

End date

If you enable diagnostics sampling, you must also provide an explicit end date via diagnosticsSamplingEndDateString. When this date elapses, sampling is disabled across all users. Always use an absolute date for this value.

This feature is designed for short-term diagnostics usage only. Do not leave it running in production without an end date in mind.

Remote Config interoperability

Designed for use on platforms where Remote Config is not available. If Remote Config is enabled, this sampling configuration is ignored. Random sampling is designed to replicate rudimentary experiment cohorting entirely client-side.

Likewise, setting diagnostic sampling flags (either this flag or diagnosticsSamplingEndDateString) via Remote Config does nothing.

Cohorting

Attempts to create a consistent cohort for the set of users with sampling enabled. To this end, sampling is done using the following:

  1. A hash of the persisted logUserID. This should persist while the same account is logged in. This also applies to signed-out users until they log in.
  2. If 1 is not available, uses UIDevice.current.identifierForVendor. This should persist for (at least) the duration of app install.
  3. If 2 is not available, generates a new random UUID for the session. This persists only for the current session.

See ClientConfigService for sampling implementation.

Diagnostic features

If sampling is enabled, the current logging session proceeds as though the following flags are enabled:

If you set any of those flags individually to true and then enable diagnostics sampling, the flags you set will always be enabled, and the other diagnostics flags will be enabled according to random sampling.

prm-dan commented 2 years ago

This description sounds sweet.