sampling.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import {Project} from './project';
  2. export enum SamplingRuleType {
  3. /**
  4. * The rule applies to traces (transaction events considered in the context of a trace)
  5. */
  6. TRACE = 'trace',
  7. /**
  8. * The rule applies to transaction events considered independently
  9. */
  10. TRANSACTION = 'transaction',
  11. }
  12. export enum SamplingConditionOperator {
  13. /**
  14. * Combine multiple sub-conditions with the operator 'and'
  15. */
  16. AND = 'and',
  17. }
  18. export enum SamplingRuleOperator {
  19. /**
  20. * The first rule on the list
  21. */
  22. IF = 'if',
  23. /**
  24. * All other rules, except rules without a condition
  25. */
  26. ELSE_IF = 'else_if',
  27. /**
  28. * Rules without a condition. In this case the rule cannot be reordered and is “pinned” at the bottom of the list
  29. */
  30. ELSE = 'else',
  31. }
  32. export enum SamplingInnerOperator {
  33. /**
  34. * It uses glob matches for checking (e.g. releases use glob matching "1.1.*" will match release 1.1.1 and 1.1.2)
  35. */
  36. GLOB_MATCH = 'glob',
  37. /**
  38. * It uses simple equality for checking
  39. */
  40. EQUAL = 'eq',
  41. /**
  42. * Custom Operation
  43. */
  44. CUSTOM = 'custom',
  45. }
  46. /**
  47. * String of the sampling category that's used on the backend.
  48. * Default naming strategy should be based on the path in the event, prefixed with `event.`.
  49. * To see the path in the event, click on the JSON button on the issue details page.
  50. */
  51. export enum SamplingInnerName {
  52. TRACE_RELEASE = 'trace.release',
  53. TRACE_ENVIRONMENT = 'trace.environment',
  54. TRACE_USER_ID = 'trace.user.id',
  55. TRACE_USER_SEGMENT = 'trace.user.segment',
  56. TRACE_TRANSACTION = 'trace.transaction',
  57. EVENT_RELEASE = 'event.release',
  58. EVENT_ENVIRONMENT = 'event.environment',
  59. EVENT_USER_ID = 'event.user.id',
  60. EVENT_USER_SEGMENT = 'event.user.segment',
  61. EVENT_LOCALHOST = 'event.is_local_ip',
  62. EVENT_WEB_CRAWLERS = 'event.web_crawlers',
  63. EVENT_TRANSACTION = 'event.transaction',
  64. EVENT_OS_NAME = 'event.contexts.os.name',
  65. EVENT_OS_VERSION = 'event.contexts.os.version',
  66. EVENT_DEVICE_NAME = 'event.contexts.device.name',
  67. EVENT_DEVICE_FAMILY = 'event.contexts.device.family',
  68. // Custom operators
  69. EVENT_IP_ADDRESSES = 'event.client_ip',
  70. EVENT_LEGACY_BROWSER = 'event.legacy_browser',
  71. EVENT_CSP = 'event.csp',
  72. EVENT_CUSTOM_TAG = 'event.custom_tag', // used for the fresh new custom tag condition (gets replaced once you choose tag key)
  73. }
  74. export enum LegacyBrowser {
  75. IE_PRE_9 = 'ie_pre_9',
  76. IE9 = 'ie9',
  77. IE10 = 'ie10',
  78. IE11 = 'ie11',
  79. SAFARI_PRE_6 = 'safari_pre_6',
  80. OPERA_PRE_15 = 'opera_pre_15',
  81. OPERA_MINI_PRE_8 = 'opera_mini_pre_8',
  82. ANDROID_PRE_4 = 'android_pre_4',
  83. }
  84. type SamplingConditionLogicalInnerGlob = {
  85. name:
  86. | SamplingInnerName.EVENT_RELEASE
  87. | SamplingInnerName.TRACE_RELEASE
  88. | SamplingInnerName.EVENT_TRANSACTION
  89. | SamplingInnerName.TRACE_TRANSACTION
  90. | SamplingInnerName.EVENT_OS_NAME
  91. | SamplingInnerName.EVENT_OS_VERSION
  92. | SamplingInnerName.EVENT_DEVICE_FAMILY
  93. | SamplingInnerName.EVENT_DEVICE_NAME
  94. | SamplingInnerName.EVENT_CUSTOM_TAG
  95. | string; // for custom tags
  96. op: SamplingInnerOperator.GLOB_MATCH;
  97. value: Array<string>;
  98. };
  99. type SamplingConditionLogicalInnerEq = {
  100. name:
  101. | SamplingInnerName.EVENT_ENVIRONMENT
  102. | SamplingInnerName.TRACE_ENVIRONMENT
  103. | SamplingInnerName.EVENT_USER_ID
  104. | SamplingInnerName.TRACE_USER_ID
  105. | SamplingInnerName.EVENT_USER_SEGMENT
  106. | SamplingInnerName.TRACE_USER_SEGMENT;
  107. op: SamplingInnerOperator.EQUAL;
  108. options: {
  109. ignoreCase: boolean;
  110. };
  111. value: Array<string>;
  112. };
  113. type SamplingConditionLogicalInnerEqBoolean = {
  114. name: SamplingInnerName.EVENT_LOCALHOST | SamplingInnerName.EVENT_WEB_CRAWLERS;
  115. op: SamplingInnerOperator.EQUAL;
  116. value: boolean;
  117. };
  118. type SamplingConditionLogicalInnerCustom = {
  119. name: SamplingInnerName.EVENT_CSP | SamplingInnerName.EVENT_IP_ADDRESSES;
  120. op: SamplingInnerOperator.CUSTOM;
  121. value: Array<string>;
  122. };
  123. type SamplingConditionLogicalInnerCustomLegacyBrowser = {
  124. name: SamplingInnerName.EVENT_LEGACY_BROWSER;
  125. op: SamplingInnerOperator.CUSTOM;
  126. value: Array<LegacyBrowser>;
  127. };
  128. export type SamplingConditionLogicalInner =
  129. | SamplingConditionLogicalInnerGlob
  130. | SamplingConditionLogicalInnerEq
  131. | SamplingConditionLogicalInnerEqBoolean
  132. | SamplingConditionLogicalInnerCustom
  133. | SamplingConditionLogicalInnerCustomLegacyBrowser;
  134. export type SamplingCondition = {
  135. inner: Array<SamplingConditionLogicalInner>;
  136. op: SamplingConditionOperator.AND;
  137. };
  138. export type SamplingRule = {
  139. /**
  140. * It is a possibly empty list of conditions to which the rule applies.
  141. * The conditions are combined using the and operator (so all the conditions must be satisfied for the rule to apply).
  142. * If the conditions field is an empty list the rule applies for all events that satisfy the projectIds and the ty fields.
  143. */
  144. condition: SamplingCondition;
  145. /**
  146. * This is a unique number within a project
  147. */
  148. id: number;
  149. /**
  150. * It is the sampling rate that will be applied if the rule is selected
  151. */
  152. sampleRate: number;
  153. /**
  154. * Describes the type of rule
  155. */
  156. type: SamplingRuleType;
  157. /**
  158. * Indicates if the rule is enabled for server-side sampling
  159. */
  160. active?: boolean;
  161. };
  162. export type SamplingDistribution = {
  163. null_sample_rate_percentage: null | number;
  164. project_breakdown:
  165. | null
  166. | {
  167. 'count()': number;
  168. project: string;
  169. project_id: number;
  170. }[];
  171. sample_rate_distributions: null | {
  172. avg: null | number;
  173. max: null | number;
  174. min: null | number;
  175. p50: null | number;
  176. p90: null | number;
  177. p95: null | number;
  178. p99: null | number;
  179. };
  180. sample_size: number;
  181. };
  182. export type SamplingSdkVersion = {
  183. isSendingSampleRate: boolean;
  184. latestSDKName: string;
  185. latestSDKVersion: string;
  186. project: string;
  187. };
  188. export type RecommendedSdkUpgrade = {
  189. latestSDKName: SamplingSdkVersion['latestSDKName'];
  190. latestSDKVersion: SamplingSdkVersion['latestSDKVersion'];
  191. project: Project;
  192. };
  193. export type UniformModalsSubmit = (props: {
  194. sampleRate: number;
  195. uniformRateModalOrigin: boolean;
  196. onError?: () => void;
  197. onSuccess?: (newRules: SamplingRule[]) => void;
  198. recommendedSampleRate?: boolean;
  199. rule?: SamplingRule;
  200. }) => void;