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

[plugin] RUM plugin #78

Merged
merged 60 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
30871ce
Add sourcemaps plugin
yoannmoinet Jun 24, 2024
fb56bc8
Automation
yoannmoinet Jun 20, 2024
e824eef
Update when we inject git data
yoannmoinet Jun 20, 2024
263640f
Update packages/plugins/rum/src/sourcemaps/files.ts
yoannmoinet Jun 24, 2024
19e3862
Add intake override and test it
yoannmoinet Jun 24, 2024
38bc7d7
Merge remote-tracking branch 'origin/master' into yoann/rum-plugin
yoannmoinet Jun 25, 2024
e69c1b8
Run integrity
yoannmoinet Jun 25, 2024
8d90ef3
Update endPoint usage
yoannmoinet Jun 25, 2024
9271c7c
Update how we compute the body
yoannmoinet Jun 26, 2024
a9ce05f
Remove form-data dependency
yoannmoinet Jun 27, 2024
afb82ea
Add type to File
yoannmoinet Jun 27, 2024
65eea4a
Install nock
yoannmoinet Jun 27, 2024
12508da
Fix bail calls
yoannmoinet Jun 27, 2024
7d6f49d
Use a mock server instead of mocking fetch
yoannmoinet Jun 27, 2024
5766384
Update licenses
yoannmoinet Jun 27, 2024
07af3f4
Update API's url in tests
yoannmoinet Jun 27, 2024
19fd428
Mock more requests
yoannmoinet Jun 28, 2024
d98411a
Fix unplugin
yoannmoinet Jun 28, 2024
b1ceafe
Update licenses
yoannmoinet Jun 28, 2024
1b54c59
Do not ignore patches
yoannmoinet Jun 28, 2024
f36076c
Fix types name
yoannmoinet Jul 1, 2024
f4c6b67
Fix unplugin patch
yoannmoinet Jul 1, 2024
78d4c25
Add an 'info' level to log
yoannmoinet Jul 1, 2024
794287b
Fix bundling issue with module.exports overrides
yoannmoinet Jul 1, 2024
7b75f29
Add more logs
yoannmoinet Jul 1, 2024
62e986b
Update types
yoannmoinet Jul 4, 2024
08ad0d4
Better log for missing tracked files
yoannmoinet Jul 4, 2024
9412e71
Update esbuild webpack rollup
yoannmoinet Jul 9, 2024
62511af
Refactor tests for telemetry
yoannmoinet Jul 9, 2024
b7ac51c
Update tsconfig for better esm support
yoannmoinet Jul 9, 2024
6b38aa0
Fix @dd/tools exports
yoannmoinet Jul 9, 2024
7a0a011
Move test constants
yoannmoinet Jul 9, 2024
f7aa680
Update prefix type
yoannmoinet Jul 9, 2024
0ca8c30
Add outputFiles to globalContext
yoannmoinet Jul 9, 2024
14d5160
Fix telemetry tests
yoannmoinet Jul 9, 2024
94439e3
Add webpack4 support to outputFiles context
yoannmoinet Jul 9, 2024
e7e87c3
Run tests with webpack4 as well
yoannmoinet Jul 9, 2024
7bc1843
Fix rollupConfig.mjs import
yoannmoinet Jul 10, 2024
5b2192e
Add outputDir to context for webpack and esbuild
yoannmoinet Jul 10, 2024
b8a4b48
Update test
yoannmoinet Jul 10, 2024
5fc71c0
Fix outputFiles global context as it was not filled in time for webpack
yoannmoinet Jul 10, 2024
8fe118c
Make jest silent
yoannmoinet Jul 10, 2024
22db40c
Run all bundlers
yoannmoinet Jul 10, 2024
35aa4a6
Use context instead of basePath for sourcemaps
yoannmoinet Jul 10, 2024
54ab14b
Clean builds before running bundlers
yoannmoinet Jul 10, 2024
b61d5b5
Update tests
yoannmoinet Jul 10, 2024
48bf921
Fix lock
yoannmoinet Jul 10, 2024
92f7158
Remove comment
yoannmoinet Jul 10, 2024
b99b3c9
Update scripts for loops
yoannmoinet Jul 10, 2024
f86c49e
Change error log
yoannmoinet Jul 10, 2024
0a37000
Update test with context to actually reflect context's mutable object
yoannmoinet Jul 10, 2024
69bcdc5
Add test:noisy
yoannmoinet Jul 10, 2024
08b9010
Webpack 4 is hanging, delay the resolution
yoannmoinet Jul 10, 2024
8865781
Remove .only
yoannmoinet Jul 10, 2024
5952bad
Merge pull request #85 from DataDog/yoann/refactor-testing-telemetry
yoannmoinet Jul 10, 2024
b2ca98d
Merge pull request #84 from DataDog/yoann/more-global-contexts
yoannmoinet Jul 10, 2024
a92830f
Update output
yoannmoinet Jul 10, 2024
d6aaea2
Merge pull request #87 from DataDog/yoann/use-context-for-sourcemaps
yoannmoinet Jul 10, 2024
872ab89
Update unplugin to latest
yoannmoinet Jul 10, 2024
500f410
v2.1.0
yoannmoinet Jul 10, 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
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
# Telemetry
packages/plugins/telemetry @DataDog/frontend-devx @yoannmoinet
packages/tests/src/plugins/telemetry @DataDog/frontend-devx @yoannmoinet

