Skip to content

[rum-privacy] add sourcemaps and telemetry - #187

Merged
yoannmoinet merged 30 commits into
masterfrom
congyao/add-sourcemaps-and-telemetry
Aug 4, 2025
Merged

[rum-privacy] add sourcemaps and telemetry#187
yoannmoinet merged 30 commits into
masterfrom
congyao/add-sourcemaps-and-telemetry

Conversation

@cy-moi

@cy-moi cy-moi commented Jul 4, 2025

Copy link
Copy Markdown
Contributor

What and why?

Improve the privacy plugin and update to the latest js-instrument-wasm library.
We want to add sourcemaps and telemetry to our privacy plugin.

How?

Change enforce: pre to post for privacy plugin
Make sdk injection plugin optional when opt-in for rum plugin
Add Typescript end to end testing and support
Update transform options to make sourcemaps working
Add logs for observability

@cy-moi
cy-moi force-pushed the congyao/add-sourcemaps-and-telemetry branch from eaaf2b5 to ecceaf7 Compare July 7, 2025 13:33

@sethfowler-datadog sethfowler-datadog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great! I posted a few nits below:

Comment thread packages/plugins/rum/src/privacy/index.ts Outdated
Comment thread packages/plugins/rum/src/privacy/transform.ts Outdated
Comment thread packages/plugins/rum/src/privacy/types.ts Outdated
Comment thread packages/plugins/rum/src/privacy/types.ts Outdated
Comment thread packages/tests/src/e2e/privacyPluginTypescript/privacyPluginTypescript.spec.ts Outdated

@yoannmoinet yoannmoinet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Started a review, will continue later on.

Comment thread packages/plugins/rum/src/privacy/index.ts Outdated
pluginOptions.module === 'cjs' ? './privacy-helpers.js' : './privacy-helpers.mjs',
);

const privacyHelpersModuleId = pluginOptions.helpersModule ?? PRIVACY_HELPERS_MODULE_ID;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need the ?? ... part?
We don't do it in buildTransformOptions().

Comment thread packages/plugins/rum/src/built/privacy-helpers.ts Outdated
Comment thread packages/plugins/rum/src/privacy/index.ts Outdated
Comment thread packages/plugins/rum/src/sdk.ts Outdated
Comment thread packages/plugins/rum/src/validate.test.ts
Comment thread packages/plugins/rum/src/validate.ts Outdated
@cy-moi
cy-moi force-pushed the congyao/add-sourcemaps-and-telemetry branch from ff4c50b to cdbd040 Compare July 15, 2025 13:15

@yoannmoinet yoannmoinet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not a fan of the addition to the verifyProjectBuild.
It's very complex, I'll have a look, but I think this can be simplified.

Comment thread packages/plugins/rum/src/types.ts Outdated
Comment thread packages/plugins/rum/src/validate.ts Outdated
Comment thread packages/plugins/rum/src/validate.ts Outdated
Comment thread packages/tests/src/_playwright/helpers/buildProject.ts Outdated
Comment on lines +24 to +47

// Get the entry for this specific bundler
const bundlerEntry = buildConfigOverride?.entry?.[bundler] || './index.js';

// Handle TypeScript compilation for each bundler
const additionalPlugins = [...(buildConfigOverride?.plugins || [])];

// Check if any entry is a TypeScript file
const hasTypeScriptEntries = Object.values(buildConfigOverride?.entry || {}).some((entry) =>
entry.endsWith('.ts'),
);

