metrics.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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: {
  61. by: Record<string, string>;
  62. series: Array<number | null>;
  63. totals: number;
  64. }[][];
  65. end: string;
  66. intervals: string[];
  67. meta: [
  68. ...{name: string; type: string}[],
  69. // The last entry in meta has a different shape
  70. MetricsQueryApiResponseLastMeta,
  71. ][];
  72. start: string;
  73. }
  74. export interface MetricsQueryApiResponseLastMeta {
  75. group_bys: string[];
  76. limit: number | null;
  77. order: string | null;
  78. has_more?: boolean;
  79. scaling_factor?: number | null;
  80. unit?: string | null;
  81. unit_family?: 'duration' | 'information' | null;
  82. }
  83. export type MetricsGroup = {
  84. by: Record<string, string>;
  85. series: Record<string, Array<number | null>>;
  86. totals: Record<string, number | null>;
  87. };
  88. export type MetricsTagCollection = Record<string, MetricsTag>;
  89. export type MetricsTag = {
  90. key: string;
  91. };
  92. export type MetricsTagValue = {
  93. key: string;
  94. value: string;
  95. };
  96. export type MetricMeta = {
  97. blockingStatus: BlockingStatus[];
  98. mri: MRI;
  99. // name: string; // returned by the API but should not be used, use parseMRI(mri).name instead
  100. operations: MetricAggregation[];
  101. projectIds: number[];
  102. type: MetricType;
  103. unit: string;
  104. };
  105. export type BlockingStatus = {
  106. blockedTags: string[];
  107. isBlocked: boolean;
  108. projectId: number;
  109. };
  110. export type MetricsMetaCollection = Record<string, MetricMeta>;
  111. export interface MetricsExtractionCondition {
  112. id: number;
  113. mris: MRI[];
  114. value: string;
  115. }
  116. export interface MetricsExtractionRule {
  117. aggregates: MetricAggregation[];
  118. conditions: MetricsExtractionCondition[];
  119. createdById: number | null;
  120. dateAdded: string;
  121. dateUpdated: string;
  122. projectId: number;
  123. spanAttribute: string;
  124. tags: string[];
  125. unit: string;
  126. }