Skip to content

Add tree shakable path for trace instrumentation#9730

Open
MaesterChestnut wants to merge 3 commits intocrashlytics-tracingfrom
bundleInvestigation
Open

Add tree shakable path for trace instrumentation#9730
MaesterChestnut wants to merge 3 commits intocrashlytics-tracingfrom
bundleInvestigation

Conversation

@MaesterChestnut
Copy link

No description provided.

@MaesterChestnut MaesterChestnut requested a review from a team as a code owner March 18, 2026 18:30
@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2026

⚠️ No Changeset found

Latest commit: 78b9147

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the tree-shaking capabilities of the crashlytics package by providing granular control over OpenTelemetry tracing instrumentations. By introducing dedicated, tree-shakable entry points for fetch and XHR instrumentations, the changes allow applications to include only the necessary tracing code, leading to smaller bundle sizes and improved performance. The core tracing provider is now more modular, enabling selective instrumentation based on application needs.

Highlights

  • Tree-shakable Instrumentation Paths: Introduced new top-level entry points (./fetch and ./xhr) in the crashlytics package, allowing consumers to import and register OpenTelemetry FetchInstrumentation and XMLHttpRequestInstrumentation independently. This enables better tree-shaking, ensuring that instrumentation code is only bundled when explicitly used.
  • Build Configuration Updates: Modified package.json to include "sideEffects": false for the crashlytics package, signaling to bundlers that modules within the package can be safely tree-shaken. New exports entries were added for the ./fetch and ./xhr paths, defining their respective type, node, and browser module resolutions. The rollup.config.js was updated to generate the necessary CJS and ES module bundles for these new entry points across different environments.
  • OpenTelemetry Integration Refinement: Decoupled the registration of FetchInstrumentation from the createTracingProvider function. Instead of automatic registration, registerFetchInstrumentation and registerXHRInstrumentation functions are now provided, giving developers explicit control over which instrumentations are enabled. This change also involved updating several OpenTelemetry related dependencies in yarn.lock.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces tree-shakable entry points for fetch and XHR trace instrumentations, which is a great improvement for bundle size optimization. The changes involve updating package.json with new exports, adding rollup configurations for the new entry points, and moving the instrumentation registration logic to be opt-in. My feedback focuses on reducing code duplication in the build configuration to improve maintainability.

Comment on lines +63 to 96
{
input: 'fetch.ts',
output: [
{
file: pkg.exports['./fetch'].browser.require,
format: 'cjs',
sourcemap: true
},
{
file: pkg.exports['./fetch'].browser.import,
format: 'es',
sourcemap: true
}
],
plugins: buildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
{
input: 'xhr.ts',
output: [
{
file: pkg.exports['./xhr'].browser.require,
format: 'cjs',
sourcemap: true
},
{
file: pkg.exports['./xhr'].browser.import,
format: 'es',
sourcemap: true
}
],
plugins: buildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability and reduce code duplication, you could generate these almost identical build configurations for fetch and xhr using a loop or a map function. This would make it easier to add more instrumentation entry points in the future.

...['fetch', 'xhr'].map(name => ({
  input: `${name}.ts`,
  output: [
    {
      file: pkg.exports[`./${name}`].browser.require,
      format: 'cjs',
      sourcemap: true
    },
    {
      file: pkg.exports[`./${name}`].browser.import,
      format: 'es',
      sourcemap: true
    }
  ],
  plugins: buildPlugins,
  external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}))

Comment on lines +124 to 157
{
input: 'fetch.ts',
output: [
{
file: pkg.exports['./fetch'].node.default,
format: 'cjs',
sourcemap: true
},
{
file: pkg.exports['./fetch'].node.import,
format: 'es',
sourcemap: true
}
],
plugins: buildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
{
input: 'xhr.ts',
output: [
{
file: pkg.exports['./xhr'].node.default,
format: 'cjs',
sourcemap: true
},
{
file: pkg.exports['./xhr'].node.import,
format: 'es',
sourcemap: true
}
],
plugins: buildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the browser builds, you can refactor this duplicated configuration for node builds to improve maintainability by generating them programmatically.

...['fetch', 'xhr'].map(name => ({
  input: `${name}.ts`,
  output: [
    {
      file: pkg.exports[`./${name}`].node.default,
      format: 'cjs',
      sourcemap: true
    },
    {
      file: pkg.exports[`./${name}`].node.import,
      format: 'es',
      sourcemap: true
    }
  ],
  plugins: buildPlugins,
  external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}))

Copy link

@andrewbrook andrewbrook left a comment

Choose a reason for hiding this comment

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

Why would someone enable instrumentation for one method but not the other? Do you expect to add more options in the future?

@MaesterChestnut
Copy link
Author

Why would someone enable instrumentation for one method but not the other? Do you expect to add more options in the future?

Yea, we will add quite a few more instrumentation libraries and I think clients will only want to pull in ones they plan on needing support for. I think we'll also want to provide an option for them to pull in all instrumentation options if they don't know what they need.

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.

2 participants