@elastic/synthetics 1.0.0-beta.15 → 1.0.0-beta.19

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 (52) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/NOTICE.txt +29 -0
  3. package/README.md +1 -1
  4. package/dist/cli.js +34 -21
  5. package/dist/cli.js.map +1 -1
  6. package/dist/common_types.d.ts +10 -40
  7. package/dist/common_types.d.ts.map +1 -1
  8. package/dist/core/gatherer.d.ts.map +1 -1
  9. package/dist/core/gatherer.js +9 -1
  10. package/dist/core/gatherer.js.map +1 -1
  11. package/dist/core/logger.d.ts +0 -2
  12. package/dist/core/logger.d.ts.map +1 -1
  13. package/dist/core/logger.js +2 -15
  14. package/dist/core/logger.js.map +1 -1
  15. package/dist/core/runner.d.ts +19 -20
  16. package/dist/core/runner.d.ts.map +1 -1
  17. package/dist/core/runner.js +14 -5
  18. package/dist/core/runner.js.map +1 -1
  19. package/dist/formatter/javascript.d.ts +2 -0
  20. package/dist/formatter/javascript.d.ts.map +1 -1
  21. package/dist/formatter/javascript.js.map +1 -1
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +0 -6
  25. package/dist/index.js.map +1 -1
  26. package/dist/parse_args.d.ts.map +1 -1
  27. package/dist/parse_args.js +1 -1
  28. package/dist/parse_args.js.map +1 -1
  29. package/dist/plugins/network.d.ts +30 -11
  30. package/dist/plugins/network.d.ts.map +1 -1
  31. package/dist/plugins/network.js +234 -175
  32. package/dist/plugins/network.js.map +1 -1
  33. package/dist/reporters/base.d.ts.map +1 -1
  34. package/dist/reporters/base.js +6 -1
  35. package/dist/reporters/base.js.map +1 -1
  36. package/dist/reporters/json.d.ts +55 -5
  37. package/dist/reporters/json.d.ts.map +1 -1
  38. package/dist/reporters/json.js +45 -14
  39. package/dist/reporters/json.js.map +1 -1
  40. package/dist/tsconfig.tsbuildinfo +1 -1
  41. package/package.json +7 -7
  42. package/src/cli.ts +37 -25
  43. package/src/common_types.ts +10 -46
  44. package/src/core/gatherer.ts +8 -1
  45. package/src/core/logger.ts +1 -12
  46. package/src/core/runner.ts +42 -28
  47. package/src/formatter/javascript.ts +2 -0
  48. package/src/index.ts +1 -6
  49. package/src/parse_args.ts +1 -5
  50. package/src/plugins/network.ts +280 -213
  51. package/src/reporters/base.ts +6 -1
  52. package/src/reporters/json.ts +52 -16
@@ -45,8 +45,9 @@ import {
45
45
  StatusValue,
46
46
  PerfMetrics,
47
47
  Params,
48
- SecurityDetails,
48
+ Screenshot,
49
49
  } from '../common_types';
50
+ import { Protocol } from 'playwright-chromium/types/protocol';
50
51
  import { PageMetrics } from '../plugins';
51
52
 
52
53
  /* eslint-disable @typescript-eslint/no-var-requires */
@@ -127,10 +128,9 @@ function getMetadata() {
127
128
  };
128
129
  }
129
130
 
