@elastic/synthetics 1.0.0-beta.3 → 1.0.0-beta.32

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 (202) hide show
  1. package/README.md +4 -3
  2. package/dist/cli.js +123 -161
  3. package/dist/cli.js.map +1 -1
  4. package/dist/common_types.d.ts +159 -34
  5. package/dist/common_types.d.ts.map +1 -1
  6. package/dist/config.d.ts +2 -5
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +5 -5
  9. package/dist/config.js.map +1 -1
  10. package/dist/core/browser-service.js +5 -5
  11. package/dist/core/browser-service.js.map +1 -1
  12. package/dist/core/expect.d.ts +25 -25
  13. package/dist/core/expect.d.ts.map +1 -1
  14. package/dist/core/expect.js.map +1 -1
  15. package/dist/core/gatherer.d.ts +4 -8
  16. package/dist/core/gatherer.d.ts.map +1 -1
  17. package/dist/core/gatherer.js +49 -15
  18. package/dist/core/gatherer.js.map +1 -1
  19. package/dist/core/index.d.ts +5 -1
  20. package/dist/core/index.d.ts.map +1 -1
  21. package/dist/core/index.js +23 -11
  22. package/dist/core/index.js.map +1 -1
  23. package/dist/core/logger.d.ts +0 -1
  24. package/dist/core/logger.d.ts.map +1 -1
  25. package/dist/core/logger.js +3 -16
  26. package/dist/core/logger.js.map +1 -1
  27. package/dist/core/runner.d.ts +21 -65
  28. package/dist/core/runner.d.ts.map +1 -1
  29. package/dist/core/runner.js +212 -93
  30. package/dist/core/runner.js.map +1 -1
  31. package/dist/dsl/index.js +5 -1
  32. package/dist/dsl/index.js.map +1 -1
  33. package/dist/dsl/journey.d.ts +9 -4
  34. package/dist/dsl/journey.d.ts.map +1 -1
  35. package/dist/dsl/journey.js +27 -7
  36. package/dist/dsl/journey.js.map +1 -1
  37. package/dist/dsl/monitor.d.ts +66 -0
  38. package/dist/dsl/monitor.d.ts.map +1 -0
  39. package/dist/dsl/monitor.js +63 -0
  40. package/dist/dsl/monitor.js.map +1 -0
  41. package/dist/dsl/step.d.ts +3 -2
  42. package/dist/dsl/step.d.ts.map +1 -1
  43. package/dist/dsl/step.js +2 -1
  44. package/dist/dsl/step.js.map +1 -1
  45. package/dist/formatter/javascript.d.ts +98 -0
  46. package/dist/formatter/javascript.d.ts.map +1 -0
  47. package/dist/formatter/javascript.js +295 -0
  48. package/dist/formatter/javascript.js.map +1 -0
  49. package/dist/generator/index.d.ts +29 -0
  50. package/dist/generator/index.d.ts.map +1 -0
  51. package/dist/generator/index.js +240 -0
  52. package/dist/generator/index.js.map +1 -0
  53. package/dist/{reporters/reporter.js → generator/utils.d.ts} +5 -3
  54. package/dist/generator/utils.d.ts.map +1 -0
  55. package/dist/generator/utils.js +80 -0
  56. package/dist/generator/utils.js.map +1 -0
  57. package/dist/helpers.d.ts +24 -1
  58. package/dist/helpers.d.ts.map +1 -1
  59. package/dist/helpers.js +126 -19
  60. package/dist/helpers.js.map +1 -1
  61. package/dist/index.d.ts +6 -7
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +5 -26
  64. package/dist/index.js.map +1 -1
  65. package/dist/{parse_args.d.ts → loader.d.ts} +2 -5
  66. package/dist/loader.d.ts.map +1 -0
  67. package/dist/loader.js +152 -0
  68. package/dist/loader.js.map +1 -0
  69. package/dist/locations/index.d.ts +45 -0
  70. package/dist/locations/index.d.ts.map +1 -0
  71. package/dist/locations/index.js +90 -0
  72. package/dist/locations/index.js.map +1 -0
  73. package/dist/{reporters/reporter.d.ts → locations/public-locations.d.ts} +12 -8
  74. package/dist/locations/public-locations.d.ts.map +1 -0
  75. package/dist/locations/public-locations.js +41 -0
  76. package/dist/locations/public-locations.js.map +1 -0
  77. package/dist/options.d.ts +41 -0
  78. package/dist/options.d.ts.map +1 -0
  79. package/dist/options.js +182 -0
  80. package/dist/options.js.map +1 -0
  81. package/dist/plugins/browser-console.d.ts +5 -4
  82. package/dist/plugins/browser-console.d.ts.map +1 -1
  83. package/dist/plugins/browser-console.js +27 -8
  84. package/dist/plugins/browser-console.js.map +1 -1
  85. package/dist/plugins/index.js +5 -1
  86. package/dist/plugins/index.js.map +1 -1
  87. package/dist/plugins/network.d.ts +20 -33
  88. package/dist/plugins/network.d.ts.map +1 -1
  89. package/dist/plugins/network.js +173 -214
  90. package/dist/plugins/network.js.map +1 -1
  91. package/dist/plugins/performance.d.ts +4 -19
  92. package/dist/plugins/performance.d.ts.map +1 -1
  93. package/dist/plugins/performance.js +5 -5
  94. package/dist/plugins/performance.js.map +1 -1
  95. package/dist/plugins/plugin-manager.d.ts +9 -5
  96. package/dist/plugins/plugin-manager.d.ts.map +1 -1
  97. package/dist/plugins/plugin-manager.js +44 -29
  98. package/dist/plugins/plugin-manager.js.map +1 -1
  99. package/dist/plugins/tracing.d.ts +6 -6
  100. package/dist/plugins/tracing.d.ts.map +1 -1
  101. package/dist/plugins/tracing.js +8 -7
  102. package/dist/plugins/tracing.js.map +1 -1
  103. package/dist/push/bundler.d.ts +34 -0
  104. package/dist/push/bundler.d.ts.map +1 -0
  105. package/dist/push/bundler.js +123 -0
  106. package/dist/push/bundler.js.map +1 -0
  107. package/dist/push/index.d.ts +33 -0
  108. package/dist/push/index.d.ts.map +1 -0
  109. package/dist/push/index.js +174 -0
  110. package/dist/push/index.js.map +1 -0
  111. package/dist/push/monitor.d.ts +34 -0
  112. package/dist/push/monitor.d.ts.map +1 -0
  113. package/dist/push/monitor.js +78 -0
  114. package/dist/push/monitor.js.map +1 -0
  115. package/{src/reporters/reporter.ts → dist/push/plugin.d.ts} +8 -10
  116. package/dist/push/plugin.d.ts.map +1 -0
  117. package/dist/push/plugin.js +133 -0
  118. package/dist/push/plugin.js.map +1 -0
  119. package/dist/push/request.d.ts +43 -0
  120. package/dist/push/request.d.ts.map +1 -0
  121. package/dist/push/request.js +83 -0
  122. package/dist/push/request.js.map +1 -0
  123. package/dist/reporters/base.d.ts +14 -6
  124. package/dist/reporters/base.d.ts.map +1 -1
  125. package/dist/reporters/base.js +54 -48
  126. package/dist/reporters/base.js.map +1 -1
  127. package/dist/reporters/index.d.ts +18 -8
  128. package/dist/reporters/index.d.ts.map +1 -1
  129. package/dist/reporters/index.js.map +1 -1
  130. package/dist/reporters/json.d.ts +18 -67
  131. package/dist/reporters/json.d.ts.map +1 -1
  132. package/dist/reporters/json.js +153 -175
  133. package/dist/reporters/json.js.map +1 -1
  134. package/dist/reporters/junit.d.ts +7 -1
  135. package/dist/reporters/junit.d.ts.map +1 -1
  136. package/dist/reporters/junit.js +94 -89
  137. package/dist/reporters/junit.js.map +1 -1
  138. package/dist/sdk/lh-trace-processor.d.ts +35 -9
  139. package/dist/sdk/lh-trace-processor.d.ts.map +1 -1
  140. package/dist/sdk/lh-trace-processor.js +114 -53
  141. package/dist/sdk/lh-trace-processor.js.map +1 -1
  142. package/dist/sdk/trace-metrics.d.ts +4 -4
  143. package/dist/sdk/trace-metrics.d.ts.map +1 -1
  144. package/dist/sdk/trace-metrics.js +5 -6
  145. package/dist/sdk/trace-metrics.js.map +1 -1
  146. package/dist/sdk/trace-processor.d.ts +11 -3
  147. package/dist/sdk/trace-processor.d.ts.map +1 -1
  148. package/dist/sdk/trace-processor.js +17 -9
  149. package/dist/sdk/trace-processor.js.map +1 -1
  150. package/dist/tsconfig.tsbuildinfo +1 -1888
  151. package/package.json +32 -20
  152. package/src/cli.ts +205 -152
  153. package/src/common_types.ts +192 -34
  154. package/src/config.ts +2 -5
  155. package/src/core/expect.ts +58 -24
  156. package/src/core/gatherer.ts +59 -24
  157. package/src/core/index.ts +36 -15
  158. package/src/core/logger.ts +1 -12
  159. package/src/core/runner.ts +215 -152
  160. package/src/dsl/journey.ts +37 -6
  161. package/src/dsl/monitor.ts +88 -0
  162. package/src/dsl/step.ts +9 -2
  163. package/src/formatter/javascript.ts +367 -0
  164. package/src/generator/index.ts +316 -0
  165. package/src/generator/utils.ts +80 -0
  166. package/src/helpers.ts +132 -12
  167. package/src/index.ts +22 -22
  168. package/src/loader.ts +171 -0
  169. package/src/locations/index.ts +108 -0
  170. package/src/locations/public-locations.ts +38 -0
  171. package/src/options.ts +211 -0
  172. package/src/plugins/browser-console.ts +30 -8
  173. package/src/plugins/network.ts +208 -267
  174. package/src/plugins/performance.ts +6 -22
  175. package/src/plugins/plugin-manager.ts +49 -31
  176. package/src/plugins/tracing.ts +8 -9
  177. package/src/push/bundler.ts +100 -0
  178. package/src/push/index.ts +202 -0
  179. package/src/push/monitor.ts +96 -0
  180. package/src/push/plugin.ts +119 -0
  181. package/src/push/request.ts +103 -0
  182. package/src/reporters/base.ts +63 -52
  183. package/src/reporters/index.ts +26 -3
  184. package/src/reporters/json.ts +203 -206
  185. package/src/reporters/junit.ts +98 -93
  186. package/src/sdk/lh-trace-processor.ts +132 -68
  187. package/src/sdk/trace-metrics.ts +10 -6
  188. package/src/sdk/trace-processor.ts +28 -13
  189. package/templates/.github/workflows/run-synthetics.yml +26 -0
  190. package/templates/README.md +21 -0
  191. package/templates/journeys/advanced-example-helpers.ts +54 -0
  192. package/templates/journeys/advanced-example.journey.ts +43 -0
  193. package/templates/journeys/example.journey.ts +18 -0
  194. package/templates/synthetics.config.ts +27 -0
  195. package/CHANGELOG.md +0 -102
  196. package/NOTICE.txt +0 -221
  197. package/dist/parse_args.d.ts.map +0 -1
  198. package/dist/parse_args.js +0 -89
  199. package/dist/parse_args.js.map +0 -1
  200. package/dist/reporters/reporter.d.ts.map +0 -1
  201. package/dist/reporters/reporter.js.map +0 -1
  202. package/src/parse_args.ts +0 -127