# Rum
packages/plugins/rum @DataDog/rum @yoannmoinet
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably fix these.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we have a good team to add for RUM?
This one seemed a bit too wide maybe.

packages/tests/src/plugins/rum @DataDog/rum @yoannmoinet
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions LICENSES-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Component,Origin,Licence,Copyright
@tsconfig/node12,npm,MIT,(https://www.npmjs.com/package/@tsconfig/node12)
@tsconfig/node14,npm,MIT,(https://www.npmjs.com/package/@tsconfig/node14)
@tsconfig/node16,npm,MIT,(https://www.npmjs.com/package/@tsconfig/node16)
@types/async-retry,npm,MIT,(https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/async-retry)
@types/babel__core,npm,MIT,(https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/babel__core)
@types/babel__generator,npm,MIT,(https://www.npmjs.com/package/@types/babel__generator)
@types/babel__preset-env,npm,MIT,(https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/babel__preset-env)
Expand All @@ -200,6 +201,7 @@ Component,Origin,Licence,Copyright
@types/node,npm,MIT,(https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node)
@types/parse-json,npm,MIT,(https://www.npmjs.com/package/@types/parse-json)
@types/resolve,npm,MIT,(https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/resolve)
@types/retry,npm,MIT,(https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/retry)
@types/semver,npm,MIT,(https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/semver)
@types/stack-utils,npm,MIT,(https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/stack-utils)
@types/wrap-ansi,npm,MIT,(https://www.npmjs.com/package/@types/wrap-ansi)
Expand Down Expand Up @@ -275,6 +277,7 @@ assert-plus,npm,MIT,Mark Cavage (https://www.npmjs.com/package/assert-plus)
assign-symbols,npm,MIT,Jon Schlinkert (https://github.com/jonschlinkert/assign-symbols)
astral-regex,npm,MIT,Kevin Mårtensson (github.com/kevva)
async-each,npm,MIT,Paul Miller (https://github.com/paulmillr/async-each/)
async-retry,npm,MIT,(https://www.npmjs.com/package/async-retry)
asynckit,npm,MIT,Alex Indigo (https://github.com/alexindigo/asynckit#readme)
atob,npm,(MIT OR Apache-2.0),AJ ONeal (https://git.coolaj86.com/coolaj86/atob.js.git)
available-typed-arrays,npm,MIT,Jordan Harband (https://github.com/inspect-js/available-typed-arrays#readme)
Expand Down Expand Up @@ -437,6 +440,7 @@ esrecurse,npm,BSD-2-Clause,(https://github.com/estools/esrecurse)
estraverse,npm,BSD-2-Clause,(https://github.com/estools/estraverse)
estree-walker,npm,MIT,Rich Harris (https://www.npmjs.com/package/estree-walker)
esutils,npm,BSD-2-Clause,(https://github.com/estools/esutils)
eventemitter3,npm,MIT,Arnout Kazemier (https://www.npmjs.com/package/eventemitter3)
events,npm,MIT,Irakli Gozalishvili (http://jeditoolkit.com)
evp_bytestokey,npm,MIT,Calvin Metcalf (https://github.com/crypto-browserify/EVP_BytesToKey)
execa,npm,MIT,Sindre Sorhus (sindresorhus.com)
Expand Down Expand Up @@ -697,9 +701,12 @@ os-homedir,npm,MIT,Sindre Sorhus (sindresorhus.com)
os-tmpdir,npm,MIT,Sindre Sorhus (sindresorhus.com)
osenv,npm,ISC,Isaac Z. Schlueter (http://blog.izs.me/)
outdent,npm,MIT,Andrew Bradley (https://github.com/cspotcode/outdent#readme)
p-finally,npm,MIT,Sindre Sorhus (sindresorhus.com)
p-limit,npm,MIT,Sindre Sorhus (sindresorhus.com)
p-locate,npm,MIT,Sindre Sorhus (sindresorhus.com)
p-map,npm,MIT,Sindre Sorhus (https://sindresorhus.com)
p-queue,npm,MIT,(https://www.npmjs.com/package/p-queue)
p-timeout,npm,MIT,Sindre Sorhus (sindresorhus.com)
p-try,npm,MIT,Sindre Sorhus (sindresorhus.com)
pad,npm,BSD-3-Clause,David Worms (https://github.com/adaltas/node-pad)
pako,npm,(MIT AND Zlib),(https://github.com/nodeca/pako)
Expand Down Expand Up @@ -771,6 +778,7 @@ resolve-url,npm,MIT,Simon Lydell (https://www.npmjs.com/package/resolve-url)
resolve.exports,npm,MIT,Luke Edwards (https://lukeed.com)
restore-cursor,npm,MIT,Sindre Sorhus (sindresorhus.com)
ret,npm,MIT,Roly Fentanes (https://github.com/fent)
retry,npm,MIT,Tim Koschützki (https://github.com/tim-kos/node-retry)
reusify,npm,MIT,Matteo Collina (https://github.com/mcollina/reusify#readme)
rimraf,npm,ISC,Isaac Z. Schlueter (http://blog.izs.me/)
ripemd160,npm,MIT,(https://www.npmjs.com/package/ripemd160)
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ A set of plugins to interact with Datadog directly from your builds.

<!-- #toc -->
- [Plugins](#plugins)
- [`rum` RUM Plugin](#rum-rum-plugin)
- [`telemetry` Telemetry Plugin](#telemetry-telemetry-plugin)
- [Configuration](#configuration)
- [`auth.apiKey`](#authapikey)
Expand All @@ -32,6 +33,12 @@ A set of plugins to interact with Datadog directly from your builds.
## Plugins

<!-- #list-of-packages -->
### `rum` RUM Plugin

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

<kbd>[📝 Full documentation ➡️](./packages/plugins/rum#readme)</kbd>

### `telemetry` Telemetry Plugin

> Display and send telemetry data as metrics to Datadog.
Expand All @@ -52,6 +59,17 @@ A set of plugins to interact with Datadog directly from your builds.
endPoint?: string;
};
logLevel?: 'debug' | 'warn' | 'error' | 'none';
rum?: {
disabled?: boolean;
sourcemaps?: {
basePath: string;
dryRun?: boolean;
maxConcurrency?: number;
minifiedPathPrefix?: string;
releaseVersion: string;
service: string;
};
};
telemetry?: {
disabled?: boolean;
output?: boolean
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/plugins/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const getGitPlugin = (options: Options, context: GlobalContext): Unplugin
enforce: 'pre',
async buildStart() {
// Verify that we should get the git information based on the options.
// Only get git information if git is not disabled.
const shouldGetGitInfo = options.disableGit !== true;
// Only get git information if sourcemaps are enabled and git is not disabled.
const shouldGetGitInfo = options.rum?.sourcemaps && options.disableGit !== true;

if (!shouldGetGitInfo) {
return;
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Copyright 2019-Present Datadog, Inc.

// #imports-injection-marker
import type { RumOptions } from '@dd/rum-plugins/types';
import type * as rum from '@dd/rum-plugins';
import type { TelemetryOptions } from '@dd/telemetry-plugins/types';
import type * as telemetry from '@dd/telemetry-plugins';
// #imports-injection-marker
Expand Down Expand Up @@ -50,6 +52,7 @@ export interface GetPluginsOptions {
export interface Options extends GetPluginsOptions {
// Each product should have a unique entry.
// #types-injection-marker
[rum.CONFIG_KEY]?: RumOptions;
[telemetry.CONFIG_KEY]?: TelemetryOptions;
// #types-injection-marker
}
Expand Down
1 change: 1 addition & 0 deletions packages/esbuild-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type { Options as EsbuildPluginOptions } from '@dd/core/types';

export type {
// #types-export-injection-marker
RumTypes,
TelemetryTypes,
// #types-export-injection-marker
} from '@dd/factory';
1 change: 1 addition & 0 deletions packages/factory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@dd/core": "workspace:*",
"@dd/rum-plugins": "workspace:*",
"@dd/telemetry-plugins": "workspace:*",
"unplugin": "1.10.1"
}
Expand Down
7 changes: 7 additions & 0 deletions packages/factory/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { getInternalPlugins } from '@dd/core/plugins/index';
import type { Options } from '@dd/core/types';

// #imports-injection-marker
import type { OptionsWithRum } from '@dd/rum-plugins/types';
import * as rum from '@dd/rum-plugins';
import type { OptionsWithTelemetry } from '@dd/telemetry-plugins/types';
import * as telemetry from '@dd/telemetry-plugins';
// #imports-injection-marker
Expand All @@ -20,12 +22,14 @@ import type { UnpluginContextMeta, UnpluginInstance, UnpluginOptions } from 'unp
import { createUnplugin } from 'unplugin';

// #types-export-injection-marker
export type { types as RumTypes } from '@dd/rum-plugins';
export type { types as TelemetryTypes } from '@dd/telemetry-plugins';
// #types-export-injection-marker

export const helpers = {
// Each product should have a unique entry.
// #helpers-injection-marker
[rum.CONFIG_KEY]: rum.helpers,
[telemetry.CONFIG_KEY]: telemetry.helpers,
// #helpers-injection-marker
};
Expand All @@ -51,6 +55,9 @@ export const buildPluginFactory = ({

// Based on configuration add corresponding plugin.
// #configs-injection-marker
if (options[rum.CONFIG_KEY] && options[rum.CONFIG_KEY].disabled !== true) {
plugins.push(...rum.getPlugins(options as OptionsWithRum, globalContext));
}
if (options[telemetry.CONFIG_KEY] && options[telemetry.CONFIG_KEY].disabled !== true) {
plugins.push(...telemetry.getPlugins(options as OptionsWithTelemetry, globalContext));
}
Expand Down
29 changes: 29 additions & 0 deletions packages/plugins/rum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# RUM Plugin <!-- #omit in toc -->

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

<!-- The title and the following line will both be added to the root README.md -->

## Table of content <!-- #omit in toc -->

<!-- This is auto generated with yarn cli integrity -->

<!-- #toc -->
- [Configuration](#configuration)
<!-- #toc -->

## Configuration

```ts
rum?: {
disabled?: boolean;
sourcemaps?: {
basePath: string;
dryRun?: boolean;
maxConcurrency?: number;
minifiedPathPrefix?: string;
releaseVersion: string;
service: string;
};
}
```
35 changes: 35 additions & 0 deletions packages/plugins/rum/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@dd/rum-plugins",
"packageManager": "yarn@4.0.2",
"license": "MIT",
"private": true,
"author": "Datadog",
"description": "Interact with our Real User Monitoring product (RUM) in Datadog directly from your build system.",
"homepage": "https://github.com/DataDog/build-plugins/tree/main/packages/plugins/rum#readme",
"repository": {
"type": "git",
"url": "https://github.com/DataDog/build-plugins",
"directory": "packages/plugins/rum"
},
"exports": {
".": "./src/index.ts",
"./sourcemaps/*": "./src/sourcemaps/*.ts",
"./*": "./src/*.ts"
},
"scripts": {
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@dd/core": "workspace:*",
"async-retry": "1.3.3",
"chalk": "2.3.1",
"form-data": "4.0.0",
"glob": "7.1.6",
"outdent": "0.8.0",
"p-queue": "6.6.2",
"unplugin": "1.10.1"
},
"devDependencies": {
"@types/async-retry": "1.4.8"
}
}
8 changes: 8 additions & 0 deletions packages/plugins/rum/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

import type { PluginName } from '@dd/core/types';

export const CONFIG_KEY = 'rum' as const;
export const PLUGIN_NAME: PluginName = 'datadog-rum-plugin' as const;
47 changes: 47 additions & 0 deletions packages/plugins/rum/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

import { getLogger } from '@dd/core/log';
import type { GlobalContext, GetPlugins } from '@dd/core/types';

import { PLUGIN_NAME } from './constants';
import { uploadSourcemaps } from './sourcemaps';
import type { OptionsWithRum, RumOptions, RumOptionsWithSourcemaps } from './types';
import { validateOptions } from './validate';

export { CONFIG_KEY, PLUGIN_NAME } from './constants';

export const helpers = {
// Add the helpers you'd like to expose here.
};
Comment on lines +15 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove this? It seems like it's not used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I was just thinking of this, I think right now we can't remove it, as the publish script expect all the plugins to have this.
But I'll submit a separate PR to make this optional, and only use the ones that are existing.


export type types = {
// Add the types you'd like to expose here.
RumOptions: RumOptions;
OptionsWithRum: OptionsWithRum;
};

export const getPlugins: GetPlugins<OptionsWithRum> = (
opts: OptionsWithRum,
context: GlobalContext,
) => {
// Verify configuration.
const rumOptions = validateOptions(opts);
return [
{
name: PLUGIN_NAME,
async writeBundle() {
if (rumOptions.disabled) {
return;
}

const log = getLogger(opts.logLevel, PLUGIN_NAME);
if (rumOptions.sourcemaps) {
// Need the "as" because Typescript doesn't understand that we've already checked for sourcemaps.
await uploadSourcemaps(rumOptions as RumOptionsWithSourcemaps, context, log);
}
},
},
];
};
53 changes: 53 additions & 0 deletions packages/plugins/rum/src/sourcemaps/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

import chalk from 'chalk';
import glob from 'glob';
import path from 'path';

import type { RumSourcemapsOptionsWithDefaults, Sourcemap } from '../types';

type PartialSourcemap = Pick<Sourcemap, 'minifiedFilePath' | 'minifiedUrl' | 'relativePath'>;

const getGlobPattern = (basePath: string) => {
// Normalizing the basePath to resolve .. and .
// Always using the posix version to avoid \ on Windows.
const newPath = path.posix.normalize(basePath);
return path.join(newPath, '**/*.@(js|mjs).map');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Should the pattern be configurable?

Copy link
Member Author

@yoannmoinet yoannmoinet Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed datadog-ci's implementation, where this is not configurable.

https://github.com/DataDog/datadog-ci/blob/026557808bb4ca0756bac078b715f63c9c11bca7/src/commands/sourcemaps/upload.ts#L173-L174

I prefer to cross that bridge when we get there for simplicity's sake.

};

const decomposePath = (
options: RumSourcemapsOptionsWithDefaults,
sourcemapFilePath: string,
): PartialSourcemap => {
if (path.extname(sourcemapFilePath) !== '.map') {
throw new Error(`The file ${chalk.green.bold(sourcemapFilePath)} is not a sourcemap.`);
}

const minifiedFilePath = sourcemapFilePath.replace(/\.map$/, '');
const relativePath = minifiedFilePath.replace(options.basePath, '');
const minifiedUrl = options.minifiedPathPrefix
? path.join(options.minifiedPathPrefix, relativePath)
: relativePath;

return {
minifiedFilePath,
minifiedUrl,
relativePath,
};
};

export const getSourcemapsFiles = (options: RumSourcemapsOptionsWithDefaults): Sourcemap[] => {
const globPattern = getGlobPattern(options.basePath);
const sourcemapFilesList = glob.sync(globPattern);
const sourcemapFiles = sourcemapFilesList.map((sourcemapFilePath) => {
return {
...decomposePath(options, sourcemapFilePath),
sourcemapFilePath,
minifiedPathPrefix: options.minifiedPathPrefix,
};
});

return sourcemapFiles;
};
37 changes: 37 additions & 0 deletions packages/plugins/rum/src/sourcemaps/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

import type { Logger } from '@dd/core/log';
import type { GlobalContext } from '@dd/core/types';
import chalk from 'chalk';
import { outdent } from 'outdent';

import type { RumOptionsWithSourcemaps } from '../types';

import { getSourcemapsFiles } from './files';
import { sendSourcemaps } from './sender';

export const uploadSourcemaps = async (
options: RumOptionsWithSourcemaps,
context: GlobalContext,
log: Logger,
) => {
// Show a pretty summary of the configuration.
const green = chalk.green.bold;
const configurationString = Object.entries(options.sourcemaps)
.map(([key, value]) => ` - ${key}: ${green(value.toString())}`)
.join('\n');

const summary = outdent`
Uploading sourcemap with this configuration:
${configurationString}
`;

log(summary);

// Gather the sourcemaps files.
const sourcemaps = getSourcemapsFiles(options.sourcemaps);
// Send everything.
await sendSourcemaps(sourcemaps, options.sourcemaps, context, log);
};
Loading
Loading