DataDog/build-plugins
A set of universal bundler plugins to interact with Datadog directly from your builds.
Datadog Build Plugins
A set of bundler plugins for:
esbuild
@datadog/esbuild-pluginRollup
@datadog/rollup-pluginRspack
@datadog/rspack-pluginVite
@datadog/vite-pluginWebpack
@datadog/webpack-plugin
To interact with Datadog directly from your builds.
Table of content
Installation
- Yarn
yarn add -D @datadog/{{bundler}}-plugin- npm
npm install --save-dev @datadog/{{bundler}}-pluginUsage
In your bundler's configuration file:
const { datadog{{Bundler}}Plugin } = require('@datadog/{{bundler}}-plugin');
export const config = {
plugins: [
datadog{{Bundler}}Plugin({
// Configuration
}),
],
};Tip
It is best to have the plugin in the first position in order to report every other plugins.
Follow the specific documentation for each bundler:
esbuild
@datadog/esbuild-pluginRollup
@datadog/rollup-pluginRspack
@datadog/rspack-pluginVite
@datadog/vite-pluginWebpack
@datadog/webpack-plugin
Configuration
Full configuration object
{
auth?: {
apiKey?: string;
appKey?: string;
site?: string;
};
customPlugins?: (arg: GetPluginsArg) => UnpluginPlugin[];
enableGit?: boolean;
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none',
metadata?: {
name?: string;
};
errorTracking?: {
enable?: boolean;
sourcemaps?: {
bailOnError?: boolean;
dryRun?: boolean;
maxConcurrency?: number;
minifiedPathPrefix: string;
releaseVersion: string;
service: string;
};
};
metrics?: {
enable?: boolean;
enableDefaultPrefix?: boolean;
enableTracing?: boolean;
prefix?: string;
tags?: string[];
timestamp?: number;
filters?: ((metric: Metric) => Metric | null)[];
};
output?: {
enable?: boolean;
path?: string;
files?: {
build?: boolean | string;
bundler?: boolean | string;
dependencies?: boolean | string;
errors?: boolean | string;
logs?: boolean | string;
metrics?: boolean | string;
timings?: boolean | string;
warnings?: boolean | string;
};
};
}auth.apiKey
default
null
In order to interact with Datadog, you have to use your own API Key.
auth.appKey
default
null
In order to interact with Datadog, you have to use your own Application Key.
auth.site
default
'datadoghq.com'
The Datadog site to use APIs from.
Possible values are 'datadoghq.com', 'datadoghq.eu', 'us3.datadoghq.com', 'us5.datadoghq.com', 'ap1.datadoghq.com', etc.
This configuration controls which Datadog site telemetry metrics and error tracking sourcemaps are sent to.
Note
The DATADOG_SITE environment variable takes priority over this configuration.
The order of precedence is:
DATADOG_SITEorDD_SITEenvironment variable (highest priority)auth.siteconfiguration'datadoghq.com'(default)
customPlugins
default:
[]
This is a way for you to inject any Unplugin Plugin you want.
It's particularly useful to use our global, shared context of the main plugin.
And to prototype some new plugins in the same environment.
{
customPlugins: ({ options, context }) => {
const name = 'my-custom-plugin';
const log = context.getLogger(name);
return [{
name,
buildStart() {
log.info('Hello world');
},
}]
};
}Your function will receive three arguments:
options: The options you passed to the main plugin (including your custom plugins).context: The global context shared accross our plugin.bundler: The currently running bundler's instance.
The context is a shared object that is mutated during the build process.
Your function has to return an array of Unplugin Plugins definitions.
You can also use our own custom hooks.
Full context object
type GlobalContext = {
// Trigger an asynchronous custom hook.
asyncHook: async (name: string, ...args: any[]) => Promise;
// Mirror of the user's config.
auth?: {
apiKey?: string;
appKey?: string;
};
// Available in the `buildReport` hook.
build: BuildReport;
// Available in the `bundlerReport` hook.
bundler: BundlerReport;
buildRoot: string;
env: string;
getLogger: (name: string) => Logger;
// Available in the `git` hook.
git?: Git;
// Trigger a synchronous custom hook.
hook: (name: string, ...args: any[]) => void;
inject: Injection;
// The list of all the plugin names that are currently running in the ecosystem.
pluginNames: string[];
// The list of all the plugin instances that are currently running in the ecosystem.
plugins: Plugin[];
// Send a log to Datadog.
sendLog: ({ message: string, context?: Record }) => Promise;
// The start time of the build.
start: number;
// The version of the plugin.
version: string;
}
📝 Full documentation ➡️
enableGit
default:
true
Enable the Git plugin to use git information in your build.
Set to false if you don't want to use it, for instance if you see a Error: No git remotes available error.
logLevel
default:
'warn'
Which level of log do you want to show.
metadata.name
default:
null
The name of the build.
This is used to identify the build in logs, metrics and spans.
Features
Error Tracking

Interact with Error Tracking directly from your build system.
📝 Full documentation ➡️
Configuration
datadogWebpackPlugin({
errorTracking?: {
enable?: boolean,
sourcemaps?: {
bailOnError?: boolean,
dryRun?: boolean,
maxConcurrency?: number,
minifiedPathPrefix: string,
releaseVersion: string,
service: string,
},
}
});Metrics

Display and send metrics to Datadog.
📝 Full documentation ➡️
Configuration
datadogWebpackPlugin({
metrics?: {
enable?: boolean,
enableDefaultPrefix?: boolean,
enableTracing?: boolean,
prefix?: string,
tags?: string[],
timestamp?: number,
filters?: ((metric: Metric) => Metric | null)[],
}
});Output

Export build reports, metrics, and bundler data to JSON files for analysis and monitoring.
📝 Full documentation ➡️
Configuration
datadogWebpackPlugin({
output?: {
enable?: boolean,
path?: string,
files?: {
build?: boolean | string,
bundler?: boolean | string,
dependencies?: boolean | string,
errors?: boolean | string,
logs?: boolean | string,
metrics?: boolean | string,
timings?: boolean | string,
warnings?: boolean | string,
},
}
});Contributing
Check out CONTRIBUTING.md for more information about how to work with the build-plugins ecosystem.