@@ -25,21 +25,20 @@
25
25
  /// <reference types="node" />
26
26
  import BaseReporter from './base';
27
27
  import { Journey, Step } from '../dsl';
28
- import { NetworkInfo, TraceOutput, StatusValue, PerfMetrics } from '../common_types';
29
- import { Protocol } from 'playwright-chromium/types/protocol';
30
- import { Metrics } from '../plugins';
31
- declare type OutputType = 'synthetics/metadata' | 'journey/register' | 'journey/start' | 'screenshot/block' | 'step/screenshot_ref' | 'step/screenshot' | 'step/end' | 'journey/network_info' | 'journey/filmstrips' | 'journey/browserconsole' | 'journey/metrics' | 'journey/end';
28
+ import { NetworkInfo, NetworkConditions, TraceOutput, StatusValue, PerfMetrics, Params, Screenshot, StartEvent, JourneyStartResult, StepEndResult, JourneyEndResult, PageMetrics } from '../common_types';
29
+ declare type OutputType = 'synthetics/metadata' | 'journey/register' | 'journey/start' | 'screenshot/block' | 'step/screenshot_ref' | 'step/screenshot' | 'step/metrics' | 'step/filmstrips' | 'step/end' | 'journey/network_info' | 'journey/browserconsole' | 'journey/end';
32
30
  declare type Payload = {
33
31
  source?: string;
34
32
  start?: number;
35
33
  end?: number;
36
34
  url?: string;
37
- status?: StatusValue | number;
38
- metrics?: Metrics;
39
- params?: Record<string, unknown>;
35
+ status?: StatusValue;
36
+ pagemetrics?: PageMetrics;
37
+ params?: Params;
40
38
  type?: OutputType;
41
39
  text?: string;
42
40
  index?: number;
41
+ network_conditions?: NetworkConditions;
43
42
  };
