Skip to content

Commit 9b18400

Browse files
committed
Add s8s plugin
1 parent 089b972 commit 9b18400

File tree

19 files changed

+242
-0
lines changed

19 files changed

+242
-0
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ packages/plugins/analytics @yoannmoin
2929

3030
# Custom Hooks
3131
packages/plugins/custom-hooks @yoannmoinet
32+
33+
# Synthetics
34+
packages/plugins/synthetics @yoannmoinet @etnbrd

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ To interact with Datadog directly from your builds.
2929
- [`customPlugins`](#customplugins)
3030
- [Features](#features)
3131
- [Error Tracking](#error-tracking-----)
32+
- [Synthetics](#synthetics-----)
3233
- [Telemetry](#telemetry-----)
3334
- [Contributing](#contributing)
3435
- [License](#license)
@@ -103,6 +104,9 @@ Follow the specific documentation for each bundler:
103104
service: string;
104105
};
105106
};
107+
synthetics?: {
108+
disabled?: boolean;
109+
};
106110
telemetry?: {
107111
disabled?: boolean;
108112
enableTracing?: boolean;
@@ -246,6 +250,26 @@ datadogWebpackPlugin({
246250

247251
</details>
248252

253+
### Synthetics <img src="packages/assets/src/esbuild.svg" alt="ESBuild" width="17" /> <img src="packages/assets/src/rollup.svg" alt="Rollup" width="17" /> <img src="packages/assets/src/rspack.svg" alt="Rspack" width="17" /> <img src="packages/assets/src/vite.svg" alt="Vite" width="17" /> <img src="packages/assets/src/webpack.svg" alt="Webpack" width="17" />
254+
255+
> Interact with Synthetics at build time.
256+
257+
#### [📝 Full documentation ➡️](/packages/plugins/synthetics#readme)
258+
259+
<details>
260+
261+
<summary>Configuration</summary>
262+
263+
```typescript
264+
datadogWebpackPlugin({
265+
synthetics?: {
266+
disabled?: boolean,
267+
}
268+
});
269+
```
270+
271+
</details>
272+
249273
### Telemetry <img src="packages/assets/src/esbuild.svg" alt="ESBuild" width="17" /> <img src="packages/assets/src/rollup.svg" alt="Rollup" width="17" /> <img src="packages/assets/src/rspack.svg" alt="Rspack" width="17" /> <img src="packages/assets/src/vite.svg" alt="Vite" width="17" /> <img src="packages/assets/src/webpack.svg" alt="Webpack" width="17" />
250274

251275
> Display and send telemetry data as metrics to Datadog.

global.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ declare global {
1919
* For instance, we only submit logs to Datadog when the environment is `production`.
2020
*/
2121
BUILD_PLUGINS_ENV?: Env;
22+
/**
23+
* Enable the dev server of our synthetics plugin.
24+
*
25+
* This is only used by datadog-ci, that will trigger a build,
26+
* using the customer's build command, which, if it includes our plugin,
27+
* will launch a dev-server over the outdir of the build so datadog-ci
28+
* can trigger a tunnel and a test batch over the branch's code.
29+
*
30+
*/
31+
BUILD_PLUGINS_S8S_LOCAL?: '1';
32+
/**
33+
* The port of the dev server of our synthetics plugin.
34+
*/
35+
BUILD_PLUGINS_S8S_PORT?: string;
2236
/**
2337
* Defined in github actions when running in CI.
2438
*/

packages/core/src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type { ErrorTrackingOptions } from '@dd/error-tracking-plugin/types';
1313
import type * as errorTracking from '@dd/error-tracking-plugin';
1414
import type { RumOptions } from '@dd/rum-plugin/types';
1515
import type * as rum from '@dd/rum-plugin';
16+
import type { SyntheticsOptions } from '@dd/synthetics-plugin/types';
17+
import type * as synthetics from '@dd/synthetics-plugin';
1618
import type { TelemetryOptions } from '@dd/telemetry-plugin/types';
1719
import type * as telemetry from '@dd/telemetry-plugin';
1820
// #imports-injection-marker
@@ -197,6 +199,7 @@ export interface Options extends BaseOptions {
197199
// #types-injection-marker
198200
[errorTracking.CONFIG_KEY]?: ErrorTrackingOptions;
199201
[rum.CONFIG_KEY]?: RumOptions;
202+
[synthetics.CONFIG_KEY]?: SyntheticsOptions;
200203
[telemetry.CONFIG_KEY]?: TelemetryOptions;
201204
// #types-injection-marker
202205
customPlugins?: GetCustomPlugins;

packages/factory/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@dd/internal-git-plugin": "workspace:*",
2626
"@dd/internal-injection-plugin": "workspace:*",
2727
"@dd/rum-plugin": "workspace:*",
28+
"@dd/synthetics-plugin": "workspace:*",
2829
"@dd/telemetry-plugin": "workspace:*",
2930
"chalk": "2.3.1",
3031
"unplugin": "1.16.0"

packages/factory/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { getContext, validateOptions } from './helpers';
2828
// #imports-injection-marker
2929
import * as errorTracking from '@dd/error-tracking-plugin';
3030
import * as rum from '@dd/rum-plugin';
31+
import * as synthetics from '@dd/synthetics-plugin';
3132
import * as telemetry from '@dd/telemetry-plugin';
3233
import { getAnalyticsPlugins } from '@dd/internal-analytics-plugin';
3334
import { getBuildReportPlugins } from '@dd/internal-build-report-plugin';
@@ -39,6 +40,7 @@ import { getInjectionPlugins } from '@dd/internal-injection-plugin';
3940
// #types-export-injection-marker
4041
export type { types as ErrorTrackingTypes } from '@dd/error-tracking-plugin';
4142
export type { types as RumTypes } from '@dd/rum-plugin';
43+
export type { types as SyntheticsTypes } from '@dd/synthetics-plugin';
4244
export type { types as TelemetryTypes } from '@dd/telemetry-plugin';
4345
// #types-export-injection-marker
4446

@@ -102,6 +104,7 @@ export const buildPluginFactory = ({
102104
// #configs-injection-marker
103105
errorTracking,
104106
rum,
107+
synthetics,
105108
telemetry,
106109
// #configs-injection-marker
107110
];

packages/plugins/synthetics/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Synthetics Plugin <!-- #omit in toc -->
2+
3+
Interact with Synthetics at build time.
4+
5+
<!-- The title and the following line will both be added to the root README.md -->
6+
7+
## Table of content <!-- #omit in toc -->
8+
9+
<!-- This is auto generated with yarn cli integrity -->
10+
11+
<!-- #toc -->
12+
- [Configuration](#configuration)
13+
<!-- #toc -->
14+
15+
## Configuration
16+
17+
```ts
18+
synthetics?: {
19+
disabled?: boolean;
20+
}
21+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@dd/synthetics-plugin",
3+
"packageManager": "yarn@4.0.2",
4+
"license": "MIT",
5+
"private": true,
6+
"author": "Datadog",
7+
"description": "Interact with Synthetics at build time.",
8+
"homepage": "https://github.com/DataDog/build-plugins/tree/main/packages/plugins/synthetics#readme",
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/DataDog/build-plugins",
12+
"directory": "packages/plugins/synthetics"
13+
},
14+
"exports": {
15+
".": "./src/index.ts",
16+
"./*": "./src/*.ts"
17+
},
18+
"scripts": {
19+
"typecheck": "tsc --noEmit"
20+
},
21+
"dependencies": {
22+
"@dd/core": "workspace:*",
23+
"chalk": "2.3.1"
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
import type { PluginName } from '@dd/core/types';
6+
7+
export const CONFIG_KEY = 'synthetics' as const;
8+
export const PLUGIN_NAME: PluginName = 'datadog-synthetics-plugin' as const;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
import { getPlugins } from '@dd/synthetics-plugin';
6+
import { getContextMock } from '@dd/tests/_jest/helpers/mocks';
7+
import { runBundlers } from '@dd/tests/_jest/helpers/runBundlers';
8+
9+
describe('Synthetics Plugin', () => {
10+
describe('getPlugins', () => {
11+
test('Should not initialize the plugin if disabled', async () => {
12+
expect(getPlugins({ synthetics: { disabled: true } }, getContextMock())).toHaveLength(
13+
0,
14+
);
15+
});
16+
17+
test('Should initialize the plugin if enabled and not configured', async () => {
18+
expect(
19+
getPlugins({ synthetics: { disabled: false } }, getContextMock()).length,
20+
).toBeGreaterThan(0);
21+
expect(getPlugins({}, getContextMock()).length).toBeGreaterThan(0);
22+
});
23+
});
24+
25+
test('Should run the server at the end of the build.', async () => {
26+
await runBundlers({
27+
logLevel: 'debug',
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)