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