44
43
  declare type OutputFields = {
45
44
  type: OutputType;
@@ -54,7 +53,7 @@ declare type OutputFields = {
54
53
  };
55
54
  error?: Error;
56
55
  root_fields?: Record<string, unknown>;
57
- payload?: Payload | NetworkInfo;
56
+ payload?: Payload;
58
57
  blob?: string;
59
58
  blob_mime?: string;
60
59
  };
@@ -73,12 +72,6 @@ declare type ScreenshotReference = {
73
72
  height: number;
74
73
  }>;
75
74
  };
76
- declare type ScreenshotOutput = {
77
- step: Step;
78
- blob_mime: string;
79
- blocks: Array<ScreenshotBlob>;
80
- reference: ScreenshotReference;
81
- };
82
75
  export declare function formatNetworkFields(network: NetworkInfo): {
83
76
  ecs: {
84
77
  url: string;
@@ -88,58 +81,10 @@ export declare function formatNetworkFields(network: NetworkInfo): {
88
81
  original: string;
89
82
  };
90
83
  http: {
91
- version: number;
92
- request: {
93
- body: {
94
- bytes: number;
95
- content: string;
96
- };
97
- referrer: string;
98
- url: string;
99
- urlFragment?: string;
100
- method: string;
101
- headers: Protocol.Network.Headers;
102
- postData?: string;
103
- hasPostData?: boolean;
104
- postDataEntries?: Protocol.Network.PostDataEntry[];
105
- mixedContentType?: Protocol.Security.MixedContentType;
106
- initialPriority: Protocol.Network.ResourcePriority;
107
- referrerPolicy: "unsafe-url" | "no-referrer-when-downgrade" | "no-referrer" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin";
108
- isLinkPreload?: boolean;
109
- trustTokenParams?: Protocol.Network.TrustTokenParams;
110
- };
111
- response: {
112
- body: {
113
- bytes: number;
114
- };
115
- status_code: number;
116
- url: string;
117
- status: number;
118
- statusText: string;
119
- headers: Protocol.Network.Headers;
120
- headersText?: string;
121
- mimeType: string;
122
- requestHeaders?: Protocol.Network.Headers;
123
- requestHeadersText?: string;
124
- connectionReused: boolean;
125
- connectionId: number;
126
- remoteIPAddress?: string;
127
- remotePort?: number;
128
- fromDiskCache?: boolean;
129
- fromServiceWorker?: boolean;
130
- fromPrefetchCache?: boolean;
131
- encodedDataLength: number;
132
- timing?: Protocol.Network.ResourceTiming;
133
- serviceWorkerResponseSource?: Protocol.Network.ServiceWorkerResponseSource;
134
- responseTime?: number;
135
- cacheStorageCacheName?: string;
136
- protocol?: string;
137
- securityState: Protocol.Security.SecurityState;
138
- securityDetails?: Protocol.Network.SecurityDetails;
139
- };
84
+ request: import("../common_types").Request;
85
+ response: import("../common_types").Response;
140
86
  };
141
87
  tls: {
142
- cipher: string;
143
88
  server: {
144
89
  x509: {
145
90
  issuer: {
@@ -168,10 +113,16 @@ export declare function getScreenshotBlocks(screenshot: Buffer): Promise<{
168
113
  * at the end of each journey and construct equally sized blocks out
169
114
  * of the individual screenshot image.
170
115
  */
171
- export declare function gatherScreenshots(screenshotsPath: string, callback: (step: Step, data: string) => Promise<void>): Promise<ScreenshotOutput[]>;
116
+ export declare function gatherScreenshots(screenshotsPath: string, callback: (data: Screenshot) => Promise<void>): Promise<void>;
172
117
  export default class JSONReporter extends BaseReporter {
173
- _registerListeners(): void;
174
- writeMetrics(journey: Journey, type: string, events: Array<TraceOutput> | PerfMetrics): void;
118
+ onStart(params: StartEvent): void;
119
+ onJourneyRegister(journey: Journey): void;
120
+ onJourneyStart(journey: Journey, { timestamp, params }: JourneyStartResult): void;
121
+ onStepEnd(journey: Journey, step: Step, { start, end, error, url, status, pagemetrics, traces, metrics, filmstrips, }: StepEndResult): void;
122
+ onJourneyEnd(journey: Journey, { timestamp, start, end, networkinfo, browserconsole, status, error, options, }: JourneyEndResult): Promise<void>;
123
+ onEnd(): void;
124
+ writeScreenshotBlocks(journey: Journey, screenshot: Screenshot): Promise<void>;
125
+ writeMetrics(journey: Journey, step: Step, type: string, events: Array<TraceOutput> | PerfMetrics): void;
175
126
  writeJSON({ _id, journey, type, timestamp, step, root_fields, error, payload, blob, blob_mime, url, }: OutputFields): void;
176
127
  }
177
128
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/reporters/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAMH,OAAO,YAAY,MAAM,QAAQ,CAAC;AASlC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EACL,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAKrC,aAAK,UAAU,GACX,qBAAqB,GACrB,kBAAkB,GAClB,eAAe,GACf,kBAAkB,GAClB,qBAAqB,GACrB,iBAAiB,GACjB,UAAU,GACV,sBAAsB,GACtB,oBAAoB,GACpB,wBAAwB,GACxB,iBAAiB,GACjB,aAAa,CAAC;AAElB,aAAK,OAAO,GAAG;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM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AC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU;IAyBpE,YAAY,CACV,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,WAAW;IAuB1C,SAAS,CAAC,EACR,GAAG,EACH,OAAO,EACP,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,WAAW,EACX,KAAK,EACL,OAAO,EACP,IAAI,EACJ,SAAS,EACT,GAAG,GACJ,EAAE,YAAY;CAgBhB"}
@@ -48,55 +48,12 @@ function getMetadata() {
48
48
  },
49
49
  };
50
50
  }
51
- function formatVersion(protocol) {
52
- if (!protocol) {
53
- return;
54
- }
55
- if (protocol === 'h2') {
56
- return 2;
57
- }
58
- else if (protocol === 'http/1.1') {
59
- return 1.1;
60
- }
61
- else if (protocol === 'http/1.0') {
62
- return 1.0;
63
- }
64
- else if (protocol.startsWith('h3')) {
65
- return 3;
66
- }
67
- }
68
- function formatRequest(request) {
69
- var _a;
70
- const postData = request.postData ? request.postData : '';
71
- return {
72
- ...request,
73
- body: {
74
- bytes: postData.length,
75
- content: postData,
76
- },
77
- referrer: (_a = request.headers) === null || _a === void 0 ? void 0 : _a.Referer,
78
- };
79
- }
80
- function formatResponse(response) {
81
- if (!response) {
82
- return;
83
- }
84
- return {
85
- ...response,
86
- body: {
87
- bytes: response.encodedDataLength,
88
- },
89
- status_code: response.status,
90
- };
91
- }
92
51
  function formatTLS(tls) {
93
- if (!tls) {
52
+ if (!tls || !tls.protocol) {
94
53
  return;
95
54
  }
96
- const cipher = `${tls.keyExchange ? tls.keyExchange + '_' : ''}${tls.cipher}_${tls.keyExchangeGroup}`;
97
55
  const [name, version] = tls.protocol.toLowerCase().split(' ');
98
56
  return {
99
- cipher,
100
57
  server: {
101
58
  x509: {
102
59
  issuer: {
@@ -110,11 +67,10 @@ function formatTLS(tls) {
110
67
  },
111
68
  },
112
69
  version_protocol: name,
113
- version: version,
70
+ version,
114
71
  };
115
72
  }
116
73
  function formatNetworkFields(network) {
117
- var _a;
118
74
  const { request, response, url, browser } = network;
119
75
  const ecs = {
120
76
  // URL would be parsed and mapped by heartbeat
@@ -122,19 +78,16 @@ function formatNetworkFields(network) {
122
78
  user_agent: {
123
79
  name: browser.name,
124
80
  version: browser.version,
125
- original: (_a = request.headers) === null || _a === void 0 ? void 0 : _a['User-Agent'],
81
+ original: request.headers?.['User-Agent'],
126
82
  },
127
83
  http: {
128
- version: formatVersion(response === null || response === void 0 ? void 0 : response.protocol),
129
- request: formatRequest(request),
130
- response: formatResponse(response),
84
+ request,
85
+ response,
131
86
  },
132
- tls: formatTLS(response === null || response === void 0 ? void 0 : response.securityDetails),
87
+ tls: formatTLS(response?.securityDetails),
133
88
  };
134
89
  const pickItems = [
135
90
  'browser',
136
- 'status',
137
- 'method',
138
91
  'type',
139
92
  'isNavigationRequest',
140
93
  'requestSentTime',
@@ -174,7 +127,7 @@ function stepInfo(step, type, status) {
174
127
  };
175
128
  }
176
129
  async function getScreenshotBlocks(screenshot) {
177
- const img = sharp_1.default(screenshot, { sequentialRead: true });
130
+ const img = (0, sharp_1.default)(screenshot, { sequentialRead: true });
178
131
  const { width, height } = await img.metadata();
179
132
  /**
180
133
  * Chop the screenshot image (1280*720) which is the default
@@ -185,8 +138,8 @@ async function getScreenshotBlocks(screenshot) {
185
138
  * optimal for caching in the ES and proved out to be bad, so we stick to 8
186
139
  */
187
140
  const divisions = 8;
188
- const blockWidth = width / divisions;
189
- const blockHeight = height / divisions;
141
+ const blockWidth = Math.floor(width / divisions);
142
+ const blockHeight = Math.floor(height / divisions);
190
143
  const reference = {
191
144
  width,
192
145
  height,
@@ -201,7 +154,7 @@ async function getScreenshotBlocks(screenshot) {
201
154
  .extract({ top, left, width: blockWidth, height: blockHeight })
202
155
  .jpeg()
203
156
  .toBuffer();
204
- const hash = crypto_1.createHash('sha1').update(buf).digest('hex');
157
+ const hash = (0, crypto_1.createHash)('sha1').update(buf).digest('hex');
205
158
  blocks.push({
206
159
  blob: buf.toString('base64'),
207
160
  id: hash,
@@ -230,95 +183,107 @@ exports.getScreenshotBlocks = getScreenshotBlocks;
230
183
  * of the individual screenshot image.
231
184
  */
232
185
  async function gatherScreenshots(screenshotsPath, callback) {
233
- const screenshots = [];
234
- if (helpers_1.isDirectory(screenshotsPath)) {
235
- await helpers_1.totalist(screenshotsPath, async (_, absPath) => {
186
+ if ((0, helpers_1.isDirectory)(screenshotsPath)) {
187
+ await (0, helpers_1.totalist)(screenshotsPath, async (_, absPath) => {
236
188
  try {
237
- const content = fs_1.readFileSync(absPath, 'utf8');
238
- const { step, data } = JSON.parse(content);
239
- await callback(step, data);
189
+ const content = (0, fs_1.readFileSync)(absPath, 'utf8');
190
+ const screenshot = JSON.parse(content);
191
+ await callback(screenshot);
240
192
  }
241
193
  catch (_) {
242
194
  // TODO: capture progarammatic synthetic errors under different type
243
195
  }
244
196
  });
245
197
  }
246
- return screenshots;
247
198
  }
248
199
  exports.gatherScreenshots = gatherScreenshots;
249
200
  class JSONReporter extends base_1.default {
250
- _registerListeners() {
201
+ onStart(params) {
251
202
  /**
252
203
  * report the number of journeys that exists on a suite which
253
204
  * could be used for better sharding
254
205
  */
255
- this.runner.on('start', ({ numJourneys }) => {
256
- this.writeJSON({
257
- type: 'synthetics/metadata',
258
- root_fields: {
259
- num_journeys: numJourneys,
260
- },
261
- });
206
+ this.writeJSON({
207
+ type: 'synthetics/metadata',
208
+ root_fields: {
209
+ num_journeys: params.numJourneys,
210
+ },
211
+ payload: params.networkConditions
212
+ ? {
213
+ network_conditions: params.networkConditions,
214
+ }
215
+ : undefined,
262
216
  });
263
- this.runner.on('journey:register', ({ journey }) => {
264
- this.writeJSON({
265
- type: 'journey/register',
266
- journey,
267
- });
217
+ }
218
+ onJourneyRegister(journey) {
219
+ this.writeJSON({
220
+ type: 'journey/register',
221
+ journey,
268
222
  });
269
- this.runner.on('journey:start', ({ journey, timestamp, params }) => {
270
- this.writeJSON({
271
- type: 'journey/start',
272
- journey,
273
- timestamp,
274
- payload: { params, source: journey.callback.toString() },
275
- });
223
+ }
224
+ onJourneyStart(journey, { timestamp, params }) {
225
+ this.writeJSON({
226
+ type: 'journey/start',
227
+ journey,
228
+ timestamp,
229
+ payload: { params, source: journey.callback.toString() },
276
230
  });
277
- this.runner.on('step:end', ({ journey, step, start, end, error, url, status, metrics }) => {
278
- this.writeJSON({
279
- type: 'step/end',
280
- journey,
281
- step: {
282
- ...step,
283
- duration: {
284
- us: helpers_1.getDurationInUs(end - start),
231
+ }
232
+ onStepEnd(journey, step, { start, end, error, url, status, pagemetrics, traces, metrics, filmstrips, }) {
233
+ this.writeMetrics(journey, step, 'relative_trace', traces);
234
+ this.writeMetrics(journey, step, 'experience', metrics);
235
+ if (filmstrips) {
236
+ // Write each filmstrip separately so that we don't get documents that are too large
237
+ filmstrips.forEach((strip, index) => {
238
+ this.writeJSON({
239
+ type: 'step/filmstrips',
240
+ journey,
241
+ step,
242
+ payload: { index },
243
+ root_fields: {
244
+ browser: { relative_trace: { start: strip.start } },
285
245
  },
246
+ blob: strip.blob,
247
+ blob_mime: strip.mime,
248
+ });
249
+ });
250
+ }
251
+ this.writeJSON({
252
+ type: 'step/end',
253
+ journey,
254
+ step: {
255
+ ...step,
256
+ duration: {
257
+ us: (0, helpers_1.getDurationInUs)(end - start),
286
258
  },
259
+ },
260
+ url,
261
+ error,
262
+ payload: {
263
+ source: step.callback.toString(),
287
264
  url,
288
- error,
289
- payload: {
290
- source: step.callback.toString(),
291
- url,
292
- status,
293
- metrics,
294
- },
295
- });
265
+ status,
266
+ pagemetrics,
267
+ },
296
268
  });
297
- this.runner.on('journey:end', async ({ journey, start, end, filmstrips, networkinfo, browserconsole, traces, metrics, status, error, ssblocks, }) => {
298
- await gatherScreenshots(path_1.join(helpers_1.CACHE_PATH, 'screenshots'), async (step, data) => {
269
+ }
270
+ async onJourneyEnd(journey, { timestamp, start, end, networkinfo, browserconsole, status, error, options, }) {
271
+ const { ssblocks, screenshots } = options;
272
+ const writeScreenshots = screenshots === 'on' ||
273
+ (screenshots === 'only-on-failure' && status === 'failed');
274
+ if (writeScreenshots) {
275
+ await gatherScreenshots((0, path_1.join)(helpers_1.CACHE_PATH, 'screenshots'), async (screenshot) => {
276
+ const { data, timestamp, step } = screenshot;
277
+ if (!data) {
278
+ return;
279
+ }
299
280
  if (ssblocks) {
300
- const { blob_mime, blocks, reference } = await getScreenshotBlocks(Buffer.from(data, 'base64'));
301
- for (let i = 0; i < blocks.length; i++) {
302
- const block = blocks[i];
303
- this.writeJSON({
304
- type: 'screenshot/block',
305
- _id: block.id,
306
- blob: block.blob,
307
- blob_mime,
308
- });
309
- }
310
- this.writeJSON({
311
- type: 'step/screenshot_ref',
312
- journey,
313
- step,
314
- root_fields: {
315
- screenshot_ref: reference,
316
- },
317
- });
281
+ await this.writeScreenshotBlocks(journey, screenshot);
318
282
  }
319
283
  else {
320
284
  this.writeJSON({
321
285
  type: 'step/screenshot',
286
+ timestamp,
322
287
  journey,
323
288
  step,
324
289
  blob: data,
@@ -326,67 +291,80 @@ class JSONReporter extends base_1.default {
326
291
  });
327
292
  }
328
293
  });
329
- if (networkinfo) {
330
- networkinfo.forEach(ni => {
331
- const { ecs, payload } = formatNetworkFields(ni);
332
- this.writeJSON({
333
- type: 'journey/network_info',
334
- journey,
335
- timestamp: ni.timestamp,
336
- root_fields: snakecase_keys_1.default(ecs),
337
- step: ni.step,
338
- payload: snakecase_keys_1.default(payload),
339
- });
340
- });
341
- }
342
- if (filmstrips) {
343
- // Write each filmstrip separately so that we don't get documents that are too large
344
- filmstrips.forEach((strip, index) => {
345
- this.writeJSON({
346
- type: 'journey/filmstrips',
347
- journey,
348
- payload: { index },
349
- root_fields: {
350
- browser: { relative_trace: { start: strip.start } },
351
- },
352
- blob: strip.blob,
353
- blob_mime: strip.mime,
354
- });
294
+ }
295
+ if (networkinfo) {
296
+ networkinfo.forEach(ni => {
297
+ const { ecs, payload } = formatNetworkFields(ni);
298
+ this.writeJSON({
299
+ type: 'journey/network_info',
300
+ journey,
301
+ timestamp: ni.timestamp,
302
+ root_fields: (0, snakecase_keys_1.default)(ecs),
303
+ step: ni.step,
304
+ payload: (0, snakecase_keys_1.default)(payload),
355
305
  });
356
- }
357
- if (browserconsole) {
358
- browserconsole.forEach(({ timestamp, text, type, step }) => {
359
- this.writeJSON({
360
- type: 'journey/browserconsole',
361
- journey,
362
- timestamp,
363
- step,
364
- payload: { text, type },
365
- });
306
+ });
307
+ }
308
+ if (browserconsole) {
309
+ browserconsole.forEach(({ timestamp, text, type, step, error }) => {
310
+ this.writeJSON({
311
+ type: 'journey/browserconsole',
312
+ journey,
313
+ timestamp,
314
+ step,
315
+ error,
316
+ payload: {
317
+ text,
318
+ type,
319
+ },
366
320
  });
367
- }
368
- this.writeMetrics(journey, 'relative_trace', traces);
369
- this.writeMetrics(journey, 'experience', metrics);
321
+ });
322
+ }
323
+ this.writeJSON({
324
+ type: 'journey/end',
325
+ journey,
326
+ timestamp,
327
+ error,
328
+ payload: {
329
+ start,
330
+ end,
331
+ status,
332
+ },
333
+ });
334
+ }
335
+ onEnd() {
336
+ this.stream.flushSync();
337
+ }
338
+ async writeScreenshotBlocks(journey, screenshot) {
339
+ const { blob_mime, blocks, reference } = await getScreenshotBlocks(Buffer.from(screenshot.data, 'base64'));
340
+ for (let i = 0; i < blocks.length; i++) {
341
+ const block = blocks[i];
370
342
  this.writeJSON({
371
- type: 'journey/end',
372
- journey,
373
- error,
374
- payload: {
375
- start,
376
- end,
377
- status,
378
- },
343
+ type: 'screenshot/block',
344
+ timestamp: screenshot.timestamp,
345
+ _id: block.id,
346
+ blob: block.blob,
347
+ blob_mime,
379
348
  });
380
- this.runner.emit('journey:end:reported', {});
349
+ }
350
+ this.writeJSON({
351
+ type: 'step/screenshot_ref',
352
+ timestamp: screenshot.timestamp,
353
+ journey,
354
+ step: screenshot.step,
355
+ root_fields: {
356
+ screenshot_ref: reference,
357
+ },
381
358
  });
382
359
  }
383
- writeMetrics(journey, type, events) {
360
+ writeMetrics(journey, step, type, events) {
384
361
  const metrics = Array.isArray(events) ? events : [events];
385
362
  metrics.forEach(event => {
386
363
  event &&
387
364
  this.writeJSON({
388
- type: 'journey/metrics',
365
+ type: 'step/metrics',
389
366
  journey,
367
+ step,
390
368
  root_fields: {
391
369
  browser: {
392
370
  [type]: event,
@@ -395,7 +373,7 @@ class JSONReporter extends base_1.default {
395
373
  });
396
374
  });
397
375
  }
398
- // Writes a structered synthetics event
376
+ // Writes a structured synthetics event
399
377
  // Note that blob is ultimately stored in ES as a base64 encoded string. You must base 64 encode
400
378
  // it before passing it into this function!
401
379
  // The payload field is an un-indexed field with no ES mapping, so users can put arbitary structured
@@ -404,14 +382,14 @@ class JSONReporter extends base_1.default {
404
382
  this.write({
405
383
  type,
406
384
  _id,
407
- '@timestamp': timestamp || helpers_1.getTimestamp(),
408
- journey: journeyInfo(journey, type, payload === null || payload === void 0 ? void 0 : payload.status),
409
- step: stepInfo(step, type, payload === null || payload === void 0 ? void 0 : payload.status),
385
+ '@timestamp': timestamp || (0, helpers_1.getTimestamp)(),
386
+ journey: journeyInfo(journey, type, payload?.status),
387
+ step: stepInfo(step, type, payload?.status),
410
388
  root_fields: { ...(root_fields || {}), ...getMetadata() },
411
389
  payload,
412
390
  blob,
413
391
  blob_mime,
414
- error: helpers_1.formatError(error),
392
+ error: (0, helpers_1.formatError)(error),
415
393
  url,
416
394
  package_version: version,
417
395
  });