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

[sourcemaps] Move sourcemaps #118

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ packages/tests/src/plugins/injection @yoannmoin
packages/plugins/telemetry @DataDog/frontend-devx @yoannmoinet
packages/tests/src/plugins/telemetry @DataDog/frontend-devx @yoannmoinet

# Rum
packages/plugins/rum @DataDog/rum @yoannmoinet
packages/tests/src/plugins/rum @DataDog/rum @yoannmoinet
# Error Tracking
packages/plugins/error-tracking @yoannmoinet
packages/tests/src/plugins/error-tracking @yoannmoinet
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
with:
node-version: ${{matrix.node}}.x
- run: yarn install
- run: yarn build:all
- run: yarn test

lint:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To interact with Datadog directly from your builds.
- [Vite](#-vite)
- [Webpack](#-webpack)
- [Features](#features)
- [RUM](#rum-----)
- [Error Tracking](#error-tracking-----)
- [Telemetry](#telemetry-----)
- [Configuration](#configuration)
- [`auth.apiKey`](#authapikey)
Expand Down Expand Up @@ -235,13 +235,13 @@ module.exports = {
## Features

<!-- #list-of-packages -->
### RUM <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/rspack.svg" alt="Rspack" width="17" /> <img src="packages/assets/src/vite.svg" alt="Vite" width="17" /> <img src="packages/assets/src/webpack.svg" alt="Webpack" width="17" />
### Error Tracking <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/rspack.svg" alt="Rspack" width="17" /> <img src="packages/assets/src/vite.svg" alt="Vite" width="17" /> <img src="packages/assets/src/webpack.svg" alt="Webpack" width="17" />

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

```typescript
datadogWebpackPlugin({
rum?: {
errorTracking?: {
disabled?: boolean,
sourcemaps?: {
bailOnError?: boolean,
Expand All @@ -256,7 +256,7 @@ datadogWebpackPlugin({
});
```

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

### 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/rspack.svg" alt="Rspack" width="17" /> <img src="packages/assets/src/vite.svg" alt="Vite" width="17" /> <img src="packages/assets/src/webpack.svg" alt="Webpack" width="17" />

Expand Down Expand Up @@ -296,7 +296,7 @@ datadogWebpackPlugin({
};
customPlugins?: (options: Options, context: GlobalContext, log: Logger) => UnpluginPlugin[];
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
rum?: {
errorTracking?: {
disabled?: boolean;
sourcemaps?: {
bailOnError?: boolean;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"loop": "yarn workspaces foreach -Apti --include \"@datadog/*\" --exclude \"@datadog/build-plugins\"",
"oss": "yarn cli oss -d packages -l mit",
"publish:all": "yarn loop --no-private npm publish",
"test": "yarn build:all && yarn workspace @dd/tests test",
"test:noisy": "yarn workspace @dd/tests test:noisy",
"test": "yarn workspace @dd/tests test",
"typecheck:all": "yarn workspaces foreach -Apti run typecheck",
"version:all": "yarn loop version --deferred ${0} && yarn version apply --all",
"watch:all": "yarn loop run watch"
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import type { TrackedFilesMatcher } from '@dd/internal-git-plugin/trackedFilesMatcher';
/* eslint-disable arca/import-ordering */
// #imports-injection-marker
import type { RumOptions } from '@dd/rum-plugin/types';
import type * as rum from '@dd/rum-plugin';
import type { ErrorTrackingOptions } from '@dd/error-tracking-plugin/types';
import type * as errorTracking from '@dd/error-tracking-plugin';
import type { TelemetryOptions } from '@dd/telemetry-plugin/types';
import type * as telemetry from '@dd/telemetry-plugin';
// #imports-injection-marker
Expand Down Expand Up @@ -127,7 +127,7 @@ export interface BaseOptions {
export interface Options extends BaseOptions {
// Each product should have a unique entry.
// #types-injection-marker
[rum.CONFIG_KEY]?: RumOptions;
[errorTracking.CONFIG_KEY]?: ErrorTrackingOptions;
[telemetry.CONFIG_KEY]?: TelemetryOptions;
// #types-injection-marker
customPlugins?: GetCustomPlugins;
Expand Down
2 changes: 1 addition & 1 deletion packages/factory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
},
"dependencies": {
"@dd/core": "workspace:*",
"@dd/error-tracking-plugin": "workspace:*",
"@dd/internal-build-report-plugin": "workspace:*",
"@dd/internal-bundler-report-plugin": "workspace:*",
"@dd/internal-git-plugin": "workspace:*",
"@dd/internal-injection-plugin": "workspace:*",
"@dd/rum-plugin": "workspace:*",
"@dd/telemetry-plugin": "workspace:*",
"chalk": "2.3.1",
"unplugin": "1.16.0"
Expand Down
17 changes: 12 additions & 5 deletions packages/factory/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { getContext, getLoggerFactory, validateOptions } from './helpers';

/* eslint-disable arca/import-ordering, arca/newline-after-import-section */
// #imports-injection-marker
import type { OptionsWithRum } from '@dd/rum-plugin/types';
import * as rum from '@dd/rum-plugin';
import type { OptionsWithErrorTracking } from '@dd/error-tracking-plugin/types';
import * as errorTracking from '@dd/error-tracking-plugin';
import type { OptionsWithTelemetry } from '@dd/telemetry-plugin/types';
import * as telemetry from '@dd/telemetry-plugin';
import { getBuildReportPlugins } from '@dd/internal-build-report-plugin';
Expand All @@ -37,7 +37,7 @@ import { getGitPlugins } from '@dd/internal-git-plugin';
import { getInjectionPlugins } from '@dd/internal-injection-plugin';
// #imports-injection-marker
// #types-export-injection-marker
export type { types as RumTypes } from '@dd/rum-plugin';
export type { types as ErrorTrackingTypes } from '@dd/error-tracking-plugin';
export type { types as TelemetryTypes } from '@dd/telemetry-plugin';
// #types-export-injection-marker
/* eslint-enable arca/import-ordering, arca/newline-after-import-section */
Expand Down Expand Up @@ -110,9 +110,16 @@ export const buildPluginFactory = ({

// Based on configuration add corresponding plugin.
// #configs-injection-marker
if (options[rum.CONFIG_KEY] && options[rum.CONFIG_KEY].disabled !== true) {
if (
options[errorTracking.CONFIG_KEY] &&
options[errorTracking.CONFIG_KEY].disabled !== true
) {
plugins.push(
...rum.getPlugins(options as OptionsWithRum, context, getLogger(rum.PLUGIN_NAME)),
...errorTracking.getPlugins(
options as OptionsWithErrorTracking,
context,
getLogger(errorTracking.PLUGIN_NAME),
),
);
}
if (options[telemetry.CONFIG_KEY] && options[telemetry.CONFIG_KEY].disabled !== true) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RUM Plugin <!-- #omit in toc -->
# Error Tracking Plugin <!-- #omit in toc -->

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

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

Expand All @@ -11,19 +11,19 @@ Interact with our Real User Monitoring product (RUM) in Datadog directly from yo
<!-- #toc -->
- [Configuration](#configuration)
- [Sourcemaps Upload](#sourcemaps-upload)
- [`rum.sourcemaps.bailOnError`](#rumsourcemapsbailonerror)
- [`rum.sourcemaps.dryRun`](#rumsourcemapsdryrun)
- [`rum.sourcemaps.intakeUrl`](#rumsourcemapsintakeurl)
- [`rum.sourcemaps.maxConcurrency`](#rumsourcemapsmaxconcurrency)
- [`rum.sourcemaps.minifiedPathPrefix`](#rumsourcemapsminifiedpathprefix)
- [`rum.sourcemaps.releaseVersion`](#rumsourcemapsreleaseversion)
- [`rum.sourcemaps.service`](#rumsourcemapsservice)
- [errorTracking.sourcemaps.bailOnError](#errortrackingsourcemapsbailonerror)
- [errorTracking.sourcemaps.dryRun](#errortrackingsourcemapsdryrun)
- [errorTracking.sourcemaps.intakeUrl](#errortrackingsourcemapsintakeurl)
- [errorTracking.sourcemaps.maxConcurrency](#errortrackingsourcemapsmaxconcurrency)
- [errorTracking.sourcemaps.minifiedPathPrefix](#errortrackingsourcemapsminifiedpathprefix)
- [errorTracking.sourcemaps.releaseVersion](#errortrackingsourcemapsreleaseversion)
- [errorTracking.sourcemaps.service](#errortrackingsourcemapsservice)
<!-- #toc -->

## Configuration

```ts
rum?: {
errorTracking?: {
disabled?: boolean;
sourcemaps?: {
bailOnError?: boolean;
Expand All @@ -45,31 +45,31 @@ Upload JavaScript sourcemaps to Datadog to un-minify your errors.
> You can override the intake URL by setting the `DATADOG_SOURCEMAP_INTAKE_URL` environment variable (eg. `https://sourcemap-intake.datadoghq.com/v1/input`).
> Or only the domain with the `DATADOG_SITE` environment variable (eg. `datadoghq.com`).

### `rum.sourcemaps.bailOnError`
### errorTracking.sourcemaps.bailOnError

> default: `false`

Should the upload of sourcemaps fail the build on first error?

### `rum.sourcemaps.dryRun`
### errorTracking.sourcemaps.dryRun

> default: `false`

It will not upload the sourcemaps to Datadog, but will do everything else.

### `rum.sourcemaps.intakeUrl`
### errorTracking.sourcemaps.intakeUrl

> default: `https://sourcemap-intake.datadoghq.com/api/v2/srcmap`

Against which endpoint do you want to upload the sourcemaps.

### `rum.sourcemaps.maxConcurrency`
### errorTracking.sourcemaps.maxConcurrency

> default: `20`

Number of concurrent upload to the API.

### `rum.sourcemaps.minifiedPathPrefix`
### errorTracking.sourcemaps.minifiedPathPrefix

> required

Expand All @@ -79,13 +79,13 @@ The prefix can be a full URL or an absolute path.

Example: if you're uploading `dist/file.js` to `https://example.com/static/file.js`, you can use `minifiedPathPrefix: 'https://example.com/static/'` or `minifiedPathPrefix: '/static/'`.`minifiedPathPrefix: '/'` is a valid input when you upload JS at the root directory of the server.

### `rum.sourcemaps.releaseVersion`
### errorTracking.sourcemaps.releaseVersion

> required

Is similar and will be used to match the `version` tag set on the RUM SDK.

### `rum.sourcemaps.service`
### errorTracking.sourcemaps.service

> required

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@dd/rum-plugin",
elbywan marked this conversation as resolved.
Show resolved Hide resolved
"name": "@dd/error-tracking-plugin",
"packageManager": "[email protected]",
"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",
"description": "Interact with Error Tracking directly from your build system.",
"homepage": "https://github.com/DataDog/build-plugins/tree/main/packages/plugins/error-tracking#readme",
"repository": {
"type": "git",
"url": "https://github.com/DataDog/build-plugins",
"directory": "packages/plugins/rum"
"directory": "packages/plugins/error-tracking"
},
"exports": {
".": "./src/index.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

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

export const CONFIG_KEY = 'rum' as const;
export const PLUGIN_NAME: PluginName = 'datadog-rum-plugin' as const;
export const CONFIG_KEY = 'errorTracking' as const;
export const PLUGIN_NAME: PluginName = 'datadog-error-tracking-plugin' as const;
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,46 @@

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

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

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

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

export const getPlugins: GetPlugins<OptionsWithRum> = (
opts: OptionsWithRum,
export const getPlugins: GetPlugins<OptionsWithErrorTracking> = (
opts: OptionsWithErrorTracking,
context: GlobalContext,
log: Logger,
) => {
// Verify configuration.
const rumOptions = validateOptions(opts, log);
const options = validateOptions(opts, log);
return [
{
name: 'datadog-rum-sourcemaps-plugin',
name: PLUGIN_NAME,
enforce: 'post',
async writeBundle() {
if (rumOptions.disabled) {
if (options.disabled) {
return;
}

if (rumOptions.sourcemaps) {
if (options.sourcemaps) {
// Need the "as" because Typescript doesn't understand that we've already checked for sourcemaps.
await uploadSourcemaps(rumOptions as RumOptionsWithSourcemaps, context, log);
await uploadSourcemaps(
options as ErrorTrackingOptionsWithSourcemaps,
context,
log,
);
}
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import type { GlobalContext } from '@dd/core/types';
import chalk from 'chalk';
import path from 'path';

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

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

const decomposePath = (
options: RumSourcemapsOptionsWithDefaults,
options: SourcemapsOptionsWithDefaults,
context: GlobalContext,
sourcemapFilePath: string,
): PartialSourcemap => {
Expand All @@ -33,7 +33,7 @@ const decomposePath = (
};

export const getSourcemapsFiles = (
options: RumSourcemapsOptionsWithDefaults,
options: SourcemapsOptionsWithDefaults,
context: GlobalContext,
): Sourcemap[] => {
if (!context.build.outputs || context.build.outputs.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import type { Logger, GlobalContext } from '@dd/core/types';
import chalk from 'chalk';
import { outdent } from 'outdent';

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

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

export const uploadSourcemaps = async (
options: RumOptionsWithSourcemaps,
options: ErrorTrackingOptionsWithSourcemaps,
context: GlobalContext,
log: Logger,
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Readable } from 'stream';
import type { Gzip } from 'zlib';
import { createGzip } from 'zlib';

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

import type { LocalAppendOptions, Metadata, MultipartFileValue, Payload } from './payload';
import { getPayload } from './payload';
Expand Down Expand Up @@ -78,7 +78,7 @@ export const getData =

export const upload = async (
payloads: Payload[],
options: RumSourcemapsOptionsWithDefaults,
options: SourcemapsOptionsWithDefaults,
context: GlobalContext,
log: Logger,
) => {
Expand Down Expand Up @@ -153,7 +153,7 @@ export const upload = async (

export const sendSourcemaps = async (
sourcemaps: Sourcemap[],
options: RumSourcemapsOptionsWithDefaults,
options: SourcemapsOptionsWithDefaults,
context: GlobalContext,
log: Logger,
) => {
Expand Down
Loading