Image from https://dogtrekker.com
An example of a scheduled GitLab job running Lighthouse audits and posting results as custom DataDog metrics.
A GitLab job audits a set of URLs at a time - a "project". Each URL is mapped to DataDog custom metric namespace and can be assigned a custom Lighthouse configuration.
- Lighthouse metrics reported to DataDog
- Configuring a project to audit
- Running Lighthouse with custom config
- DataDog metrics naming
Scores:
- Performance
- Accessibility
- SEO
- Best practices
- PWA
Other metric values:
- First contentful paint
- Speed index
- Largest contentful paint
- Time to interactive
- Total blocking time
- Cumulative layout shift
- Server response time
Custom values:
- Total bundle size - a total size of all javascript downloaded by the browser (sent as a
total_bundle_size
DataDog metric)
An object in src/config/metric-map.ts maps Lighthouse report scores to the DataDog-compatible metric names.
- Create a project file in the src/config/projects directory specifying the array of URLs to test and corresponding metric namespaces you would like to use in DataDog. See example here. Add your project to src/config/projects/index.ts
- In GitLab create a new Scheduled Job, providing your project handle via
AUDITED_PROJECT
environment variable
It is possible to run Lighthouse with a custom configuration, that lets you fine-tune the run (e.g. block certain scripts). To do so:
-
Add your custom Lighthouse config as a
*.config.ts
file in the src/config/custom-lighthouse-configs folder.export default { name: 'My custom config', extends: 'lighthouse:default', settings: { // custom settings } };
-
In your project configuration provide the custom config via a
customLighthouseConfig
property.import myCustomConfig from '../custom-lighthouse-configs/my-custom-config'; export default [ { url: 'https://url1', metricNamespace: 'abc' customLighthouseConfig: myCustomConfig } ];
Metrics sent will be following this naming convention:
lighthouse.[metric-name].[metric-namespace]
Where
- [metric-name] is one of the metric names, see Lighthouse metrics reported to DataDog section below
- [metric-namespace] is a
metricNamespace
from your project config in src/config/projects
NOTE: DataDog metric names and namespaces must follow DataDog naming convention.