Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telemetry] Refactor telemetry with build report #93

Merged
merged 29 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8dbd02f
Move the endPoint setting to be telemetry only
yoannmoinet Sep 4, 2024
c6bc98d
Remove some files output
yoannmoinet Sep 4, 2024
54de817
Fix plugin detection
yoannmoinet Sep 4, 2024
16ff0a9
Refactor telemetry module to use the build-report
yoannmoinet Sep 4, 2024
d5af7ab
Update readme
yoannmoinet Sep 5, 2024
eb5ab6c
Use the logger to output telemetry
yoannmoinet Sep 5, 2024
6ac78c6
Update TODO
yoannmoinet Sep 5, 2024
768b311
Add enableTracing option to telemetry
yoannmoinet Sep 6, 2024
7ccd272
Refactor and simplify metrics aggregation
yoannmoinet Sep 6, 2024
20bf294
Centralize telemetry default configurations
yoannmoinet Sep 6, 2024
8d1dc96
Streamline files output decision
yoannmoinet Sep 6, 2024
9f4b0ae
Refactor text output of telemetry
yoannmoinet Sep 6, 2024
e13a9ee
Update documentation
yoannmoinet Sep 6, 2024
1220a53
Update files tests
yoannmoinet Sep 6, 2024
2fa749b
Update helpers tests
yoannmoinet Sep 6, 2024
fccf639
Add deprecated comment on enableTracing
yoannmoinet Sep 6, 2024
049d0f1
Update commit hook
yoannmoinet Sep 6, 2024
5d381c1
Update output text rendering
yoannmoinet Sep 6, 2024
7b9c81e
Output more info in the text report
yoannmoinet Sep 6, 2024
2cdea04
Fix readme links
yoannmoinet Sep 6, 2024
ebae582
Prevent tests from doing real HTTP request
yoannmoinet Sep 6, 2024
40b086e
Fix files output
yoannmoinet Sep 6, 2024
0bee3a6
Tweaks and fixes
yoannmoinet Sep 9, 2024
bcfbaf4
Add .toBeInRange helper for jest
yoannmoinet Sep 9, 2024
7474b2d
Add possibility to filter bundlers programmatically
yoannmoinet Sep 9, 2024
8e5718e
Add tests for metrics
yoannmoinet Sep 9, 2024
fe073b1
Integrity
yoannmoinet Sep 9, 2024
c1b22bd
Merge branch 'yoann/build-report-internal-plugin' into yoann/refactor…
yoannmoinet Sep 11, 2024
878468d
Fix aggregator type issue
yoannmoinet Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading