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

[plugin] RUM plugin #78

merged 60 commits into from
Jul 10, 2024

Conversation

yoannmoinet
Copy link
Member

@yoannmoinet yoannmoinet commented Jun 6, 2024

Note

Stacked on #82

What and why?

Adding a new customer facing plugin to let them upload sourcemaps at the end of a build.

rum?: {
    disabled?: boolean;
    sourcemaps?: {
        basePath: string;
        dryRun?: boolean;
        maxConcurrency?: number;
        minifiedPathPrefix?: string;
        releaseVersion: string;
        service: string;
    };
}

I followed datadog-ci's implementation but re-wrote it entirely to make it leverage native primitives (like fetch). And straightened its helpers.

I could have imported datadog-ci directly, but this was bringing A TON of unnecessary dependencies, so I decided to re-wrote it.

Note

This also slightly changes how the git internal plugin works. It will only enable it if the sourcemaps plugin is enabled.

How?

This is a sub-plugin of the higher order rum plugin.
Added some configuration validation, as well as a lot of tests for the added functionality.

I've also split out the git internal plugin in #82 so we keep this one more digest to review.

The implementation is pretty straight-forward:

  1. glob sourcemaps files.
  2. construct payloads.
  3. send it all to Datadog.

In the future I'd like to:

  • deduct the basePath from the bundler's config.
  • make it possible to upload to more than one DC in one go.
  • remove the dependency on form-data to use the native one instead.

Finally, I tested the upload and it seemed to work as expected.

@yoannmoinet yoannmoinet changed the base branch from master to yoann/add-plugin-and-test-helpers June 7, 2024 14:27
Base automatically changed from yoann/add-plugin-and-test-helpers to master June 10, 2024 09:56
@yoannmoinet yoannmoinet force-pushed the yoann/rum-plugin branch 2 times, most recently from b477374 to 795c522 Compare June 10, 2024 15:01
@yoannmoinet yoannmoinet changed the base branch from master to yoann/move-telemetry June 10, 2024 15:01
Base automatically changed from yoann/move-telemetry to master June 10, 2024 15:32
@yoannmoinet yoannmoinet changed the base branch from master to yoann/core-plugins-update June 20, 2024 14:16
Comment on lines 104 to 108
// Using form-data as a dependency isn't really required.
// But this implementation makes it mandatory for the gzip step.
// NodeJS' fetch SHOULD support everything else from the native FormData primitive.
// content.options are totally optional and should only be filename.
// form.getHeaders() is natively handled by fetch and FormData.
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.

This one is a toughy, so any help will be appreciated.
Not blocking, but would be great to remove this dependency.

@yoannmoinet yoannmoinet marked this pull request as ready for review June 24, 2024 09:32
Copy link
Collaborator

@Miz85 Miz85 left a comment

Choose a reason for hiding this comment

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

LGTM! I have a few comments/suggestions but otherwise it looks good

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

Comment on lines +15 to +17
export const helpers = {
// Add the helpers you'd like to expose here.
};
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.

Comment on lines 15 to 17
// 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.


export const getApiUrl = (context: GlobalContext) => {
const siteUrl = context.auth?.endPoint || 'datadoghq.com';
return `https://sourcemap-intake.${siteUrl}/api/v2/srcmap`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: We could also make this pattern configurable if there's any chance it could change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same as prior, followed datadog-ci's implementation, where it's not configurable (yet).

https://github.com/DataDog/datadog-ci/blob/026557808bb4ca0756bac078b715f63c9c11bca7/src/helpers/base-intake-url.ts#L1-L9

I do see where it could be valuable to make it configurable, but I prefer to cross this bridge when we get there.

For the sake of simplicity.

Copy link
Member Author

Choose a reason for hiding this comment

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

ps: I'll add support for env vars in a separate PR as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔 this may be actually needed before we release this plugin after all, given that datadog-ci's offers the DATADOG_SOURCEMAP_INTAKE_URL.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added it in the last commit 19e3862

Base automatically changed from yoann/core-plugins-update to master June 25, 2024 07:58
@yoannmoinet yoannmoinet merged commit accae07 into master Jul 10, 2024
5 checks passed
@yoannmoinet yoannmoinet deleted the yoann/rum-plugin branch July 10, 2024 15:42
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