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

fix(vue): Update Vue trackComponents list to match components with or without <> #13543

Merged
merged 5 commits into from
Sep 9, 2024

Conversation

Zen-cronic
Copy link
Contributor

Resolves #13510

Tests to be added.

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

…or without `<>`

Signed-off-by: Kaung Zin Hein <kaungzinhein113@gmail.com>
if (!(currentCompo.startsWith('<') && currentCompo.endsWith('>'))) {
currentCompo = `<${currentCompo}>`;
}
return formattedName === currentCompo;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

formattedName from formatComponentName() always return a name with < >.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, it can also be <Component> at Component.vue.

@Zen-cronic Zen-cronic marked this pull request as ready for review September 3, 2024 01:00
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Hey @Zen-cronic thanks for opening this PR!

The change looks good to me but I had a slightly more size-efficient solution.

Could you add a test as well? We already have a Vue 3 test E2E test application. I was thinking that we could set a trackComponents array option in the Sentry init call and adjust the pageload test that it also includes a ui.vue.* span for a component that matches one of the array entries.

If you don't have time, just let me know, then I'll add the test.

Comment on lines 52 to 57
let currentCompo = compo;

if (!(currentCompo.startsWith('<') && currentCompo.endsWith('>'))) {
currentCompo = `<${currentCompo}>`;
}
return formattedName === currentCompo;
Copy link
Member

Choose a reason for hiding this comment

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

I think we can replace this with a more bundle size efficient version:

Suggested change
let currentCompo = compo;
if (!(currentCompo.startsWith('<') && currentCompo.endsWith('>'))) {
currentCompo = `<${currentCompo}>`;
}
return formattedName === currentCompo;
return compo.replace(/^<(.*)>$/, '$1') === formattedName

Copy link
Member

Choose a reason for hiding this comment

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

Ah in this case we don't even need the block anymore but could inline it to the some call. So feel free to do that as well :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey, I've taken your approach and found that formattedName must also be replaced:

function findTrackComponent(trackComponents: string[], formattedName: string): boolean {

  function extractComponentName(name: string): string {
    return name.replace(/^<(.*)>(?:.*)?$/, "$1");
  }
  const isMatched = trackComponents.some(compo => {
    return    extractComponentName(formattedName) === extractComponentName(compo)
  }
  );
  return isMatched;
}

The regex is needed for both the user provided component and the formatted component.

  • User provided: either <App> or App
  • Formatted: either <App> or <App> at App.vue.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Good observation, you're right! Also, I didn't think about the <App> at App.vue case.

There's one unfortunate side effect of this regex though: It can lead to polynomial build up when evaluating an input. Given that we run extractComponentName on user input I'd rather not risk the (still unlikely but possible) chance of some kind of ReDoS attack (I used this ReDoS checker to test it)

I played around with the regex to make it safer and keep it linear and arrived at this one: /^<([^\s]*)>( at [^\s]*)?$
I think this should still cover all component names but would appreciate it if you could double check it as well :)

Also, since this logic is getting a little bit more involved now, could you add a couple of unit test for findTrackComponent? It's fine to export the function just for testing purposes btw. Thanks!

(I don't want to overburden you with tests btw, I just want to keep stuff like this covered and understandable for everyone. So if you don't have the time, just let me know. We appreciate your hard work either way!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, unit and e2e tests added.

@Lms24 Lms24 self-assigned this Sep 4, 2024
@Zen-cronic
Copy link
Contributor Author

Just read your comments and review, I'll take them up now. Thanks!

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Sorry, I realized I approved the PR yesterday on accident. Please don't mind the change request, I'm just putting it here so that we don't merge the PR accidentally before the extract name logic is resolved.

Signed-off-by: Kaung Zin Hein <kaungzinhein113@gmail.com>
*
*/
function extractComponentName(name: string): string {
return name.replace(/^<([^\s]*)>(?: at [^\s]*)?$/, '$1');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on what you suggested @Lms24, just an added non-capture group. The ReDoS Checker passes.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me, thanks!

Signed-off-by: Kaung Zin Hein <kaungzinhein113@gmail.com>
'sentry.op': 'ui.vue.mount',
'sentry.origin': 'auto.ui.vue',
},
description: 'Vue <<HomeView>>',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just making sure, are the double brackets intended? They're formatted here.

Copy link
Member

Choose a reason for hiding this comment

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

Good observation! I don't think they're intended. Let's remove them.

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes! We're almost there :)

@@ -122,3 +122,101 @@ test('sends a pageload transaction with a route name as transaction name if avai
},
});
});

