@oneuptime/common 11.5.12 → 11.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/Models/DatabaseModels/AIInsight.ts +30 -0
  2. package/Models/DatabaseModels/EnterpriseLicense.ts +21 -0
  3. package/Models/DatabaseModels/EnterpriseLicenseInstance.ts +25 -0
  4. package/Models/DatabaseModels/GlobalConfig.ts +76 -0
  5. package/Models/DatabaseModels/Project.ts +30 -0
  6. package/Models/DatabaseModels/TelemetryException.ts +128 -0
  7. package/Server/API/AIAgentDataAPI.ts +129 -5
  8. package/Server/API/AIInvestigationAPI.ts +87 -0
  9. package/Server/API/EnterpriseLicenseAPI.ts +57 -0
  10. package/Server/API/GlobalConfigAPI.ts +62 -1
  11. package/Server/EnvironmentConfig.ts +22 -0
  12. package/Server/Infrastructure/Postgres/SchemaMigrations/1784640000000-AddExceptionTriageAndPrivacyColumns.ts +56 -0
  13. package/Server/Infrastructure/Postgres/SchemaMigrations/1784659816363-AddInstanceVersionAndLatestReleaseColumns.ts +38 -0
  14. package/Server/Infrastructure/Postgres/SchemaMigrations/1784705487674-AddEnterpriseLicenseEvaluationColumns.ts +25 -0
  15. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +6 -0
  16. package/Server/Services/AIRunService.ts +8 -0
  17. package/Server/Services/AnalyticsDatabaseService.ts +48 -45
  18. package/Server/Services/DatabaseService.ts +66 -1
  19. package/Server/Services/TelemetryExceptionService.ts +320 -24
  20. package/Server/Services/WorkflowService.ts +100 -39
  21. package/Server/Types/Workflow/Components/Schedule.ts +57 -32
  22. package/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.ts +15 -4
  23. package/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.ts +15 -4
  24. package/Server/Utils/AI/SRE/Insights/InsightScanner.ts +222 -24
  25. package/Server/Utils/AI/SRE/Insights/InsightTriageRunner.ts +225 -9
  26. package/Server/Utils/AI/SRE/SubjectCodeFixRun.ts +39 -0
  27. package/Server/Utils/AI/SRE/TelemetryImprovementTaskTrigger.ts +114 -0
  28. package/Server/Utils/AnalyticsDatabase/InsertDedupContext.ts +59 -0
  29. package/Server/Utils/Express.ts +13 -0
  30. package/Server/Utils/Telemetry/ExceptionSanitizer.ts +222 -0
  31. package/Server/Utils/Telemetry/TelemetryFanInWriter.ts +799 -0
  32. package/Server/Utils/Telemetry/TelemetryWriterClient.ts +263 -0
  33. package/Server/Utils/Telemetry/TelemetryWriterServer.ts +240 -0
  34. package/Server/Utils/Telemetry/TelemetryWriterShedMetrics.ts +93 -0
  35. package/Tests/Server/Services/DatabaseServiceSanitizeUpdateData.test.ts +232 -0
  36. package/Tests/Server/Services/TelemetryExceptionCodeFixRun.test.ts +205 -1
  37. package/Tests/Server/Services/UpdateOneByIdKeepsRowId.test.ts +107 -0
  38. package/Tests/Server/Services/WorkflowService.test.ts +308 -0
  39. package/Tests/Server/Utils/AI/Insights/InsightScanner.test.ts +150 -141
  40. package/Tests/Server/Utils/AI/Insights/InsightTriageRunner.test.ts +277 -1
  41. package/Tests/Server/Utils/Attribution.test.ts +203 -0
  42. package/Tests/Server/Utils/ExceptionSanitizer.test.ts +70 -0
  43. package/Tests/Server/Utils/InsightTriageClassification.test.ts +57 -0
  44. package/Tests/Server/Utils/Marketing/ConversionUploadProvider.test.ts +183 -0
  45. package/Tests/Server/Utils/Marketing/GoogleAds.test.ts +340 -0
  46. package/Tests/Server/Utils/Monitor/Criteria/ExceptionMonitorCriteria.test.ts +87 -0
  47. package/Tests/Server/Utils/Monitor/Criteria/LogMonitorCriteria.test.ts +165 -0
  48. package/Tests/Server/Utils/Monitor/Criteria/TraceMonitorCriteria.test.ts +86 -0
  49. package/Tests/Server/Utils/Telemetry/TelemetryFanInWriter.test.ts +1565 -0
  50. package/Tests/Server/Utils/Telemetry/TelemetryWriterClient.test.ts +313 -0
  51. package/Tests/Server/Utils/Telemetry/TelemetryWriterServer.test.ts +270 -0
  52. package/Tests/Server/Utils/Telemetry/TelemetryWriterShedMetrics.test.ts +127 -0
  53. package/Tests/Server/Utils/TelemetryImprovementTaskTrigger.test.ts +141 -0
  54. package/Tests/Types/AI/CodeFixTaskType.test.ts +3 -0
  55. package/Tests/Types/Monitor/MonitorCriteriaMetricVariables.test.ts +228 -0
  56. package/Tests/Types/Monitor/MonitorStepDefaultTelemetryConfig.test.ts +169 -0
  57. package/Tests/Types/Monitor/MonitorStepExceptionMonitor.test.ts +289 -0
  58. package/Tests/Types/Monitor/MonitorStepLogMonitor.test.ts +231 -0
  59. package/Tests/Types/Monitor/MonitorStepMetricViewConfigUtil.test.ts +245 -0
  60. package/Tests/Types/Monitor/MonitorStepNetworkDeviceMonitor.test.ts +155 -0
  61. package/Tests/Types/Monitor/MonitorStepTelemetrySerialization.test.ts +141 -0
  62. package/Tests/Types/Monitor/MonitorStepTraceMonitor.test.ts +137 -0
  63. package/Tests/Types/Workspace/NotificationRules/NotificationRuleCondition.test.ts +311 -0
  64. package/Tests/UI/Components/ModelTableSelectFromColumns.test.ts +259 -0
  65. package/Tests/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.test.ts +461 -0
  66. package/Tests/UI/Utils/Breadcrumb/fixtures/RealBreadcrumbTrails.ts +2852 -0
  67. package/Tests/UI/Utils/Breadcrumb/fixtures/RealRoutePatterns.ts +758 -0
  68. package/Tests/UI/Utils/NotificationMethodUtil.test.ts +564 -0
  69. package/Tests/Utils/Array.test.ts +156 -0
  70. package/Tests/Utils/CronTab.test.ts +199 -0
  71. package/Tests/Utils/ModelImportExport.test.ts +101 -0
  72. package/Tests/Utils/Number.test.ts +179 -0
  73. package/Tests/Utils/VersionUtil.test.ts +348 -0
  74. package/Tests/jest.setup.ts +1 -0
  75. package/Types/AI/CodeFixTaskContext.ts +6 -0
  76. package/Types/AI/CodeFixTaskType.ts +38 -1
  77. package/Types/AI/ExceptionAIClassification.ts +27 -0
  78. package/Types/EnterpriseLicense/EnterpriseLicenseInstanceSummary.ts +6 -0
  79. package/Types/Log/LogScrubPatternType.ts +7 -0
  80. package/Types/Monitor/MonitorStep.ts +24 -4
  81. package/Types/Monitor/MonitorStepMetricViewConfigUtil.ts +105 -0
  82. package/Types/Trace/TraceScrubPatternType.ts +7 -0
  83. package/UI/Components/EditionLabel/EditionLabel.tsx +445 -12
  84. package/UI/Components/ModelTable/BaseModelTable.tsx +15 -46
  85. package/UI/Components/ModelTable/SelectFromColumns.ts +129 -0
  86. package/UI/Components/Workflow/ArgumentsForm.tsx +68 -30
  87. package/UI/Components/Workflow/CronScheduleField.tsx +411 -0
  88. package/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.ts +176 -0
  89. package/UI/Utils/NotificationMethodUtil.ts +310 -0
  90. package/Utils/CronTab.ts +823 -0
  91. package/Utils/ModelImportExport.ts +21 -6
  92. package/Utils/VersionUtil.ts +260 -0
  93. package/build/dist/Models/DatabaseModels/AIInsight.js +31 -0
  94. package/build/dist/Models/DatabaseModels/AIInsight.js.map +1 -1
  95. package/build/dist/Models/DatabaseModels/EnterpriseLicense.js +22 -0
  96. package/build/dist/Models/DatabaseModels/EnterpriseLicense.js.map +1 -1
  97. package/build/dist/Models/DatabaseModels/EnterpriseLicenseInstance.js +26 -0
  98. package/build/dist/Models/DatabaseModels/EnterpriseLicenseInstance.js.map +1 -1
  99. package/build/dist/Models/DatabaseModels/GlobalConfig.js +81 -0
  100. package/build/dist/Models/DatabaseModels/GlobalConfig.js.map +1 -1
  101. package/build/dist/Models/DatabaseModels/Project.js +31 -0
  102. package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
  103. package/build/dist/Models/DatabaseModels/TelemetryException.js +134 -0
  104. package/build/dist/Models/DatabaseModels/TelemetryException.js.map +1 -1
  105. package/build/dist/Server/API/AIAgentDataAPI.js +97 -8
  106. package/build/dist/Server/API/AIAgentDataAPI.js.map +1 -1
  107. package/build/dist/Server/API/AIInvestigationAPI.js +55 -0
  108. package/build/dist/Server/API/AIInvestigationAPI.js.map +1 -1
  109. package/build/dist/Server/API/EnterpriseLicenseAPI.js +47 -0
  110. package/build/dist/Server/API/EnterpriseLicenseAPI.js.map +1 -1
  111. package/build/dist/Server/API/GlobalConfigAPI.js +52 -1
  112. package/build/dist/Server/API/GlobalConfigAPI.js.map +1 -1
  113. package/build/dist/Server/EnvironmentConfig.js +17 -0
  114. package/build/dist/Server/EnvironmentConfig.js.map +1 -1
  115. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784640000000-AddExceptionTriageAndPrivacyColumns.js +33 -0
  116. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784640000000-AddExceptionTriageAndPrivacyColumns.js.map +1 -0
  117. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784659816363-AddInstanceVersionAndLatestReleaseColumns.js +18 -0
  118. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784659816363-AddInstanceVersionAndLatestReleaseColumns.js.map +1 -0
  119. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784705487674-AddEnterpriseLicenseEvaluationColumns.js +14 -0
  120. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784705487674-AddEnterpriseLicenseEvaluationColumns.js.map +1 -0
  121. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +6 -0
  122. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  123. package/build/dist/Server/Services/AIRunService.js +9 -2
  124. package/build/dist/Server/Services/AIRunService.js.map +1 -1
  125. package/build/dist/Server/Services/AnalyticsDatabaseService.js +44 -16
  126. package/build/dist/Server/Services/AnalyticsDatabaseService.js.map +1 -1
  127. package/build/dist/Server/Services/DatabaseService.js +53 -1
  128. package/build/dist/Server/Services/DatabaseService.js.map +1 -1
  129. package/build/dist/Server/Services/TelemetryExceptionService.js +263 -22
  130. package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -1
  131. package/build/dist/Server/Services/WorkflowService.js +80 -30
  132. package/build/dist/Server/Services/WorkflowService.js.map +1 -1
  133. package/build/dist/Server/Types/Workflow/Components/Schedule.js +44 -19
  134. package/build/dist/Server/Types/Workflow/Components/Schedule.js.map +1 -1
  135. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js +12 -4
  136. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js.map +1 -1
  137. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js +12 -4
  138. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js.map +1 -1
  139. package/build/dist/Server/Utils/AI/SRE/Insights/InsightScanner.js +193 -22
  140. package/build/dist/Server/Utils/AI/SRE/Insights/InsightScanner.js.map +1 -1
  141. package/build/dist/Server/Utils/AI/SRE/Insights/InsightTriageRunner.js +178 -9
  142. package/build/dist/Server/Utils/AI/SRE/Insights/InsightTriageRunner.js.map +1 -1
  143. package/build/dist/Server/Utils/AI/SRE/SubjectCodeFixRun.js +37 -0
  144. package/build/dist/Server/Utils/AI/SRE/SubjectCodeFixRun.js.map +1 -1
  145. package/build/dist/Server/Utils/AI/SRE/TelemetryImprovementTaskTrigger.js +98 -0
  146. package/build/dist/Server/Utils/AI/SRE/TelemetryImprovementTaskTrigger.js.map +1 -0
  147. package/build/dist/Server/Utils/AnalyticsDatabase/InsertDedupContext.js +24 -0
  148. package/build/dist/Server/Utils/AnalyticsDatabase/InsertDedupContext.js.map +1 -0
  149. package/build/dist/Server/Utils/Express.js +12 -0
  150. package/build/dist/Server/Utils/Express.js.map +1 -1
  151. package/build/dist/Server/Utils/Telemetry/ExceptionSanitizer.js +149 -0
  152. package/build/dist/Server/Utils/Telemetry/ExceptionSanitizer.js.map +1 -0
  153. package/build/dist/Server/Utils/Telemetry/TelemetryFanInWriter.js +496 -0
  154. package/build/dist/Server/Utils/Telemetry/TelemetryFanInWriter.js.map +1 -0
  155. package/build/dist/Server/Utils/Telemetry/TelemetryWriterClient.js +165 -0
  156. package/build/dist/Server/Utils/Telemetry/TelemetryWriterClient.js.map +1 -0
  157. package/build/dist/Server/Utils/Telemetry/TelemetryWriterServer.js +136 -0
  158. package/build/dist/Server/Utils/Telemetry/TelemetryWriterServer.js.map +1 -0
  159. package/build/dist/Server/Utils/Telemetry/TelemetryWriterShedMetrics.js +76 -0
  160. package/build/dist/Server/Utils/Telemetry/TelemetryWriterShedMetrics.js.map +1 -0
  161. package/build/dist/Types/AI/CodeFixTaskType.js +38 -1
  162. package/build/dist/Types/AI/CodeFixTaskType.js.map +1 -1
  163. package/build/dist/Types/AI/ExceptionAIClassification.js +28 -0
  164. package/build/dist/Types/AI/ExceptionAIClassification.js.map +1 -0
  165. package/build/dist/Types/Log/LogScrubPatternType.js +7 -0
  166. package/build/dist/Types/Log/LogScrubPatternType.js.map +1 -1
  167. package/build/dist/Types/Monitor/MonitorStep.js +20 -4
  168. package/build/dist/Types/Monitor/MonitorStep.js.map +1 -1
  169. package/build/dist/Types/Monitor/MonitorStepMetricViewConfigUtil.js +73 -0
  170. package/build/dist/Types/Monitor/MonitorStepMetricViewConfigUtil.js.map +1 -0
  171. package/build/dist/Types/Trace/TraceScrubPatternType.js +7 -0
  172. package/build/dist/Types/Trace/TraceScrubPatternType.js.map +1 -1
  173. package/build/dist/UI/Components/EditionLabel/EditionLabel.js +261 -13
  174. package/build/dist/UI/Components/EditionLabel/EditionLabel.js.map +1 -1
  175. package/build/dist/UI/Components/ModelTable/BaseModelTable.js +12 -37
  176. package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
  177. package/build/dist/UI/Components/ModelTable/SelectFromColumns.js +82 -0
  178. package/build/dist/UI/Components/ModelTable/SelectFromColumns.js.map +1 -0
  179. package/build/dist/UI/Components/Workflow/ArgumentsForm.js +30 -6
  180. package/build/dist/UI/Components/Workflow/ArgumentsForm.js.map +1 -1
  181. package/build/dist/UI/Components/Workflow/CronScheduleField.js +209 -0
  182. package/build/dist/UI/Components/Workflow/CronScheduleField.js.map +1 -0
  183. package/build/dist/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.js +129 -0
  184. package/build/dist/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.js.map +1 -0
  185. package/build/dist/UI/Utils/NotificationMethodUtil.js +189 -0
  186. package/build/dist/UI/Utils/NotificationMethodUtil.js.map +1 -0
  187. package/build/dist/Utils/CronTab.js +609 -0
  188. package/build/dist/Utils/CronTab.js.map +1 -0
  189. package/build/dist/Utils/ModelImportExport.js +20 -6
  190. package/build/dist/Utils/ModelImportExport.js.map +1 -1
  191. package/build/dist/Utils/VersionUtil.js +193 -0
  192. package/build/dist/Utils/VersionUtil.js.map +1 -0
  193. package/package.json +1 -1