if (hasTypeScriptEntries) {
if (bundler === 'rollup' || bundler === 'vite') {
// Use @rollup/plugin-typescript for Rollup and Vite
additionalPlugins.push(
typescript({
tsconfig: path.resolve(cwd, 'tsconfig.json'),
}),
);
}
// ESBuild has built-in TypeScript support, no additional plugins needed
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't this logic live at the test level?

As-in, if your test requires to override the build's configuration, it should also handle this part as well (adding the ts plugin to the build).

Can you also give me more details on why you need this @rollup/plugin-typescript plugin exactly and not re-use the esbuild plugin?

@cy-moi cy-moi Jul 15, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did try this, but it requires changing the params for verifyProjectBuild even more, as we need to be able to accept different plugins for different bundlers. We are using @rollup/plugin-typescript to isolate issues of generated sourcemaps and avoid having two bundlers for the same build, per discussions in slack previously.

Comment thread packages/tools/src/bundlers.ts Outdated
Comment thread packages/tools/src/plugins.ts Outdated
@cy-moi
cy-moi force-pushed the congyao/add-sourcemaps-and-telemetry branch from 2b630f6 to 8a0f8ab Compare July 25, 2025 08:03
@cy-moi
cy-moi marked this pull request as ready for review July 25, 2025 09:07
@cy-moi
cy-moi requested a review from a team as a code owner July 25, 2025 09:07

@yoannmoinet yoannmoinet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very good update!
Left some comments and nits.

// FIXME: Handle sourcemaps.
await fsp.writeFile(output, data.code);
} catch (e) {
// skip if the file doesn't exist

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you specify the error if we only want to skip if the file doesn't exist?

Suggested change
// skip if the file doesn't exist
// Skip if the file doesn't exist
if (e.code !== 'ENOENT') {
throw e;
}

Also, in which circonstances will it happen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For example, when we have sub-builds in web-ui, the build entries are not actual entries and it may not exist when injecting. I'm not sure we should throw the error when the file does not exist, as it is not the entry file we want to inject anyway. I added comments and a log here instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You still need to filter on the e.code, otherwise, you will skip every kind of error, and not just the "missing file" error.

My suggestion isn't throwing when the file does not exist, on the contrary, it only throws when it's NOT a missing file error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yes indeed! Sorry I read wrong

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Your current code is skipping any error that could happen in fsp.readFile, esbuild.transform and fsp.writeFile, which is not what we want, and not what the comment is suggesting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should be fixed in the latest commit.

Comment thread packages/plugins/rum/src/privacy/constants.ts
Comment thread packages/plugins/rum/src/built/privacy-helpers.ts Outdated
Comment thread packages/plugins/rum/src/built/privacy-helpers.ts Outdated
Comment thread packages/plugins/rum/src/privacy/index.ts Outdated
Comment thread packages/plugins/rum/src/privacy/transform.ts Outdated
Comment thread packages/plugins/rum/src/validate.ts Outdated
Comment thread packages/published/rollup-plugin/package.json
Comment thread packages/plugins/rum/src/index.ts Outdated
Comment thread packages/plugins/rum/src/index.test.ts Outdated
cy-moi and others added 2 commits July 28, 2025 18:08
Co-authored-by: Yoann Moinet <597828+yoannmoinet@users.noreply.github.com>

@yoannmoinet yoannmoinet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Small nits.
Waiting for the update on the esbuild skipping errors then I'll ✅

Comment thread packages/plugins/rum/src/built/privacy-helpers.ts Outdated
Comment thread packages/plugins/rum/src/validate.ts Outdated
// Validate and add defaults sub-options.
const sdkResults = validateSDKOptions(options);
const privacyResults = validatePrivacyOptions(options);
const privacyResults = validatePrivacyOptions(options, log);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NIT: instead of passing the log here, you could log what you need on line 42.

@yoannmoinet yoannmoinet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, well done!

Comment thread packages/plugins/injection/src/esbuild.ts Outdated
Co-authored-by: Yoann Moinet <597828+yoannmoinet@users.noreply.github.com>
@cy-moi

cy-moi commented Aug 4, 2025

Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Aug 4, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-08-04 11:32:59 UTC ℹ️ Start processing command /merge


2025-08-04 11:33:04 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 0s (p90).


2025-08-04 13:33:18 UTCMergeQueue: The build pipeline has timeout

The merge request has been interrupted because the build 0 took longer than expected. The current limit for the base branch 'master' is 120 minutes.

Possible reasons:

  • target branch of PR is restricted to only allow up-to-date branches, but the pr is now outdated

@yoannmoinet
yoannmoinet enabled auto-merge August 4, 2025 13:45
@yoannmoinet
yoannmoinet merged commit 06ad51b into master Aug 4, 2025
5 checks passed
@yoannmoinet
yoannmoinet deleted the congyao/add-sourcemaps-and-telemetry branch August 4, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants