Monitor.fields ignored for browser monitors and monitor.tags are not merged

Hello,

I try to add labels to my monitors using the project setting monitor.fields in synthetics.config.ts file.
When i push all my monitors, labels are added only to lightweight monitors.

Let's check my setup below.

An other question about tags. I would like to create tags at project level to apply to all my monitors but i need also to add specific tags for each monitor.
Finally after pushing journeys with Elastic CLI i realise list of tags added inside each monitor fully overwrite tags declared at project level in synthetics.config.ts file.

Here is my setup :
synthetics.config.ts

import type { SyntheticsConfig } from '@elastic/synthetics';

export default env => {
  const config: SyntheticsConfig = {
    params: {
      url: 'https://www.elastic.co',
    },
    playwrightOptions: {
      ignoreHTTPSErrors: false,
      locale: 'fr-FR'
    },
    /**
     * Configure global monitor settings
     */
    monitor: {
      schedule: 20,
      locations: [],
      privateLocations: ['synthetics-agent-demo'],
      tags: [ 'demo1', 'demo2' ],
      fields: { 'label1' : 'value1' },
    },
    /**
     * Project monitors settings
     */
    project: {
      id: 'my_awesome_project-new',
      url: 'http://kibana-demo/',
      space: 'default',
    },
  };
  if (env !== 'development') {
    /**
     * Override configuration specific to environment
     * For example, config.params.url = ""
     */
  }
  return config;
};

And the related journey:

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

journey('Monitor demo', ({ page, params }) => {
  monitor.use({
    id: 'demo-journey',
    tags: ["prd"],
  });
  step('Step 1 - Monitor sample - Load the demo page', async () => {
    await page.goto(params.url);
  });
});

Using this setup

  • i get only one tag in this case "prd" (same for browser or lightweight monitors)
  • i don't get any fields/labels (only for browser monitor)

How to make fields/labels work with browser monitor ?
Is there any way to merge tags from project and journey ?

Thank you :slight_smile:

Note that labels/fields are working for browser monitor only when defined inside journey directly like this :

  monitor.use({
    id: 'demo-journey',
    schedule: 10,
    locations: [],
    fields: { 'label1' : 'value1'},
  });

By the way I need to add the same label to all my journeys; so as describe in documentation I prefer to add it at project level :slight_smile:

thank you for reporting, we are fixing it fix: fix fields bugs for browser monitors for global config !! by shahzad31 · Pull Request #1000 · elastic/synthetics · GitHub

1 Like

Thanks for the quick fix !
One last question, is there any way to merge tags from project and journey settings ?

@barcus i think tags question is more of a way how we handle monitor config, i mean it is usually meant as an override over global config.

Though one can argue that tags should be bit different, global tags should be mixed with local monitor config tags.

Though that might not be true for other data let's locations, if you only want to run some specific monitor from a one particular location, in that case it make sense to have monitor config act as an override.

I am interested to hear if you have any thoughts. I will probably create an issue/PR and see what my team thinks.

A workaround would be use a shared variable or something like this


 monitor.use({
    id: 'example-monitor',
    schedule: 10,
    tags: [...(syntheticsConfig("").monitor?.tags || []) , "test-tag-2"]
  });

The main idea was to not duplicate tags inside each journey while keeping specific tags

Do i need to import/load something to make this workaround works ?

I do it using a new const finally

in synthetics.config.ts :

export const monitorTags = ['global-tag1'];

and I use it inside project settings:

    monitor: {
      schedule: 20,
      privateLocations: ['synthetics-agent-demo'],
      tags: monitorTags,
      fields: { 'label1' : 'value1' },
    },

and in my journey:

import { monitorTags } from '../synthetics.config.ts';
  monitor.use({
    id: 'demo-journey',
    tags: [...monitorTags , "local-tag1"],
  });