Skip to content

[rum-privacy] add sourcemaps and telemetry #187

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

cy-moi
Copy link
Contributor

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

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
Copy link

@sethfowler-datadog sethfowler-datadog left a comment

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:

Copy link
Member

@yoannmoinet yoannmoinet left a comment

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.

pluginOptions.module === 'cjs' ? './privacy-helpers.js' : './privacy-helpers.mjs',
);

const privacyHelpersModuleId = pluginOptions.helpersModule ?? PRIVACY_HELPERS_MODULE_ID;
Copy link
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().

@cy-moi cy-moi force-pushed the congyao/add-sourcemaps-and-telemetry branch from ff4c50b to cdbd040 Compare July 15, 2025 13:15
Copy link
Member

@yoannmoinet yoannmoinet left a comment

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 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
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?

Copy link
Contributor Author

@cy-moi cy-moi Jul 15, 2025

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.

@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
Copy link
Member

@yoannmoinet yoannmoinet left a comment

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
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
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.

Comment on lines 27 to 28
"./dist-basic/src": "./dist-basic/src/index.js",
"./dist-basic/src/*": "./dist-basic/src/*",
Copy link
Member

Choose a reason for hiding this comment

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

I believe this got removed automatically once again.
The process has been fixed in a separate branch.

@@ -55,12 +55,15 @@ export const getPlugins: GetPlugins = ({ options, context }) => {
});
}

if (validatedOptions.privacy) {
if (validatedOptions.privacy && !validatedOptions.privacy.disabled) {
Copy link
Member

Choose a reason for hiding this comment

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

NIT: This should be handled in the validate process.
The same as for the sdk counterpart.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the privacy.disabled option as well, per bug bash feedback.

@@ -35,7 +35,7 @@ describe('RUM Plugin', () => {
},
{
type: 'sdk',
config: { sdk: { applicationId: 'app-id' } },
config: { sdk: { applicationId: 'app-id', clientToken: '123' } },
Copy link
Member

Choose a reason for hiding this comment

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

Weird, what was the issue with this, how did we miss it before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no longer an issue after restoring to previous types. clientToken is not required. I restored this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants