Skip to content

Commit 69185c1

Browse files
committed
onweek commit, please do not remove
1 parent cbf4c4e commit 69185c1

File tree

7 files changed

+69
-5
lines changed

7 files changed

+69
-5
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"enquirer": "^2.3.6",
4747
"esbuild": "^0.16.10",
4848
"expect": "^28.1.3",
49+
"glob-to-regexp": "^0.4.1",
4950
"http-proxy": "^1.18.1",
5051
"kleur": "^4.1.5",
5152
"micromatch": "^4.0.5",

src/cli.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ program
123123
{}
124124
)
125125
.option('--no-throttling', 'Turns off default network throttling.')
126+
.option(
127+
'--trace-url-patterns <strings delimited by ,>',
128+
'each of these strings correspond to url patterns that will receive the baggage header containing monitorid and checkgroup'
129+
)
126130
.addOption(playwrightOpts)
127131
.version(version)
128132
.description('Run synthetic tests')

src/common_types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export type CliArgs = BaseArgs & {
225225
sandbox?: boolean;
226226
richEvents?: boolean;
227227
capability?: Array<string>;
228+
traceUrlPatterns?: string;
228229
ignoreHttpsErrors?: boolean;
229230
};
230231

@@ -238,6 +239,9 @@ export type RunOptions = BaseArgs & {
238239
playwrightOptions?: PlaywrightOptions;
239240
networkConditions?: NetworkConditions;
240241
reporter?: BuiltInReporterName | ReporterInstance;
242+
apm?: ApmOptions;
243+
monitorId?: string;
244+
checkgroup?: string;
241245
};
242246

243247
export type PushOptions = Partial<ProjectSettings> & {
@@ -254,12 +258,17 @@ export type ProjectSettings = {
254258
space: string;
255259
};
256260

261+
export type ApmOptions = {
262+
traceUrlPatterns: Array<string | RegExp>;
263+
};
264+
257265
export type PlaywrightOptions = LaunchOptions & BrowserContextOptions;
258266
export type SyntheticsConfig = {
259267
params?: Params;
260268
playwrightOptions?: PlaywrightOptions;
261269
monitor?: MonitorConfig;
262270
project?: ProjectSettings;
271+
apm?: ApmOptions;
263272
};
264273

265274
/** Runner Payload types */

src/core/gatherer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,13 @@ export class Gatherer {
109109
*/
110110
static async beginRecording(driver: Driver, options: RunOptions) {
111111
log('Gatherer: started recording');
112-
const { network, metrics } = options;
112+
const { network, metrics, apm } = options;
113113
const pluginManager = new PluginManager(driver);
114114
pluginManager.registerAll(options);
115115
const plugins = [await pluginManager.start('browserconsole')];
116116
network && plugins.push(await pluginManager.start('network'));
117117
metrics && plugins.push(await pluginManager.start('performance'));
118+
apm && plugins.push(await pluginManager.start('apm'));
118119
await Promise.all(plugins);
119120
return pluginManager;
120121
}

src/options.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import merge from 'deepmerge';
2727
import { createOption } from 'commander';
2828
import { readConfig } from './config';
29+
import globToRegExp from 'glob-to-regexp';
2930
import { getNetworkConditions, DEFAULT_THROTTLING_OPTIONS } from './helpers';
3031
import type { CliArgs, RunOptions, ThrottlingOptions } from './common_types';
3132

@@ -42,7 +43,10 @@ export function normalizeOptions(cliArgs: CliArgs): RunOptions {
4243
const options: RunOptions = {
4344
...cliArgs,
4445
environment: process.env['NODE_ENV'] || 'development',
46+
monitorId: process.env['MONITOR_ID'],
47+
checkgroup: process.env['CHECKGROUP'],
4548
};
49+
4650
/**
4751
* Group all events that can be consumed by heartbeat and
4852
* eventually by the Synthetics UI.
@@ -55,6 +59,16 @@ export function normalizeOptions(cliArgs: CliArgs): RunOptions {
5559
options.quietExitCode = true;
5660
}
5761

62+
if (cliArgs.traceUrlPatterns) {
63+
const urlPatterns = cliArgs.traceUrlPatterns.split(',').map(pattern => {
64+
return globToRegExp(pattern);
65+
});
66+
67+
options.apm = {
68+
traceUrlPatterns: urlPatterns,
69+
};
70+
}
71+
5872
if (cliArgs.capability) {
5973
const supportedCapabilities = [
6074
'trace',

src/plugins/plugin-manager.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
*/
2525

26-
import { PluginOutput, Driver } from '../common_types';
26+
import { PluginOutput, Driver, RunOptions } from '../common_types';
2727
import {
2828
BrowserConsole,
2929
NetworkManager,
@@ -32,10 +32,25 @@ import {
3232
TraceOptions,
3333
} from './';
3434
import { Step } from '../dsl';
35+
import { Apm } from './apm';
3536

36-
type PluginType = 'network' | 'trace' | 'performance' | 'browserconsole';
37-
type Plugin = NetworkManager | Tracing | PerformanceManager | BrowserConsole;
38-
type PluginOptions = TraceOptions;
37+
type PluginType =
38+
| 'network'
39+
| 'trace'
40+
| 'performance'
41+
| 'browserconsole'
42+
| 'apm';
43+
type Plugin =
44+
| NetworkManager
45+
| Tracing
46+
| PerformanceManager
47+
| BrowserConsole
48+
| Apm;
49+
type PluginOptions = TraceOptions & {
50+
apm?: RunOptions['apm'];
51+
monitorId?: RunOptions['monitorId'];
52+
checkgroup?: RunOptions['checkgroup'];
53+
};
3954

4055
export class PluginManager {
4156
protected plugins = new Map<PluginType, Plugin>();
@@ -44,6 +59,7 @@ export class PluginManager {
4459
'trace',
4560
'performance',
4661
'browserconsole',
62+
'apm',
4763
];
4864
constructor(private driver: Driver) {}
4965

@@ -62,6 +78,14 @@ export class PluginManager {
6278
case 'browserconsole':
6379
instance = new BrowserConsole(this.driver);
6480
break;
81+
case 'apm':
82+
instance = new Apm(
83+
this.driver,
84+
options.apm,
85+
options.monitorId,
86+
options.checkgroup
87+
);
88+
break;
6589
}
6690
instance && this.plugins.set(type, instance);
6791
return instance;

0 commit comments

Comments
 (0)