Skip to content

v1.0.0-beta.26

Compare
Choose a tag to compare
@vigneshshanmugam vigneshshanmugam released this 20 May 23:26
· 266 commits to main since this release

Features

Scaffolding a Synthetics project

If you are new to Synthetics and want to quickly get started, you can scaffold the project using init command.

npx @elastic/synthetics init synthetics-project

Running the above command will install the synthetics agent and required dependencies. Will also create Synthetics configuration file and example journey files.

Push command and Monitor management

Manage the monitors in the Kibana monitor management UI (available from Elastic stack >= 8.3.0) using the new push command.

npx @elastic/synthetics push <path/to/journey-dir> --auth <api-key> --url <kibana-url> --project <id|name>

Running the above command will bundle all your local journey files and creates them in Kibana. This allows you to manage all the browser monitors from your local environment. Users can configure most of monitor related fields using the newly provided Monitor DSL.

import { journey, step, monitor, expect } from '@elastic/synthetics';

journey('My Example Journey', ({ page, params }) => {
  /**
   *  Only relevant for the push command to create monitors in Kibana
   */
  monitor.use({
    id: 'example-monitor',
    schedule: 10,
    throttling: {
      download: 10,
      upload: 5,
      latency: 100,
    },
  });
  step('launch application', async () => {
    await page.goto('https://example.com');
  });
});

Custom Reporter API

In addition to the built in reporters like default, json, junit, you can create a custom reporter using the new reporter API.

// reporter.ts
import { Reporter } from '@elastic/synthetics';

export class CustomReporter implements Reporter {
  onStart({ numJourneys }) {
    console.log(`Running ${numJourneys} journeys`);
  }
  onJourneyStart(journey) {
    console.log(`journey:start ${journey.name}`);
  }
  onJourneyEnd(journey) {
    console.log(`journey:end ${journey.name}`);
  }
  onEnd() {
    console.log('done');
  }
}

Now the reporter can be programmatically invoked via the run API

import { run } from '@elastic/synthetics';
import { CustomReporter } from './reporter';

const result = await run({
  reporter: CustomReporter,
});