test('sends a lifecycle span for the tracked HomeView component - with `<>`', async ({ page }) => {
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of an unfortunate and very intransparent limitation of our e2e test setup but we shouldn't navigate to the same route in more than one e2e test. The reason is that we execute them in parallel in CI and the waitForTransaction call from one test might actually resolve for a transaction in another test, depending on the condition in the callback.

To avoid this confusion, we generally create a new route for each test. Suggestion: Either we create new routes for the two new tests or we integrate them in already existing tests and simply check for the spans there. I'll let you make the call, I'm fine with either option.
Also, feel free to test both kinds trackComponent notations in one route/test :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey, thanks for the info. i decided to go with creating a new route, and grouped the different notations together in a single test.

Signed-off-by: Kaung Zin Hein <kaungzinhein113@gmail.com>
Group trackComponent tests together:
1. With <>
2. Without <>
3. Not tracked

Signed-off-by: Kaung Zin Hein <kaungzinhein113@gmail.com>
<h1>Demonstrating Component Tracking</h1>
<ComponentOneView />
<ComponentTwoView />
</template>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inspired by the sveltekit-2-svelte-5 test setup.

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Thanks a lot @Zen-cronic, looks great to me now!

By the way, the entire JS SDK team really appreciates your contributions! @mydea sent you a message with a small thank you gift on LinkedIn a couple of days ago, in case you missed it. If this message somehow got lost, please feel free to drop me or @mydea an email (email in GH bio) :)

@Lms24 Lms24 merged commit a7d3a9d into getsentry:develop Sep 9, 2024
124 checks passed
Lms24 added a commit that referenced this pull request Sep 9, 2024
This PR adds the external contributor to the CHANGELOG.md file, so that
they are credited for their contribution. See #13543

Co-authored-by: Lms24 <8420481+Lms24@users.noreply.github.com>
alexandresoro pushed a commit to alexandresoro/ouca that referenced this pull request Sep 12, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@sentry/node](https://github.com/getsentry/sentry-javascript/tree/master/packages/node) ([source](https://github.com/getsentry/sentry-javascript)) | dependencies | minor | [`8.26.0` -> `8.30.0`](https://renovatebot.com/diffs/npm/@sentry%2fnode/8.26.0/8.30.0) |
| [@sentry/react](https://github.com/getsentry/sentry-javascript/tree/master/packages/react) ([source](https://github.com/getsentry/sentry-javascript)) | dependencies | minor | [`8.26.0` -> `8.30.0`](https://renovatebot.com/diffs/npm/@sentry%2freact/8.26.0/8.30.0) |

---

### Release Notes

<details>
<summary>getsentry/sentry-javascript (@&#8203;sentry/node)</summary>

### [`v8.30.0`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8300)

[Compare Source](getsentry/sentry-javascript@8.29.0...8.30.0)

##### Important Changes

-   *feat(node): Add `kafkajs` integration ([#&#8203;13528](getsentry/sentry-javascript#13528

This release adds a new integration that instruments `kafkajs` library with spans and traces. This integration is
automatically enabled by default, but can be included with the `Sentry.kafkaIntegration()` import.

```js
Sentry.init({
  integrations: [Sentry.kafkaIntegration()],
});
```

##### Other Changes

-   feat(core): Allow adding measurements without global client ([#&#8203;13612](getsentry/sentry-javascript#13612))
-   feat(deps): Bump [@&#8203;opentelemetry/instrumentation-undici](https://github.com/opentelemetry/instrumentation-undici) from 0.5.0 to 0.6.0 ([#&#8203;13622](getsentry/sentry-javascript#13622))
-   feat(deps): Bump [@&#8203;sentry/cli](https://github.com/sentry/cli) from 2.33.0 to 2.35.0 ([#&#8203;13624](getsentry/sentry-javascript#13624))
-   feat(node): Use `@opentelemetry/instrumentation-undici` for fetch tracing ([#&#8203;13485](getsentry/sentry-javascript#13485))
-   feat(nuxt): Add server config to root folder ([#&#8203;13583](getsentry/sentry-javascript#13583))
-   feat(otel): Upgrade [@&#8203;opentelemetry/semantic-conventions](https://github.com/opentelemetry/semantic-conventions) to 1.26.0 ([#&#8203;13631](getsentry/sentry-javascript#13631))
-   fix(browser): check supportedEntryTypes before caling the function ([#&#8203;13541](getsentry/sentry-javascript#13541))
-   fix(browser): Ensure Standalone CLS span timestamps are correct ([#&#8203;13649](getsentry/sentry-javascript#13649))
-   fix(nextjs): Widen removal of 404 transactions ([#&#8203;13628](getsentry/sentry-javascript#13628))
-   fix(node): Remove ambiguity and race conditions when matching local variables to exceptions ([#&#8203;13501](getsentry/sentry-javascript#13501))
-   fix(node): Update OpenTelemetry instrumentation package for solidstart and opentelemetry ([#&#8203;13640](getsentry/sentry-javascript#13640))
-   fix(node): Update OpenTelemetry instrumentation package for solidstart and opentelemetry ([#&#8203;13642](getsentry/sentry-javascript#13642))
-   fix(vue): Ensure Vue `trackComponents` list matches components with or without `<>` ([#&#8203;13543](getsentry/sentry-javascript#13543))
-   ref(profiling): Conditionally shim cjs globals ([#&#8203;13267](getsentry/sentry-javascript#13267))

Work in this release was contributed by [@&#8203;Zen-cronic](https://github.com/Zen-cronic) and [@&#8203;odanado](https://github.com/odanado). Thank you for your contributions!

### [`v8.29.0`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8290)

[Compare Source](getsentry/sentry-javascript@8.28.0...8.29.0)

##### Important Changes

-   **Beta releases of official Solid and SolidStart Sentry SDKs**

This release marks the beta releases of the `@sentry/solid` and `@sentry/solidstart` Sentry SDKs. For details on how to
use them, check out the
[Sentry Solid SDK README](https://github.com/getsentry/sentry-javascript/tree/develop/packages/solid) and the
[Sentry SolidStart SDK README](https://github.com/getsentry/sentry-javascript/tree/develop/packages/solidstart)
respectively. Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have
any feedback or concerns.

-   **feat(node): Option to only wrap instrumented modules ([#&#8203;13139](getsentry/sentry-javascript#13139

Adds the SDK option to only wrap ES modules with `import-in-the-middle` that specifically need to be instrumented.

```javascript
import * as Sentry from '@&#8203;sentry/node';

Sentry.init({
  dsn: '__PUBLIC_DSN__',
  registerEsmLoaderHooks: { onlyIncludeInstrumentedModules: true },
});
```

-   **feat(node): Update OpenTelemetry packages to instrumentation v0.53.0 ([#&#8203;13587](getsentry/sentry-javascript#13587

All internal OpenTelemetry instrumentation was updated to their latest version. This adds support for Mongoose v7 and v8
and fixes various bugs related to ESM mode.

##### Other Changes

-   feat(nextjs): Emit warning when using turbopack ([#&#8203;13566](getsentry/sentry-javascript#13566))
-   feat(nextjs): Future-proof Next.js config options overriding ([#&#8203;13586](getsentry/sentry-javascript#13586))
-   feat(node): Add `generic-pool` integration ([#&#8203;13465](getsentry/sentry-javascript#13465))
-   feat(nuxt): Upload sourcemaps generated by Nitro ([#&#8203;13382](getsentry/sentry-javascript#13382))
-   feat(solidstart): Add `browserTracingIntegration` by default ([#&#8203;13561](getsentry/sentry-javascript#13561))
-   feat(solidstart): Add `sentrySolidStartVite` plugin to simplify source maps upload ([#&#8203;13493](getsentry/sentry-javascript#13493))
-   feat(vue): Only start UI spans if parent is available ([#&#8203;13568](getsentry/sentry-javascript#13568))
-   fix(cloudflare): Guard `context.waitUntil` call in request handler ([#&#8203;13549](getsentry/sentry-javascript#13549))
-   fix(gatsby): Fix assets path for sourcemaps upload ([#&#8203;13592](getsentry/sentry-javascript#13592))
-   fix(nextjs): Use posix paths for sourcemap uploads ([#&#8203;13603](getsentry/sentry-javascript#13603))
-   fix(node-fetch): Use stringified origin url ([#&#8203;13581](getsentry/sentry-javascript#13581))
-   fix(node): Replace dashes in `generic-pool` span origins with underscores ([#&#8203;13579](getsentry/sentry-javascript#13579))
-   fix(replay): Fix types in WebVitalData ([#&#8203;13573](getsentry/sentry-javascript#13573))
-   fix(replay): Improve replay web vital types ([#&#8203;13602](getsentry/sentry-javascript#13602))
-   fix(utils): Keep logger on carrier ([#&#8203;13570](getsentry/sentry-javascript#13570))

Work in this release was contributed by [@&#8203;Zen-cronic](https://github.com/Zen-cronic). Thank you for your contribution!

### [`v8.28.0`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8280)

[Compare Source](getsentry/sentry-javascript@8.27.0...8.28.0)

##### Important Changes

-   **Beta release of official NestJS SDK**

This release contains the beta version of `@sentry/nestjs`! For details on how to use it, check out the
[README](https://github.com/getsentry/sentry-javascript/blob/master/packages/nestjs/README.md). Any feedback/bug reports
are greatly appreciated, please reach out on GitHub.

-   **fix(browser): Remove faulty LCP, FCP and FP normalization logic ([#&#8203;13502](getsentry/sentry-javascript#13502

This release fixes a bug in the `@sentry/browser` package and all SDKs depending on this package (e.g. `@sentry/react`
or `@sentry/nextjs`) that caused the SDK to send incorrect web vital values for the LCP, FCP and FP vitals. The SDK
previously incorrectly processed the original values as they were reported from the browser. When updating your SDK to
this version, you might experience an increase in LCP, FCP and FP values, which potentially leads to a decrease in your
performance score in the Web Vitals Insights module in Sentry. This is because the previously reported values were
smaller than the actually measured values. We apologize for the inconvenience!

##### Other Changes

-   feat(nestjs): Add `SentryGlobalGraphQLFilter` ([#&#8203;13545](getsentry/sentry-javascript#13545))
-   feat(nestjs): Automatic instrumentation of nestjs interceptors after route execution ([#&#8203;13264](getsentry/sentry-javascript#13264))
-   feat(nextjs): Add `bundleSizeOptimizations` to build options ([#&#8203;13323](getsentry/sentry-javascript#13323))
-   feat(nextjs): Stabilize `captureRequestError` ([#&#8203;13550](getsentry/sentry-javascript#13550))
-   feat(nuxt): Wrap config in nuxt context ([#&#8203;13457](getsentry/sentry-javascript#13457))
-   feat(profiling): Expose profiler as top level primitive ([#&#8203;13512](getsentry/sentry-javascript#13512))
-   feat(replay): Add layout shift to CLS replay data ([#&#8203;13386](getsentry/sentry-javascript#13386))
-   feat(replay): Upgrade rrweb packages to 2.26.0 ([#&#8203;13483](getsentry/sentry-javascript#13483))
-   fix(cdn): Do not mangle \_metadata ([#&#8203;13426](getsentry/sentry-javascript#13426))
-   fix(cdn): Fix SDK source for CDN bundles ([#&#8203;13475](getsentry/sentry-javascript#13475))
-   fix(nestjs): Check arguments before instrumenting with `@Injectable` ([#&#8203;13544](getsentry/sentry-javascript#13544))
-   fix(nestjs): Ensure exception and host are correctly passed on when using [@&#8203;WithSentry](https://github.com/WithSentry) ([#&#8203;13564](getsentry/sentry-javascript#13564))
-   fix(node): Suppress tracing for transport request execution rather than transport creation ([#&#8203;13491](getsentry/sentry-javascript#13491))
-   fix(replay): Consider more things as DOM mutations for dead clicks ([#&#8203;13518](getsentry/sentry-javascript#13518))
-   fix(vue): Correctly obtain component name ([#&#8203;13484](getsentry/sentry-javascript#13484))

Work in this release was contributed by [@&#8203;leopoldkristjansson](https://github.com/leopoldkristjansson), [@&#8203;mhuggins](https://github.com/mhuggins) and [@&#8203;filips123](https://github.com/filips123). Thank you for your
contributions!

### [`v8.27.0`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8270)

[Compare Source](getsentry/sentry-javascript@8.26.0...8.27.0)

##### Important Changes

-   **fix(nestjs): Exception filters in main app module are not being executed ([#&#8203;13278](getsentry/sentry-javascript#13278

    With this release nestjs error monitoring is no longer automatically set up after adding the `SentryModule` to your
    application, which led to issues in certain scenarios. You will now have to either add the `SentryGlobalFilter` to
    your main module providers or decorate the `catch()` method in your existing global exception filters with the newly
    released `@WithSentry()` decorator. See the [docs](https://docs.sentry.io/platforms/javascript/guides/nestjs/) for
    more details.

##### Other Changes

-   feat: Add options for passing nonces to feedback integration ([#&#8203;13347](getsentry/sentry-javascript#13347))
-   feat: Add support for SENTRY_SPOTLIGHT env var in Node ([#&#8203;13325](getsentry/sentry-javascript#13325))
-   feat(deps): bump [@&#8203;prisma/instrumentation](https://github.com/prisma/instrumentation) from 5.17.0 to 5.18.0 ([#&#8203;13327](getsentry/sentry-javascript#13327))
-   feat(feedback): Improve error message for 403 errors ([#&#8203;13441](getsentry/sentry-javascript#13441))
-   fix(deno): Don't rely on `Deno.permissions.querySync` ([#&#8203;13378](getsentry/sentry-javascript#13378))
-   fix(replay): Ensure we publish replay CDN bundles ([#&#8203;13437](getsentry/sentry-javascript#13437))

Work in this release was contributed by [@&#8203;charpeni](https://github.com/charpeni). Thank you for your contribution!

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC41NS4zIiwidXBkYXRlZEluVmVyIjoiMzguNzMuNyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19-->

Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/61
Reviewed-by: Alexandre Soro <code@soro.dev>
Co-authored-by: renovate <renovate@git.tristess.app>
Co-committed-by: renovate <renovate@git.tristess.app>
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.

Vue trackComponents allowlist should match for components without <>
2 participants