metrics.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import type {DateString} from './core';
  2. export type MetricAggregation =
  3. | 'sum'
  4. | 'count_unique'
  5. | 'avg'
  6. | 'count'
  7. | 'min'
  8. | 'max'
  9. | 'min'
  10. | 'p50'
  11. | 'p75'
  12. | 'p90'
  13. | 'p95'
  14. | 'p99';
  15. export type MetricType =
  16. | 'c'
  17. | 'd'
  18. | 'g'
  19. | 'e'
  20. | 's'
  21. // Virtual metrics combine multiple metrics into one, to hide the internal complexity
  22. // of span based metrics.
  23. // Created and used only in the frontend
  24. | 'v';
  25. export type UseCase = 'custom' | 'transactions' | 'sessions' | 'spans' | 'metric_stats';
  26. export type MRI = `${MetricType}:${UseCase}${string}@${string}`;
  27. export type ParsedMRI = {
  28. name: string;
  29. type: MetricType;
  30. unit: string;
  31. useCase: UseCase;
  32. };
  33. export type MetricsApiRequestMetric = {
  34. field: string;
  35. groupBy?: string[];
  36. orderBy?: string;
  37. query?: string;
  38. };
  39. export interface MetricsApiRequestQuery extends MetricsApiRequestMetric {
  40. interval: string;
  41. end?: DateString;
  42. environment?: string[];
  43. includeSeries?: number;
  44. includeTotals?: number;
  45. limit?: number;
  46. project?: number[];
  47. start?: DateString;
  48. statsPeriod?: string;
  49. }
  50. export type MetricsDataIntervalLadder = 'metrics' | 'bar' | 'dashboard';
  51. export type MetricsApiResponse = {
  52. end: string;
  53. groups: MetricsGroup[];
  54. intervals: string[];
  55. meta: MetricMeta[];
  56. query: string;
  57. start: string;
  58. };
  59. export interface MetricsQueryApiResponse {
  60. data: Array<
  61. Array<{
  62. by: Record<string, string>;
  63. series: Array<number | null>;
  64. totals: number;
  65. }>
  66. >;
  67. end: string;
  68. intervals: string[];
  69. meta: Array<
  70. [
  71. ...Array<{name: string; type: string}>,
  72. // The last entry in meta has a different shape
  73. MetricsQueryApiResponseLastMeta,
  74. ]
  75. >;
  76. start: string;
  77. }
  78. export interface MetricsQueryApiResponseLastMeta {
  79. group_bys: string[];
  80. limit: number | null;
  81. order: string | null;
  82. has_more?: boolean;
  83. scaling_factor?: number | null;
  84. unit?: string | null;
  85. unit_family?: 'duration' | 'information' | null;
  86. }
  87. export type MetricsGroup = {
  88. by: Record<string, string>;
  89. series: Record<string, Array<number | null>>;
  90. totals: Record<string, number | null>;
  91. };
  92. export type MetricsTagCollection = Record<string, MetricsTag>;
  93. export type MetricsTag = {
  94. key: string;
  95. };
  96. export type MetricsTagValue = {
  97. key: string;
  98. value: string;
  99. };
  100. export type MetricMeta = {
  101. blockingStatus: BlockingStatus[];
  102. mri: MRI;
  103. // name: string; // returned by the API but should not be used, use parseMRI(mri).name instead
  104. operations: MetricAggregation[];
  105. projectIds: number[];
  106. type: MetricType;
  107. unit: string;
  108. };
  109. export type BlockingStatus = {
  110. blockedTags: string[];
  111. isBlocked: boolean;
  112. projectId: number;
  113. };
  114. export type MetricsMetaCollection = Record<string, MetricMeta>;
  115. export interface MetricsExtractionCondition {
  116. id: number;
  117. mris: MRI[];
  118. value: string;
  119. }
  120. export interface MetricsExtractionRule {
  121. aggregates: MetricAggregation[];
  122. conditions: MetricsExtractionCondition[];
  123. createdById: number | null;
  124. dateAdded: string;
  125. dateUpdated: string;
  126. projectId: number;
  127. spanAttribute: string;
  128. tags: string[];
  129. unit: string;
  130. }