|
| 1 | +import { afterAll, expect, test } from 'vitest'; |
| 2 | +import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; |
| 3 | + |
| 4 | +afterAll(() => { |
| 5 | + cleanupChildProcesses(); |
| 6 | +}); |
| 7 | + |
| 8 | +test('should log messages with different levels and formats', async () => { |
| 9 | + await createRunner(__dirname, 'scenario.ts') |
| 10 | + .expect({ |
| 11 | + otel_log: { |
| 12 | + severityText: 'trace', |
| 13 | + severityNumber: 1, // TRACE |
| 14 | + body: { |
| 15 | + stringValue: 'test trace', |
| 16 | + }, |
| 17 | + attributes: [ |
| 18 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 19 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 20 | + ], |
| 21 | + }, |
| 22 | + }) |
| 23 | + .expect({ |
| 24 | + otel_log: { |
| 25 | + severityText: 'debug', |
| 26 | + severityNumber: 5, // DEBUG |
| 27 | + body: { |
| 28 | + stringValue: 'test debug', |
| 29 | + }, |
| 30 | + attributes: [ |
| 31 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 32 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 33 | + ], |
| 34 | + }, |
| 35 | + }) |
| 36 | + .expect({ |
| 37 | + otel_log: { |
| 38 | + severityText: 'info', |
| 39 | + severityNumber: 9, // INFO |
| 40 | + body: { |
| 41 | + stringValue: 'test info', |
| 42 | + }, |
| 43 | + attributes: [ |
| 44 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 45 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 46 | + ], |
| 47 | + }, |
| 48 | + }) |
| 49 | + .expect({ |
| 50 | + otel_log: { |
| 51 | + severityText: 'warn', |
| 52 | + severityNumber: 13, // WARN |
| 53 | + body: { |
| 54 | + stringValue: 'test warn', |
| 55 | + }, |
| 56 | + attributes: [ |
| 57 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 58 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 59 | + ], |
| 60 | + }, |
| 61 | + }) |
| 62 | + .expect({ |
| 63 | + otel_log: { |
| 64 | + severityText: 'error', |
| 65 | + severityNumber: 17, // ERROR |
| 66 | + body: { |
| 67 | + stringValue: 'test error', |
| 68 | + }, |
| 69 | + attributes: [ |
| 70 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 71 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 72 | + ], |
| 73 | + }, |
| 74 | + }) |
| 75 | + .expect({ |
| 76 | + otel_log: { |
| 77 | + severityText: 'fatal', |
| 78 | + severityNumber: 21, // FATAL |
| 79 | + body: { |
| 80 | + stringValue: 'test fatal', |
| 81 | + }, |
| 82 | + attributes: [ |
| 83 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 84 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 85 | + ], |
| 86 | + }, |
| 87 | + }) |
| 88 | + .expect({ |
| 89 | + otel_log: { |
| 90 | + severityText: 'trace', |
| 91 | + severityNumber: 1, // TRACE |
| 92 | + body: { |
| 93 | + stringValue: 'test trace stringArg false 123', |
| 94 | + }, |
| 95 | + attributes: [ |
| 96 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 97 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 98 | + { key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } }, |
| 99 | + { key: 'sentry.message.param.0', value: { stringValue: 'trace' } }, |
| 100 | + { key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } }, |
| 101 | + { key: 'sentry.message.param.2', value: { boolValue: false } }, |
| 102 | + { key: 'sentry.message.param.3', value: { doubleValue: 123 } }, |
| 103 | + ], |
| 104 | + }, |
| 105 | + }) |
| 106 | + .expect({ |
| 107 | + otel_log: { |
| 108 | + severityText: 'debug', |
| 109 | + severityNumber: 5, // DEBUG |
| 110 | + body: { |
| 111 | + stringValue: 'test debug stringArg false 123', |
| 112 | + }, |
| 113 | + attributes: [ |
| 114 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 115 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 116 | + { key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } }, |
| 117 | + { key: 'sentry.message.param.0', value: { stringValue: 'debug' } }, |
| 118 | + { key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } }, |
| 119 | + { key: 'sentry.message.param.2', value: { boolValue: false } }, |
| 120 | + { key: 'sentry.message.param.3', value: { doubleValue: 123 } }, |
| 121 | + ], |
| 122 | + }, |
| 123 | + }) |
| 124 | + .expect({ |
| 125 | + otel_log: { |
| 126 | + severityText: 'info', |
| 127 | + severityNumber: 9, // INFO |
| 128 | + body: { |
| 129 | + stringValue: 'test info stringArg false 123', |
| 130 | + }, |
| 131 | + attributes: [ |
| 132 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 133 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 134 | + { key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } }, |
| 135 | + { key: 'sentry.message.param.0', value: { stringValue: 'info' } }, |
| 136 | + { key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } }, |
| 137 | + { key: 'sentry.message.param.2', value: { boolValue: false } }, |
| 138 | + { key: 'sentry.message.param.3', value: { doubleValue: 123 } }, |
| 139 | + ], |
| 140 | + }, |
| 141 | + }) |
| 142 | + .expect({ |
| 143 | + otel_log: { |
| 144 | + severityText: 'warn', |
| 145 | + severityNumber: 13, // WARN |
| 146 | + body: { |
| 147 | + stringValue: 'test warn stringArg false 123', |
| 148 | + }, |
| 149 | + attributes: [ |
| 150 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 151 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 152 | + { key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } }, |
| 153 | + { key: 'sentry.message.param.0', value: { stringValue: 'warn' } }, |
| 154 | + { key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } }, |
| 155 | + { key: 'sentry.message.param.2', value: { boolValue: false } }, |
| 156 | + { key: 'sentry.message.param.3', value: { doubleValue: 123 } }, |
| 157 | + ], |
| 158 | + }, |
| 159 | + }) |
| 160 | + .expect({ |
| 161 | + otel_log: { |
| 162 | + severityText: 'error', |
| 163 | + severityNumber: 17, // ERROR |
| 164 | + body: { |
| 165 | + stringValue: 'test error stringArg false 123', |
| 166 | + }, |
| 167 | + attributes: [ |
| 168 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 169 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 170 | + { key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } }, |
| 171 | + { key: 'sentry.message.param.0', value: { stringValue: 'error' } }, |
| 172 | + { key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } }, |
| 173 | + { key: 'sentry.message.param.2', value: { boolValue: false } }, |
| 174 | + { key: 'sentry.message.param.3', value: { doubleValue: 123 } }, |
| 175 | + ], |
| 176 | + }, |
| 177 | + }) |
| 178 | + .expect({ |
| 179 | + otel_log: { |
| 180 | + severityText: 'fatal', |
| 181 | + severityNumber: 21, // FATAL |
| 182 | + body: { |
| 183 | + stringValue: 'test fatal stringArg false 123', |
| 184 | + }, |
| 185 | + attributes: [ |
| 186 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 187 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 188 | + { key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } }, |
| 189 | + { key: 'sentry.message.param.0', value: { stringValue: 'fatal' } }, |
| 190 | + { key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } }, |
| 191 | + { key: 'sentry.message.param.2', value: { boolValue: false } }, |
| 192 | + { key: 'sentry.message.param.3', value: { doubleValue: 123 } }, |
| 193 | + ], |
| 194 | + }, |
| 195 | + }) |
| 196 | + .expect({ |
| 197 | + otel_log: { |
| 198 | + severityText: 'trace', |
| 199 | + severityNumber: 1, // TRACE |
| 200 | + body: { |
| 201 | + stringValue: 'test trace with node format', |
| 202 | + }, |
| 203 | + attributes: [ |
| 204 | + { key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } }, |
| 205 | + { key: 'sentry.message.param.0', value: { stringValue: 'trace' } }, |
| 206 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 207 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 208 | + ], |
| 209 | + }, |
| 210 | + }) |
| 211 | + .expect({ |
| 212 | + otel_log: { |
| 213 | + severityText: 'debug', |
| 214 | + severityNumber: 5, // DEBUG |
| 215 | + body: { |
| 216 | + stringValue: 'test debug with node format', |
| 217 | + }, |
| 218 | + attributes: [ |
| 219 | + { key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } }, |
| 220 | + { key: 'sentry.message.param.0', value: { stringValue: 'debug' } }, |
| 221 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 222 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 223 | + ], |
| 224 | + }, |
| 225 | + }) |
| 226 | + .expect({ |
| 227 | + otel_log: { |
| 228 | + severityText: 'info', |
| 229 | + severityNumber: 9, // INFO |
| 230 | + body: { |
| 231 | + stringValue: 'test info with node format', |
| 232 | + }, |
| 233 | + attributes: [ |
| 234 | + { key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } }, |
| 235 | + { key: 'sentry.message.param.0', value: { stringValue: 'info' } }, |
| 236 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 237 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 238 | + ], |
| 239 | + }, |
| 240 | + }) |
| 241 | + .expect({ |
| 242 | + otel_log: { |
| 243 | + severityText: 'warn', |
| 244 | + severityNumber: 13, // WARN |
| 245 | + body: { |
| 246 | + stringValue: 'test warn with node format', |
| 247 | + }, |
| 248 | + attributes: [ |
| 249 | + { key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } }, |
| 250 | + { key: 'sentry.message.param.0', value: { stringValue: 'warn' } }, |
| 251 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 252 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 253 | + ], |
| 254 | + }, |
| 255 | + }) |
| 256 | + .expect({ |
| 257 | + otel_log: { |
| 258 | + severityText: 'error', |
| 259 | + severityNumber: 17, // ERROR |
| 260 | + body: { |
| 261 | + stringValue: 'test error with node format', |
| 262 | + }, |
| 263 | + attributes: [ |
| 264 | + { key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } }, |
| 265 | + { key: 'sentry.message.param.0', value: { stringValue: 'error' } }, |
| 266 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 267 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 268 | + ], |
| 269 | + }, |
| 270 | + }) |
| 271 | + .expect({ |
| 272 | + otel_log: { |
| 273 | + severityText: 'fatal', |
| 274 | + severityNumber: 21, // FATAL |
| 275 | + body: { |
| 276 | + stringValue: 'test fatal with node format', |
| 277 | + }, |
| 278 | + attributes: [ |
| 279 | + { key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } }, |
| 280 | + { key: 'sentry.message.param.0', value: { stringValue: 'fatal' } }, |
| 281 | + { key: 'release', value: { stringValue: '1.0' } }, |
| 282 | + { key: 'environment', value: { stringValue: 'test' } }, |
| 283 | + ], |
| 284 | + }, |
| 285 | + }) |
| 286 | + .start() |
| 287 | + .completed(); |
| 288 | +}); |
0 commit comments