130
- /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
131
131
  function formatVersion(protocol: string | undefined) {
132
132
  if (!protocol) {
133
- return 1.1;
133
+ return;
134
134
  }
135
135
  if (protocol === 'h2') {
136
136
  return 2;
@@ -143,12 +143,41 @@ function formatVersion(protocol: string | undefined) {
143
143
  }
144
144
  }
145
145
 
146
- function formatTLS(tls: SecurityDetails) {
147
- if (!tls || !tls.issuer) {
146
+ function formatRequest(request: Protocol.Network.Request) {
147
+ const postData = request.postData ? request.postData : '';
148
+ return {
149
+ ...request,
150
+ body: {
151
+ bytes: postData.length,
152
+ content: postData,
153
+ },
154
+ referrer: request.headers?.Referer,
155
+ };
156
+ }
157
+
158
+ function formatResponse(response: Protocol.Network.Response) {
159
+ if (!response) {
148
160
  return;
149
161
  }
162
+ return {
163
+ ...response,
164
+ body: {
165
+ bytes: response.encodedDataLength,
166
+ },
167
+ status_code: response.status,
168
+ };
169
+ }
170
+
171
+ function formatTLS(tls: Protocol.Network.SecurityDetails) {
172
+ if (!tls) {
173
+ return;
174
+ }
175
+ const cipher = `${tls.keyExchange ? tls.keyExchange + '_' : ''}${
176
+ tls.cipher
177
+ }_${tls.keyExchangeGroup}`;
150
178
  const [name, version] = tls.protocol.toLowerCase().split(' ');
151
179
  return {
180
+ cipher,
152
181
  server: {
153
182
  x509: {
154
183
  issuer: {
@@ -174,11 +203,12 @@ export function formatNetworkFields(network: NetworkInfo) {
174
203
  user_agent: {
175
204
  name: browser.name,
176
205
  version: browser.version,
177
- original: request.headers?.['user-agent'],
206
+ original: request.headers?.['User-Agent'],
178
207
  },
179
208
  http: {
180
- request,
181
- response,
209
+ version: formatVersion(response?.protocol),
210
+ request: formatRequest(request),
211
+ response: formatResponse(response),
182
212
  },
183
213
  tls: formatTLS(response?.securityDetails),
184
214
  };
@@ -297,14 +327,14 @@ export async function getScreenshotBlocks(screenshot: Buffer) {
297
327
  */
298
328
  export async function gatherScreenshots(
299
329
  screenshotsPath: string,
300
- callback: (step: Step, data: string) => Promise<void>
330
+ callback: (data: Screenshot) => Promise<void>
301
331
  ) {
302
332
  if (isDirectory(screenshotsPath)) {
303
333
  await totalist(screenshotsPath, async (_, absPath) => {
304
334
  try {
305
335
  const content = readFileSync(absPath, 'utf8');
306
- const { step, data } = JSON.parse(content);
307
- await callback(step, data);
336
+ const screenshot: Screenshot = JSON.parse(content);
337
+ await callback(screenshot);
308
338
  } catch (_) {
309
339
  // TODO: capture progarammatic synthetic errors under different type
310
340
  }
@@ -406,6 +436,7 @@ export default class JSONReporter extends BaseReporter {
406
436
  'journey:end',
407
437
  async ({
408
438
  journey,
439
+ timestamp,
409
440
  start,
410
441
  end,
411
442
  networkinfo,
@@ -421,15 +452,17 @@ export default class JSONReporter extends BaseReporter {
421
452
  if (writeScreenshots) {
422
453
  await gatherScreenshots(
423
454
  join(CACHE_PATH, 'screenshots'),
424
- async (step, data) => {
455
+ async screenshot => {
456
+ const { data, timestamp, step } = screenshot;
425
457
  if (!data) {
426
458
  return;
427
459
  }
428
460
  if (ssblocks) {
429
- await this.writeScreenshotBlocks(journey, step, data);
461
+ await this.writeScreenshotBlocks(journey, screenshot);
430
462
  } else {
431
463
  this.writeJSON({
432
464
  type: 'step/screenshot',
465
+ timestamp,
433
466
  journey,
434
467
  step,
435
468
  blob: data,
@@ -472,6 +505,7 @@ export default class JSONReporter extends BaseReporter {
472
505
  this.writeJSON({
473
506
  type: 'journey/end',
474
507
  journey,
508
+ timestamp,
475
509
  error,
476
510
  payload: {
477
511
  start,
@@ -484,14 +518,15 @@ export default class JSONReporter extends BaseReporter {
484
518
  );
485
519
  }
486
520
 
487
- async writeScreenshotBlocks(journey: Journey, step: Step, data: string) {
521
+ async writeScreenshotBlocks(journey: Journey, screenshot: Screenshot) {
488
522
  const { blob_mime, blocks, reference } = await getScreenshotBlocks(
489
- Buffer.from(data, 'base64')
523
+ Buffer.from(screenshot.data, 'base64')
490
524
  );
491
525
  for (let i = 0; i < blocks.length; i++) {
492
526
  const block = blocks[i];
493
527
  this.writeJSON({
494
528
  type: 'screenshot/block',
529
+ timestamp: screenshot.timestamp,
495
530
  _id: block.id,
496
531
  blob: block.blob,
497
532
  blob_mime,
@@ -499,8 +534,9 @@ export default class JSONReporter extends BaseReporter {
499
534
  }
500
535
  this.writeJSON({
501
536
  type: 'step/screenshot_ref',
537
+ timestamp: screenshot.timestamp,
502
538
  journey,
503
- step,
539
+ step: screenshot.step,
504
540
  root_fields: {
505
541
  screenshot_ref: reference,
506
542
  },