Skip to content

Commit

Permalink
Merge pull request #93 from DataDog/yoann/refactor-telemetry-with-bui…
Browse files Browse the repository at this point in the history
…ld-report

[Telemetry] Refactor telemetry with build report
  • Loading branch information
yoannmoinet authored Sep 18, 2024
2 parents 6cdd799 + 878468d commit ff1b213
Show file tree
Hide file tree
Showing 38 changed files with 1,168 additions and 2,099 deletions.
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ A set of plugins to interact with Datadog directly from your builds.
- [Webpack](#-webpack)
- [Features](#features)
- [RUM](#rum----)
- [Telemetry](#telemetry--)
- [Telemetry](#telemetry----)
- [Configuration](#configuration)
- [`auth.apiKey`](#authapikey)
- [`auth.endPoint`](#authendpoint)
- [`logLevel`](#loglevel)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -216,23 +215,22 @@ datadogWebpackPlugin({
<kbd>[📝 Full documentation ➡️](./packages/plugins/rum#readme)</kbd>
### Telemetry <img src="packages/assets/src/esbuild.svg" alt="ESBuild" width="17" /> <img src="packages/assets/src/webpack.svg" alt="Webpack" width="17" />
### 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/vite.svg" alt="Vite" width="17" /> <img src="packages/assets/src/webpack.svg" alt="Webpack" width="17" />
> Display and send telemetry data as metrics to Datadog.
```typescript
datadogWebpackPlugin({
telemetry?: {
disabled?: boolean,
enableTracing?: boolean,
endPoint?: string,
output?: boolean
| string
| {
destination: string,
timings?: boolean,
dependencies?: boolean,
bundler?: boolean,
metrics?: boolean,
logs?: boolean,
},
prefix?: string,
tags?: string[],
Expand Down Expand Up @@ -268,15 +266,14 @@ datadogWebpackPlugin({
};
telemetry?: {
disabled?: boolean;
enableTracing?: boolean;
endPoint?: string;
output?: boolean
| string
| {
destination: string;
timings?: boolean;
dependencies?: boolean;
bundler?: boolean;
metrics?: boolean;
logs?: boolean;
};
prefix?: string;
tags?: string[];
Expand All @@ -293,12 +290,6 @@ datadogWebpackPlugin({
In order to interact with Datadog, you have to use [your own API Key](https://app.datadoghq.com/organization-settings/api-keys).
### `auth.endPoint`
> default: `"app.datadoghq.com"`
To which endpoint will the metrics be sent.
### `logLevel`
> default: `'warn'`
Expand Down
7 changes: 6 additions & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
// Copyright 2019-Present Datadog, Inc.

module.exports = {
'*.{ts,tsx}': () => ['yarn typecheck:all', 'yarn format', 'git add'],
'*.{ts,tsx}': (filenames) => [
'yarn typecheck:all',
`eslint ${filenames.join(' ')} --quiet --fix`,
'git add',
],
'*.{js,mjs}': (filenames) => [`eslint ${filenames.join(' ')} --quiet --fix`, 'git add'],
relative: 'true',
};
3 changes: 1 addition & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { UnpluginContextMeta, UnpluginOptions } from 'unplugin';

import type { TrackedFilesMatcher } from './plugins/git/trackedFilesMatcher';

type Assign<A, B> = Omit<A, keyof B> & B;
export type Assign<A, B> = Omit<A, keyof B> & B;

export interface RepositoryData {
hash: string;
Expand Down Expand Up @@ -88,7 +88,6 @@ export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';

export type AuthOptions = {
apiKey?: string;
endPoint?: string;
};

export interface GetPluginsOptions {
Expand Down
107 changes: 63 additions & 44 deletions packages/plugins/telemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Display and send telemetry data as metrics to Datadog.
<!-- #toc -->
- [Configuration](#configuration)
- [`disabled`](#disabled)
- [`enableTracing`](#enabletracing)
- [`endPoint`](#endpoint)
- [`output`](#output)
- [`prefix`](#prefix)
- [`tags`](#tags)
Expand All @@ -29,15 +31,14 @@ Display and send telemetry data as metrics to Datadog.
```ts
telemetry?: {
disabled?: boolean;
enableTracing?: boolean;
endPoint?: string;
output?: boolean
| string
| {
destination: string;
timings?: boolean;
dependencies?: boolean;
bundler?: boolean;
metrics?: boolean;
logs?: boolean;
};
prefix?: string;
tags?: string[];
Expand All @@ -52,30 +53,46 @@ telemetry?: {
Plugin will be disabled and won't track anything.

### `enableTracing`

> default: `false`
> [!NOTE]
> This option is **deprecated** and will most likely be removed in the future.
If `true`, it will add tracing data to the metrics.

But it is way more time consuming on the build.

And only supports <img src="packages/assets/src/webpack.svg" alt="Webpack" width="17" /> Webpack and <img src="packages/assets/src/esbuild.svg" alt="Esbuild" width="17" /> Esbuild (for now).

### `endPoint`

> default: `"app.datadoghq.com"`
To which endpoint will the metrics be sent.

### `output`

> default: `true`
If `true`, you'll get all outputs in the logs and the creation of the json files.
If a path, you'll also save json files at this location:

- `dependencies.json`: track all dependencies and dependents of your modules.
If `true`, you'll get the creation of both json files:
- `metrics.json`: an array of all the metrics that would be sent to Datadog.
- `bundler.json`: some 'stats' from your bundler.
- `timings.json`: timing data for modules, loaders and plugins.

If a path, it will save the files at this location.

You can also pass an object of the form:

```javascript
{
destination: 'path/to/destination',
timings: true,
// This will only output the metrics file and nothing in the logs.
logs: false,
metrics: false,
}
```

To only output a specified file.
To only output a specific file.

### `prefix`

Expand All @@ -97,7 +114,7 @@ Which timestamp to use when submitting your metrics.

### `filters`

> default: [`[ filterTreeMetrics, filterSourcemapsAndNodeModules, filterMetricsOnThreshold ]`](../../core/src/helpers.ts)
> default: [`[ filterTreeMetrics, filterSourcemapsAndNodeModules, filterMetricsOnThreshold ]`](packages/telemetry/src/common/filters.ts)
You can add as many filters as you want. They are just functions getting the `metric` as an argument.

Expand Down Expand Up @@ -157,38 +174,40 @@ datadogWebpackPlugin({
## Metrics

> [!CAUTION]
> Please note that this plugin can generate a lot of metrics, you can greatly reduce their number by tweaking the [`datadog.filters`](./#datadogfilters).
Here's the list of metrics and their corresponding tags:

| Metric | Tags | Type | Description |
| :---------------------------------- | :----------------------------------------- | :----------- | :----------------------------------------------------- |
| `${prefix}.assets.count` | `[]` | count | Number of assets. |
| `${prefix}.assets.size` | `[assetName:${name}, assetType:${type}]` | bytes | Size of an asset file. |
| `${prefix}.chunks.count` | `[]` | count | Number of chunks. |
| `${prefix}.chunks.modules.count` | `[chunkName:${name}]` | count | Number of modules in a chunk. |
| `${prefix}.chunks.size` | `[chunkName:${name}]` | bytes | Size of a chunk. |
| `${prefix}.compilation.duration` | `[]` | milliseconds | Duration of the build. |
| `${prefix}.entries.assets.count` | `[entryName:${name}]` | count | Number of assets from an entry. |
| `${prefix}.entries.chunks.count` | `[entryName:${name}]` | count | Number of chunks from an entry. |
| `${prefix}.entries.count` | `[]` | count | Number of entries. |
| `${prefix}.entries.modules.count` | `[entryName:${name}]` | count | Number of modules from an entry. |
| `${prefix}.entries.size` | `[entryName:${name}]` | bytes | Size of an entry file. |
| `${prefix}.errors.count` | `[]` | count | Number of errors generated by the build. |
| `${prefix}.loaders.count` | `[]` | count | Number of loaders. |
| `${prefix}.loaders.duration` | `[loaderName:${name}]` | milliseconds | Runtime duration of a loader. |
| `${prefix}.loaders.increment` | `[loaderName:${name}]` | count | Number of hit a loader had. |
| `${prefix}.modules.count` | `[]` | count | Number of modules. |
| `${prefix}.modules.dependencies` | `[moduleName:${name}, moduleType:${type}]` | count | Number of dependencies a module has. |
| `${prefix}.modules.dependents` | `[moduleName:${name}, moduleType:${type}]` | count | Number of dependents a module has. |
| `${prefix}.modules.size` | `[moduleName:${name}, moduleType:${type}]` | bytes | Size of a module. |
| `${prefix}.plugins.count` | `[]` | count | Number of plugins. |
| `${prefix}.plugins.duration` | `[pluginName:${name}]` | milliseconds | Total runtime duration of a plugin. |
| `${prefix}.plugins.hooks.duration` | `[pluginName:${name}, hookName:${name}]` | milliseconds | Runtime duration of a hook. |
| `${prefix}.plugins.hooks.increment` | `[pluginName:${name}, hookName:${name}]` | count | Number of hit a hook had. |
| `${prefix}.plugins.increment` | `[pluginName:${name}]` | count | Number of hit a plugin had. |
| `${prefix}.plugins.meta.duration` | `[pluginName:datadogwebpackplugin]` | milliseconds | Duration of the process of the Webpack Datadog plugin. |
| `${prefix}.warnings.count` | `[]` | count | Number of warnings generated by the build. |
> Please note that this plugin can generate a lot of metrics, you can greatly reduce their number by tweaking the [`datadog.filters`](./#filters).
Here's the list of the metrics that are computed by default:

| Metric | Tags | Type | Description |
| :---------------------------------- | :------------------------------------------------------------ | :----------- | :----------------------------------------------------- |
| `${prefix}.assets.count` | `[]` | count | Number of assets. |
| `${prefix}.assets.size` | `[assetName:${name}, assetType:${type}, entryName:${name}]` | bytes | Size of an asset file. |
| `${prefix}.assets.modules.count` | `[assetName:${name}, assetType:${type}, entryName:${name}]` | count | Number of modules in a chunk. |
| `${prefix}.compilation.duration` | `[]` | milliseconds | Duration of the build. |
| `${prefix}.entries.assets.count` | `[entryName:${name}]` | count | Number of assets from an entry. |
| `${prefix}.entries.count` | `[]` | count | Number of entries. |
| `${prefix}.entries.modules.count` | `[entryName:${name}]` | count | Number of modules from an entry. |
| `${prefix}.entries.size` | `[entryName:${name}]` | bytes | Total size of an entry (and all its assets). |
| `${prefix}.errors.count` | `[]` | count | Number of errors generated by the build. |
| `${prefix}.modules.count` | `[]` | count | Number of modules. |
| `${prefix}.modules.dependencies` | `[moduleName:${name}, moduleType:${type}, assetName:${name}, entryName:${name}]` | count | Number of dependencies a module has. |
| `${prefix}.modules.dependents` | `[moduleName:${name}, moduleType:${type}, assetName:${name}, entryName:${name}]` | count | Number of dependents a module has. |
| `${prefix}.modules.size` | `[moduleName:${name}, moduleType:${type}, assetName:${name}, entryName:${name}]` | bytes | Size of a module. |
| `${prefix}.plugins.meta.duration` | `[pluginName:datadogwebpackplugin]` | milliseconds | Duration of the process of the Webpack Datadog plugin. |
| `${prefix}.warnings.count` | `[]` | count | Number of warnings generated by the build. |

We also have some metrics that are only available to `esbuild` and `webpack` when the [`enableTracing`](#enableTracing) option is set to `true`:

| Metric | Tags | Type | Description |
| :---------------------------------- | :--------------------------------------- | :----------- | :---------------------------------- |
| `${prefix}.loaders.count` | `[]` | count | Number of loaders. |
| `${prefix}.loaders.duration` | `[loaderName:${name}]` | milliseconds | Runtime duration of a loader. |
| `${prefix}.loaders.increment` | `[loaderName:${name}]` | count | Number of hit a loader had. |
| `${prefix}.plugins.count` | `[]` | count | Number of plugins. |
| `${prefix}.plugins.duration` | `[pluginName:${name}]` | milliseconds | Total runtime duration of a plugin. |
| `${prefix}.plugins.hooks.duration` | `[pluginName:${name}, hookName:${name}]` | milliseconds | Runtime duration of a hook. |
| `${prefix}.plugins.hooks.increment` | `[pluginName:${name}, hookName:${name}]` | count | Number of hit a hook had. |
| `${prefix}.plugins.increment` | `[pluginName:${name}]` | count | Number of hit a plugin had. |

## Dashboard

Expand Down
Loading

0 comments on commit ff1b213

Please sign in to comment.