File
Blob: src/cloudflare/internal/test/images/images-api-instrumentation-test.js
| 1 | // Copyright (c) 2017-2023 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | import { |
| 6 | createInstrumentationState, |
| 7 | createTailStreamHandler, |
| 8 | runInstrumentationTest, |
| 9 | } from 'instrumentation-test-helper'; |
| 10 | |
| 11 | const state = createInstrumentationState(); |
| 12 | |
| 13 | export default { |
| 14 | tailStream: createTailStreamHandler(state), |
| 15 | }; |
| 16 | |
| 17 | export const test = { |
| 18 | async test() { |
| 19 | // Use the helper with mapFn to normalize dynamic multipart boundaries |
| 20 | await runInstrumentationTest(state, expectedSpans, { |
| 21 | testName: 'Images instrumentation', |
| 22 | mapFn: (span) => { |
| 23 | const contentType = span['http.request.header.content-type']; |
| 24 | if (contentType?.startsWith('multipart/form-data; boundary=')) { |
| 25 | return { |
| 26 | ...span, |
| 27 | 'http.request.header.content-type': |
| 28 | 'multipart/form-data; boundary=<dynamic>', |
| 29 | }; |
| 30 | } |
| 31 | return span; |
| 32 | }, |
| 33 | }); |
| 34 | }, |
| 35 | }; |
| 36 | |
| 37 | // spans emitted by images-api-test.js in execution order |
| 38 | const expectedSpans = [ |
| 39 | { |
| 40 | name: 'images_output', |
| 41 | 'cloudflare.binding.type': 'Images', |
| 42 | 'cloudflare.images.options.format': 'image/avif', |
| 43 | closed: true, |
| 44 | }, |
| 45 | { |
| 46 | name: 'fetch', |
| 47 | 'network.protocol.name': 'http', |
| 48 | 'network.protocol.version': 'HTTP/1.1', |
| 49 | 'http.request.method': 'POST', |
| 50 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 51 | 'http.request.header.content-type': |
| 52 | 'multipart/form-data; boundary=<dynamic>', |
| 53 | 'http.response.status_code': 200n, |
| 54 | 'http.response.body.size': 63n, |
| 55 | closed: true, |
| 56 | }, |
| 57 | { |
| 58 | name: 'images_output', |
| 59 | 'cloudflare.binding.type': 'Images', |
| 60 | 'cloudflare.images.options.format': 'image/avif', |
| 61 | closed: true, |
| 62 | }, |
| 63 | { |
| 64 | name: 'fetch', |
| 65 | 'network.protocol.name': 'http', |
| 66 | 'network.protocol.version': 'HTTP/1.1', |
| 67 | 'http.request.method': 'POST', |
| 68 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 69 | 'http.request.header.content-type': |
| 70 | 'multipart/form-data; boundary=<dynamic>', |
| 71 | 'http.response.status_code': 200n, |
| 72 | 'http.response.body.size': 57n, |
| 73 | closed: true, |
| 74 | }, |
| 75 | { |
| 76 | name: 'images_output', |
| 77 | 'cloudflare.binding.type': 'Images', |
| 78 | 'cloudflare.images.options.transforms': '[{"imageIndex":0,"rotate":90}]', |
| 79 | 'cloudflare.images.options.format': 'image/avif', |
| 80 | closed: true, |
| 81 | }, |
| 82 | { |
| 83 | name: 'fetch', |
| 84 | 'network.protocol.name': 'http', |
| 85 | 'network.protocol.version': 'HTTP/1.1', |
| 86 | 'http.request.method': 'POST', |
| 87 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 88 | 'http.request.header.content-type': |
| 89 | 'multipart/form-data; boundary=<dynamic>', |
| 90 | 'http.response.status_code': 200n, |
| 91 | 'http.response.body.size': 88n, |
| 92 | closed: true, |
| 93 | }, |
| 94 | { |
| 95 | name: 'images_output', |
| 96 | 'cloudflare.binding.type': 'Images', |
| 97 | 'cloudflare.images.options.transforms': '[{"imageIndex":0,"rotate":90}]', |
| 98 | 'cloudflare.images.options.format': 'image/avif', |
| 99 | closed: true, |
| 100 | }, |
| 101 | { |
| 102 | name: 'fetch', |
| 103 | 'network.protocol.name': 'http', |
| 104 | 'network.protocol.version': 'HTTP/1.1', |
| 105 | 'http.request.method': 'POST', |
| 106 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 107 | 'http.request.header.content-type': |
| 108 | 'multipart/form-data; boundary=<dynamic>', |
| 109 | 'http.response.status_code': 200n, |
| 110 | 'http.response.body.size': 24661n, |
| 111 | closed: true, |
| 112 | }, |
| 113 | { |
| 114 | name: 'images_output', |
| 115 | 'cloudflare.binding.type': 'Images', |
| 116 | 'cloudflare.images.options.transforms': '[{"imageIndex":0,"rotate":90}]', |
| 117 | 'cloudflare.images.options.format': 'image/avif', |
| 118 | closed: true, |
| 119 | }, |
| 120 | { |
| 121 | name: 'fetch', |
| 122 | 'network.protocol.name': 'http', |
| 123 | 'network.protocol.version': 'HTTP/1.1', |
| 124 | 'http.request.method': 'POST', |
| 125 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 126 | 'http.request.header.content-type': |
| 127 | 'multipart/form-data; boundary=<dynamic>', |
| 128 | 'http.response.status_code': 200n, |
| 129 | 'http.response.body.size': 24664n, |
| 130 | closed: true, |
| 131 | }, |
| 132 | { |
| 133 | name: 'images_output', |
| 134 | 'cloudflare.binding.type': 'Images', |
| 135 | 'cloudflare.images.options.transforms': '[{"imageIndex":0,"rotate":90}]', |
| 136 | 'cloudflare.images.options.format': 'image/avif', |
| 137 | closed: true, |
| 138 | }, |
| 139 | { |
| 140 | name: 'fetch', |
| 141 | 'network.protocol.name': 'http', |
| 142 | 'network.protocol.version': 'HTTP/1.1', |
| 143 | 'http.request.method': 'POST', |
| 144 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 145 | 'http.request.header.content-type': |
| 146 | 'multipart/form-data; boundary=<dynamic>', |
| 147 | 'http.response.status_code': 200n, |
| 148 | 'http.response.body.size': 491605n, |
| 149 | closed: true, |
| 150 | }, |
| 151 | { |
| 152 | name: 'images_output', |
| 153 | 'cloudflare.binding.type': 'Images', |
| 154 | 'cloudflare.images.options.transforms': '[{"imageIndex":0,"rotate":90}]', |
| 155 | 'cloudflare.images.options.format': 'image/avif', |
| 156 | closed: true, |
| 157 | }, |
| 158 | { |
| 159 | name: 'fetch', |
| 160 | 'network.protocol.name': 'http', |
| 161 | 'network.protocol.version': 'HTTP/1.1', |
| 162 | 'http.request.method': 'POST', |
| 163 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 164 | 'http.request.header.content-type': |
| 165 | 'multipart/form-data; boundary=<dynamic>', |
| 166 | 'http.response.status_code': 200n, |
| 167 | 'http.response.body.size': 86n, |
| 168 | closed: true, |
| 169 | }, |
| 170 | { |
| 171 | name: 'images_output', |
| 172 | 'cloudflare.binding.type': 'Images', |
| 173 | 'cloudflare.images.options.transforms': '[{"imageIndex":0,"rotate":90}]', |
| 174 | 'cloudflare.images.options.format': 'image/avif', |
| 175 | closed: true, |
| 176 | }, |
| 177 | { |
| 178 | name: 'fetch', |
| 179 | 'network.protocol.name': 'http', |
| 180 | 'network.protocol.version': 'HTTP/1.1', |
| 181 | 'http.request.method': 'POST', |
| 182 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 183 | 'http.request.header.content-type': |
| 184 | 'multipart/form-data; boundary=<dynamic>', |
| 185 | 'http.response.status_code': 200n, |
| 186 | 'http.response.body.size': 32855n, |
| 187 | closed: true, |
| 188 | }, |
| 189 | { |
| 190 | name: 'images_output', |
| 191 | 'cloudflare.binding.type': 'Images', |
| 192 | 'cloudflare.images.options.transforms': '[{"imageIndex":0,"rotate":90}]', |
| 193 | 'cloudflare.images.options.format': 'image/avif', |
| 194 | closed: true, |
| 195 | }, |
| 196 | { |
| 197 | name: 'fetch', |
| 198 | 'network.protocol.name': 'http', |
| 199 | 'network.protocol.version': 'HTTP/1.1', |
| 200 | 'http.request.method': 'POST', |
| 201 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 202 | 'http.request.header.content-type': |
| 203 | 'multipart/form-data; boundary=<dynamic>', |
| 204 | 'http.response.status_code': 200n, |
| 205 | 'http.response.body.size': 655465n, |
| 206 | closed: true, |
| 207 | }, |
| 208 | { |
| 209 | name: 'images_output', |
| 210 | 'cloudflare.binding.type': 'Images', |
| 211 | 'cloudflare.images.options.format': 'image/avif', |
| 212 | closed: true, |
| 213 | }, |
| 214 | { |
| 215 | name: 'fetch', |
| 216 | 'network.protocol.name': 'http', |
| 217 | 'network.protocol.version': 'HTTP/1.1', |
| 218 | 'http.request.method': 'POST', |
| 219 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 220 | 'http.request.header.content-type': |
| 221 | 'multipart/form-data; boundary=<dynamic>', |
| 222 | 'http.response.status_code': 200n, |
| 223 | 'http.response.body.size': 58n, |
| 224 | closed: true, |
| 225 | }, |
| 226 | { |
| 227 | name: 'images_output', |
| 228 | 'cloudflare.binding.type': 'Images', |
| 229 | 'cloudflare.images.options.format': 'image/avif', |
| 230 | closed: true, |
| 231 | }, |
| 232 | { |
| 233 | name: 'fetch', |
| 234 | 'network.protocol.name': 'http', |
| 235 | 'network.protocol.version': 'HTTP/1.1', |
| 236 | 'http.request.method': 'POST', |
| 237 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 238 | 'http.request.header.content-type': |
| 239 | 'multipart/form-data; boundary=<dynamic>', |
| 240 | 'http.response.status_code': 200n, |
| 241 | 'http.response.body.size': 59n, |
| 242 | closed: true, |
| 243 | }, |
| 244 | { |
| 245 | name: 'images_output', |
| 246 | 'cloudflare.binding.type': 'Images', |
| 247 | 'cloudflare.images.options.format': 'image/avif', |
| 248 | closed: true, |
| 249 | }, |
| 250 | { |
| 251 | name: 'fetch', |
| 252 | 'network.protocol.name': 'http', |
| 253 | 'network.protocol.version': 'HTTP/1.1', |
| 254 | 'http.request.method': 'POST', |
| 255 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 256 | 'http.request.header.content-type': |
| 257 | 'multipart/form-data; boundary=<dynamic>', |
| 258 | 'http.response.status_code': 200n, |
| 259 | 'http.response.body.size': 60n, |
| 260 | closed: true, |
| 261 | }, |
| 262 | { |
| 263 | name: 'images_output', |
| 264 | 'cloudflare.binding.type': 'Images', |
| 265 | 'cloudflare.images.options.format': 'image/avif', |
| 266 | closed: true, |
| 267 | }, |
| 268 | { |
| 269 | name: 'fetch', |
| 270 | 'network.protocol.name': 'http', |
| 271 | 'network.protocol.version': 'HTTP/1.1', |
| 272 | 'http.request.method': 'POST', |
| 273 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 274 | 'http.request.header.content-type': |
| 275 | 'multipart/form-data; boundary=<dynamic>', |
| 276 | 'http.response.status_code': 200n, |
| 277 | 'http.response.body.size': 63n, |
| 278 | closed: true, |
| 279 | }, |
| 280 | { |
| 281 | name: 'images_output', |
| 282 | 'cloudflare.binding.type': 'Images', |
| 283 | 'cloudflare.images.options.format': 'image/avif', |
| 284 | closed: true, |
| 285 | }, |
| 286 | { |
| 287 | name: 'fetch', |
| 288 | 'network.protocol.name': 'http', |
| 289 | 'network.protocol.version': 'HTTP/1.1', |
| 290 | 'http.request.method': 'POST', |
| 291 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 292 | 'http.request.header.content-type': |
| 293 | 'multipart/form-data; boundary=<dynamic>', |
| 294 | 'http.response.status_code': 200n, |
| 295 | 'http.response.body.size': 63n, |
| 296 | closed: true, |
| 297 | }, |
| 298 | { |
| 299 | name: 'images_output', |
| 300 | 'cloudflare.binding.type': 'Images', |
| 301 | 'cloudflare.images.options.format': 'image/avif', |
| 302 | closed: true, |
| 303 | }, |
| 304 | { |
| 305 | name: 'fetch', |
| 306 | 'network.protocol.name': 'http', |
| 307 | 'network.protocol.version': 'HTTP/1.1', |
| 308 | 'http.request.method': 'POST', |
| 309 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 310 | 'http.request.header.content-type': |
| 311 | 'multipart/form-data; boundary=<dynamic>', |
| 312 | 'http.response.status_code': 200n, |
| 313 | 'http.response.body.size': 63n, |
| 314 | closed: true, |
| 315 | }, |
| 316 | { |
| 317 | name: 'images_info', |
| 318 | 'cloudflare.binding.type': 'Images', |
| 319 | 'cloudflare.images.options.encoding': 'base64', |
| 320 | 'cloudflare.images.result.format': 'image/png', |
| 321 | 'cloudflare.images.result.file_size': 123, |
| 322 | 'cloudflare.images.result.width': 123, |
| 323 | 'cloudflare.images.result.height': 123, |
| 324 | closed: true, |
| 325 | }, |
| 326 | { |
| 327 | name: 'fetch', |
| 328 | 'network.protocol.name': 'http', |
| 329 | 'network.protocol.version': 'HTTP/1.1', |
| 330 | 'http.request.method': 'POST', |
| 331 | 'url.full': 'https://js.images.cloudflare.com/info', |
| 332 | 'http.request.header.content-type': |
| 333 | 'multipart/form-data; boundary=<dynamic>', |
| 334 | 'http.response.status_code': 200n, |
| 335 | 'http.response.body.size': 63n, |
| 336 | closed: true, |
| 337 | }, |
| 338 | { |
| 339 | name: 'images_info', |
| 340 | 'cloudflare.binding.type': 'Images', |
| 341 | 'cloudflare.images.options.encoding': 'base64', |
| 342 | 'cloudflare.images.result.format': 'image/png', |
| 343 | 'cloudflare.images.result.file_size': 123, |
| 344 | 'cloudflare.images.result.width': 123, |
| 345 | 'cloudflare.images.result.height': 123, |
| 346 | closed: true, |
| 347 | }, |
| 348 | { |
| 349 | name: 'fetch', |
| 350 | 'network.protocol.name': 'http', |
| 351 | 'network.protocol.version': 'HTTP/1.1', |
| 352 | 'http.request.method': 'POST', |
| 353 | 'url.full': 'https://js.images.cloudflare.com/info', |
| 354 | 'http.request.header.content-type': |
| 355 | 'multipart/form-data; boundary=<dynamic>', |
| 356 | 'http.response.status_code': 200n, |
| 357 | 'http.response.body.size': 63n, |
| 358 | closed: true, |
| 359 | }, |
| 360 | { |
| 361 | name: 'images_info', |
| 362 | 'cloudflare.binding.type': 'Images', |
| 363 | 'cloudflare.images.options.encoding': 'base64', |
| 364 | 'cloudflare.images.error.code': '123', |
| 365 | 'error.type': 'ERROR 123: Bad request', |
| 366 | closed: true, |
| 367 | }, |
| 368 | { |
| 369 | name: 'fetch', |
| 370 | 'network.protocol.name': 'http', |
| 371 | 'network.protocol.version': 'HTTP/1.1', |
| 372 | 'http.request.method': 'POST', |
| 373 | 'url.full': 'https://js.images.cloudflare.com/info', |
| 374 | 'http.request.header.content-type': |
| 375 | 'multipart/form-data; boundary=<dynamic>', |
| 376 | 'http.response.status_code': 409n, |
| 377 | 'http.response.body.size': 22n, |
| 378 | closed: true, |
| 379 | }, |
| 380 | { |
| 381 | name: 'images_info', |
| 382 | 'cloudflare.binding.type': 'Images', |
| 383 | 'cloudflare.images.options.encoding': 'base64', |
| 384 | 'cloudflare.images.result.format': 'image/svg+xml', |
| 385 | closed: true, |
| 386 | }, |
| 387 | { |
| 388 | name: 'fetch', |
| 389 | 'network.protocol.name': 'http', |
| 390 | 'network.protocol.version': 'HTTP/1.1', |
| 391 | 'http.request.method': 'POST', |
| 392 | 'url.full': 'https://js.images.cloudflare.com/info', |
| 393 | 'http.request.header.content-type': |
| 394 | 'multipart/form-data; boundary=<dynamic>', |
| 395 | 'http.response.status_code': 200n, |
| 396 | 'http.response.body.size': 26n, |
| 397 | closed: true, |
| 398 | }, |
| 399 | { |
| 400 | name: 'images_output', |
| 401 | 'cloudflare.binding.type': 'Images', |
| 402 | 'cloudflare.images.options.transforms': |
| 403 | '[{"imageIndex":0,"rotate":90},{"imageIndex":1,"rotate":180},{"drawImageIndex":1,"targetImageIndex":0},{"drawImageIndex":3,"targetImageIndex":2},{"imageIndex":2,"rotate":270},{"drawImageIndex":2,"targetImageIndex":0},{"drawImageIndex":4,"targetImageIndex":0}]', |
| 404 | 'cloudflare.images.options.format': 'image/avif', |
| 405 | closed: true, |
| 406 | }, |
| 407 | { |
| 408 | name: 'fetch', |
| 409 | 'network.protocol.name': 'http', |
| 410 | 'network.protocol.version': 'HTTP/1.1', |
| 411 | 'http.request.method': 'POST', |
| 412 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 413 | 'http.request.header.content-type': |
| 414 | 'multipart/form-data; boundary=<dynamic>', |
| 415 | 'http.response.status_code': 200n, |
| 416 | 'http.response.body.size': 359n, |
| 417 | closed: true, |
| 418 | }, |
| 419 | { |
| 420 | name: 'images_output', |
| 421 | 'cloudflare.binding.type': 'Images', |
| 422 | 'cloudflare.images.options.transforms': '[{"imageIndex":0,"rotate":90}]', |
| 423 | 'cloudflare.images.options.format': 'image/avif', |
| 424 | 'cloudflare.images.options.anim': true, |
| 425 | closed: true, |
| 426 | }, |
| 427 | { |
| 428 | name: 'fetch', |
| 429 | 'network.protocol.name': 'http', |
| 430 | 'network.protocol.version': 'HTTP/1.1', |
| 431 | 'http.request.method': 'POST', |
| 432 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 433 | 'http.request.header.content-type': |
| 434 | 'multipart/form-data; boundary=<dynamic>', |
| 435 | 'http.response.status_code': 200n, |
| 436 | 'http.response.body.size': 102n, |
| 437 | closed: true, |
| 438 | }, |
| 439 | { |
| 440 | name: 'images_output', |
| 441 | 'cloudflare.binding.type': 'Images', |
| 442 | 'cloudflare.images.options.transforms': '[{"imageIndex":0,"rotate":90}]', |
| 443 | 'cloudflare.images.options.format': 'image/avif', |
| 444 | 'cloudflare.images.error.code': '123', |
| 445 | 'error.type': 'ERROR 123: Bad request', |
| 446 | closed: true, |
| 447 | }, |
| 448 | { |
| 449 | name: 'fetch', |
| 450 | 'network.protocol.name': 'http', |
| 451 | 'network.protocol.version': 'HTTP/1.1', |
| 452 | 'http.request.method': 'POST', |
| 453 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 454 | 'http.request.header.content-type': |
| 455 | 'multipart/form-data; boundary=<dynamic>', |
| 456 | 'http.response.status_code': 409n, |
| 457 | 'http.response.body.size': 22n, |
| 458 | closed: true, |
| 459 | }, |
| 460 | { |
| 461 | name: 'images_output', |
| 462 | 'cloudflare.binding.type': 'Images', |
| 463 | 'cloudflare.images.options.transforms': '[{"imageIndex":0,"rotate":90}]', |
| 464 | 'cloudflare.images.options.format': 'image/avif', |
| 465 | closed: true, |
| 466 | }, |
| 467 | { |
| 468 | name: 'fetch', |
| 469 | 'network.protocol.name': 'http', |
| 470 | 'network.protocol.version': 'HTTP/1.1', |
| 471 | 'http.request.method': 'POST', |
| 472 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 473 | 'http.request.header.content-type': |
| 474 | 'multipart/form-data; boundary=<dynamic>', |
| 475 | 'http.response.status_code': 200n, |
| 476 | 'http.response.body.size': 88n, |
| 477 | closed: true, |
| 478 | }, |
| 479 | { |
| 480 | name: 'images_output', |
| 481 | 'cloudflare.binding.type': 'Images', |
| 482 | closed: true, |
| 483 | }, |
| 484 | { |
| 485 | name: 'fetch', |
| 486 | 'network.protocol.name': 'http', |
| 487 | 'network.protocol.version': 'HTTP/1.1', |
| 488 | 'http.request.method': 'POST', |
| 489 | 'url.full': 'https://js.images.cloudflare.com/transform', |
| 490 | 'http.request.header.content-type': |
| 491 | 'multipart/form-data; boundary=<dynamic>', |
| 492 | 'http.response.status_code': 200n, |
| 493 | 'http.response.body.size': 60n, |
| 494 | closed: true, |
| 495 | }, |
| 496 | { |
| 497 | name: 'images_output', |
| 498 | 'cloudflare.binding.type': 'Images', |
| 499 | closed: true, |
| 500 | }, |
| 501 | ]; |