@@ -0,0 +1,165 @@
1
+ import LogMonitorCriteria from "../../../../../Server/Utils/Monitor/Criteria/LogMonitorCriteria";
2
+ import {
3
+ CheckOn,
4
+ CriteriaFilter,
5
+ FilterType,
6
+ } from "../../../../../Types/Monitor/CriteriaFilter";
7
+ import LogMonitorResponse from "../../../../../Types/Monitor/LogMonitor/LogMonitorResponse";
8
+ import DataToProcess from "../../../../../Server/Utils/Monitor/DataToProcess";
9
+ import ObjectID from "../../../../../Types/ObjectID";
10
+
11
+ /*
12
+ * LogMonitorCriteria is what turns the logCount the (now-fixed) worker
13
+ * produces into an online/offline verdict. It only understands
14
+ * CheckOn.LogCount — the sole check the Logs criteria UI offers — and defers
15
+ * the numeric comparison to CompareCriteria.
16
+ */
17
+ function buildResponse(logCount: number | undefined): DataToProcess {
18
+ const response: Partial<LogMonitorResponse> = {
19
+ projectId: ObjectID.generate(),
20
+ monitorId: ObjectID.generate(),
21
+ logCount: logCount as number,
22
+ logQuery: {},
23
+ };
24
+ return response as DataToProcess;
25
+ }
26
+
27
+ function evaluate(
28
+ logCount: number | undefined,
29
+ criteriaFilter: CriteriaFilter,
30
+ ): Promise<string | null> {
31
+ return LogMonitorCriteria.isMonitorInstanceCriteriaFilterMet({
32
+ dataToProcess: buildResponse(logCount),
33
+ criteriaFilter,
34
+ });
35
+ }
36
+
37
+ describe("LogMonitorCriteria.isMonitorInstanceCriteriaFilterMet", () => {
38
+ describe("LogCount GreaterThan", () => {
39
+ test("count above threshold → met", async () => {
40
+ const result: string | null = await evaluate(5, {
41
+ checkOn: CheckOn.LogCount,
42
+ filterType: FilterType.GreaterThan,
43
+ value: 0,
44
+ });
45
+ expect(result).toBeTruthy();
46
+ expect(result).toContain("Log Count");
47
+ });
48
+
49
+ test("count equal to threshold → not met", async () => {
50
+ expect(
51
+ await evaluate(3, {
52
+ checkOn: CheckOn.LogCount,
53
+ filterType: FilterType.GreaterThan,
54
+ value: 3,
55
+ }),
56
+ ).toBeNull();
57
+ });
58
+
59
+ test("count below threshold → not met", async () => {
60
+ expect(
61
+ await evaluate(0, {
62
+ checkOn: CheckOn.LogCount,
63
+ filterType: FilterType.GreaterThan,
64
+ value: 0,
65
+ }),
66
+ ).toBeNull();
67
+ });
68
+ });
69
+
70
+ describe("LogCount EqualTo (the default offline criteria)", () => {
71
+ test("zero logs equal to 0 → met (monitor goes offline)", async () => {
72
+ const result: string | null = await evaluate(0, {
73
+ checkOn: CheckOn.LogCount,
74
+ filterType: FilterType.EqualTo,
75
+ value: 0,
76
+ });
77
+ expect(result).toBeTruthy();
78
+ });
79
+
80
+ test("some logs not equal to 0 → not met", async () => {
81
+ expect(
82
+ await evaluate(7, {
83
+ checkOn: CheckOn.LogCount,
84
+ filterType: FilterType.EqualTo,
85
+ value: 0,
86
+ }),
87
+ ).toBeNull();
88
+ });
89
+ });
90
+
91
+ describe("other numeric comparators", () => {
92
+ test("LessThan → met when below", async () => {
93
+ expect(
94
+ await evaluate(2, {
95
+ checkOn: CheckOn.LogCount,
96
+ filterType: FilterType.LessThan,
97
+ value: 5,
98
+ }),
99
+ ).toBeTruthy();
100
+ });
101
+
102
+ test("GreaterThanOrEqualTo → met at the boundary", async () => {
103
+ expect(
104
+ await evaluate(5, {
105
+ checkOn: CheckOn.LogCount,
106
+ filterType: FilterType.GreaterThanOrEqualTo,
107
+ value: 5,
108
+ }),
109
+ ).toBeTruthy();
110
+ });
111
+
112
+ test("LessThanOrEqualTo → met at the boundary", async () => {
113
+ expect(
114
+ await evaluate(5, {
115
+ checkOn: CheckOn.LogCount,
116
+ filterType: FilterType.LessThanOrEqualTo,
117
+ value: 5,
118
+ }),
119
+ ).toBeTruthy();
120
+ });
121
+
122
+ test("NotEqualTo → met when different", async () => {
123
+ expect(
124
+ await evaluate(4, {
125
+ checkOn: CheckOn.LogCount,
126
+ filterType: FilterType.NotEqualTo,
127
+ value: 0,
128
+ }),
129
+ ).toBeTruthy();
130
+ });
131
+ });
132
+
133
+ describe("edge cases", () => {
134
+ test("a missing logCount is treated as 0", async () => {
135
+ // undefined logCount → 0; "equal to 0" is therefore met.
136
+ expect(
137
+ await evaluate(undefined, {
138
+ checkOn: CheckOn.LogCount,
139
+ filterType: FilterType.EqualTo,
140
+ value: 0,
141
+ }),
142
+ ).toBeTruthy();
143
+ });
144
+
145
+ test("a string threshold is coerced to a number", async () => {
146
+ expect(
147
+ await evaluate(10, {
148
+ checkOn: CheckOn.LogCount,
149
+ filterType: FilterType.GreaterThan,
150
+ value: "5",
151
+ }),
152
+ ).toBeTruthy();
153
+ });
154
+
155
+ test("a non-LogCount checkOn returns null (unhandled)", async () => {
156
+ expect(
157
+ await evaluate(100, {
158
+ checkOn: CheckOn.SpanCount,
159
+ filterType: FilterType.GreaterThan,
160
+ value: 0,
161
+ }),
162
+ ).toBeNull();
163
+ });
164
+ });
165
+ });
@@ -0,0 +1,86 @@
1
+ import TraceMonitorCriteria from "../../../../../Server/Utils/Monitor/Criteria/TraceMonitorCriteria";
2
+ import {
3
+ CheckOn,
4
+ CriteriaFilter,
5
+ FilterType,
6
+ } from "../../../../../Types/Monitor/CriteriaFilter";
7
+ import TraceMonitorResponse from "../../../../../Types/Monitor/TraceMonitor/TraceMonitorResponse";
8
+ import DataToProcess from "../../../../../Server/Utils/Monitor/DataToProcess";
9
+ import ObjectID from "../../../../../Types/ObjectID";
10
+
11
+ /*
12
+ * TraceMonitorCriteria is the SpanCount analogue of LogMonitorCriteria and
13
+ * shares the same fallback-fixed worker path (monitorTrace). Covered here for
14
+ * parity so the two count-based telemetry criteria stay in lock-step.
15
+ */
16
+ function buildResponse(spanCount: number | undefined): DataToProcess {
17
+ const response: Partial<TraceMonitorResponse> = {
18
+ projectId: ObjectID.generate(),
19
+ monitorId: ObjectID.generate(),
20
+ spanCount: spanCount as number,
21
+ spanQuery: {},
22
+ };
23
+ return response as DataToProcess;
24
+ }
25
+
26
+ function evaluate(
27
+ spanCount: number | undefined,
28
+ criteriaFilter: CriteriaFilter,
29
+ ): Promise<string | null> {
30
+ return TraceMonitorCriteria.isMonitorInstanceCriteriaFilterMet({
31
+ dataToProcess: buildResponse(spanCount),
32
+ criteriaFilter,
33
+ });
34
+ }
35
+
36
+ describe("TraceMonitorCriteria.isMonitorInstanceCriteriaFilterMet", () => {
37
+ test("SpanCount GreaterThan → met when above threshold", async () => {
38
+ expect(
39
+ await evaluate(9, {
40
+ checkOn: CheckOn.SpanCount,
41
+ filterType: FilterType.GreaterThan,
42
+ value: 0,
43
+ }),
44
+ ).toBeTruthy();
45
+ });
46
+
47
+ test("SpanCount EqualTo 0 → met when no spans (offline)", async () => {
48
+ expect(
49
+ await evaluate(0, {
50
+ checkOn: CheckOn.SpanCount,
51
+ filterType: FilterType.EqualTo,
52
+ value: 0,
53
+ }),
54
+ ).toBeTruthy();
55
+ });
56
+
57
+ test("SpanCount GreaterThan → not met at/below threshold", async () => {
58
+ expect(
59
+ await evaluate(0, {
60
+ checkOn: CheckOn.SpanCount,
61
+ filterType: FilterType.GreaterThan,
62
+ value: 0,
63
+ }),
64
+ ).toBeNull();
65
+ });
66
+
67
+ test("a missing spanCount is treated as 0", async () => {
68
+ expect(
69
+ await evaluate(undefined, {
70
+ checkOn: CheckOn.SpanCount,
71
+ filterType: FilterType.EqualTo,
72
+ value: 0,
73
+ }),
74
+ ).toBeTruthy();
75
+ });
76
+
77
+ test("a non-SpanCount checkOn returns null (unhandled)", async () => {
78
+ expect(
79
+ await evaluate(50, {
80
+ checkOn: CheckOn.LogCount,
81
+ filterType: FilterType.GreaterThan,
82
+ value: 0,
83
+ }),
84
+ ).toBeNull();
85
+ });
86
+ });