Skip to content

A set of universal bundler plugins to interact with Datadog directly from your builds.

License

Notifications You must be signed in to change notification settings

DataDog/build-plugins

Repository files navigation

Datadog Build Plugins

A set of plugins to interact with Datadog directly from your builds.

✨ Key takeaways ✨

  • This is a bundler plugin for Webpack Webpack, Vite Vite, ESBuild ESBuild and Rollup Rollup.
  • Very easy to setup and disable on the fly.

Note

If you want to upgrade from v1 to v2, please follow our migration guide.

Table of content

Bundler Plugins

ESBuild ESBuild

@datadog/esbuild-plugin

Installation

  • Yarn
yarn add -D @datadog/esbuild-plugin
  • NPM
npm install --save-dev @datadog/esbuild-plugin

Usage

const { datadogEsbuildPlugin } = require('@datadog/esbuild-plugin');

require('esbuild').build({
    plugins: [
        datadogEsbuildPlugin({
            // Configuration
        }),
    ],
});

Tip

It is important to have the plugin in the first position in order to report every other plugins.

📝 More details ➡️

Rollup Rollup

@datadog/rollup-plugin

Installation

  • Yarn
yarn add -D @datadog/rollup-plugin
  • NPM
npm install --save-dev @datadog/rollup-plugin

Usage

Inside your rollup.config.js.

import { datadogRollupPlugin } from '@datadog/rollup-plugin';

export default {
    plugins: [
        datadogRollupPlugin({
            // Configuration
        }),
    ],
};

Tip

It is important to have the plugin in the first position in order to report every other plugins.

📝 More details ➡️

Vite Vite

@datadog/vite-plugin

Installation

  • Yarn
yarn add -D @datadog/vite-plugin
  • NPM
npm install --save-dev @datadog/vite-plugin

Usage

Inside your vite.config.js.

import { datadogVitePlugin } from '@datadog/vite-plugin';
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
        datadogVitePlugin({
            // Configuration
        }),
    ],
};

Tip

It is important to have the plugin in the first position in order to report every other plugins.

📝 More details ➡️

Webpack Webpack

@datadog/webpack-plugin

Installation

  • Yarn
yarn add -D @datadog/webpack-plugin
  • NPM
npm install --save-dev @datadog/webpack-plugin

Usage

Inside your webpack.config.js.

const { datadogWebpackPlugin } = require('@datadog/webpack-plugin');

module.exports = {
    plugins: [
        datadogWebpackPlugin({
            // Configuration
        }),
    ],
};

Tip

It is important to have the plugin in the first position in order to report every other plugins.

📝 More details ➡️

Features

RUM ESBuild Rollup Vite Webpack

Interact with our Real User Monitoring product (RUM) in Datadog directly from your build system.

datadogWebpackPlugin({
    rum?: {
        disabled?: boolean,
        sourcemaps?: {
            bailOnError?: boolean,
            dryRun?: boolean,
            intakeUrl?: string,
            maxConcurrency?: number,
            minifiedPathPrefix: string,
            releaseVersion: string,
            service: string,
        },
    }
});

📝 Full documentation ➡️

Telemetry ESBuild Rollup Vite Webpack

Display and send telemetry data as metrics to Datadog.

datadogWebpackPlugin({
    telemetry?: {
        disabled?: boolean,
        enableTracing?: boolean,
        endPoint?: string,
        output?: boolean
            | string
            | {
                destination: string,
                timings?: boolean,
                metrics?: boolean,
            },
        prefix?: string,
        tags?: string[],
        timestamp?: number,
        filters?: ((metric: Metric) => Metric | null)[],
    }
});

📝 Full documentation ➡️

Configuration

{
    auth?: {
        apiKey?: string;
    };
    customPlugins?: (options: Options, context: GlobalContext) => UnpluginPlugin[];
    logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
    rum?: {
        disabled?: boolean;
        sourcemaps?: {
            bailOnError?: boolean;
            dryRun?: boolean;
            intakeUrl?: string;
            maxConcurrency?: number;
            minifiedPathPrefix: string;
            releaseVersion: string;
            service: string;
        };
    };
    telemetry?: {
        disabled?: boolean;
        enableTracing?: boolean;
        endPoint?: string;
        output?: boolean
            | string
            | {
                destination: string;
                timings?: boolean;
                metrics?: boolean;
            };
        prefix?: string;
        tags?: string[];
        timestamp?: number;
        filters?: ((metric: Metric) => Metric | null)[];
    }
}

auth.apiKey

default null

In order to interact with Datadog, you have to use your own API Key.

logLevel

default: 'warn'

Which level of log do you want to show.

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.

Or to prototype some new plugins in the same environment.

{
    customPlugins: (options, context) => [{
        name: 'my-custom-plugin',
        buildStart() {
            console.log('Hello world');
        },
    }];
}

Your function will receive two arguments:

  • options: The options you passed to the main plugin (including your custom plugins).
  • context: The global context shared accross our plugin.
type GlobalContext = {
    // Available from the initialization.
    auth?: {
        apiKey?: string;
    };
    // Available from the initialization.
    // More details on the currently running bundler.
    bundler: {
        name: string;
        fullName: string; // Including its variant.
        outDir: string;
        rawConfig?: any;
        variant?: string; // Major version of the bundler (webpack 4, webpack 5)
    };
    // Available from `writeBundle`.
    build: {
        errors: string[];
        warnings: string[];
        entries?: { filepath: string; name: string; size: number; type: string, inputs: Input[], outputs: Output[] }[];
        inputs?: { filepath: string; name: string; size: number; type: string, dependencies: Input[]; dependents: Input[] }[];
        outputs?: { filepath: string; name: string; size: number; type: string, inputs: (Input | Output)[] }[];
        start?: number;
        end?: number;
        duration?: number;
        writeDuration?: number;
    };
    // Available from the initialization.
    cwd: string;
    // Available from `buildStart`.
    git?: {
        hash: string;
        remote: string;
        trackedFilesMatcher: [TrackedFilesMatcher](packages/core/src/plugins/git/trackedFilesMatcher.ts);
    };
    // Available from the initialization.
    start: number;
    // Available from the initialization.
    version: string;
}

Your function will need to return an array of Unplugin Plugins definitions.

Note

Some parts of the context are only available after certain hooks.

Contributing

Check out the CONTRIBUTING.md file for more information.

License

MIT

Back to top ⬆️