Skip to content

test(vue): Add tests for Vue tracing mixins #16486

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

Merged
merged 3 commits into from
Jun 5, 2025
Merged

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Jun 5, 2025

There were no tests yet for the Vue tracing mixins. To be more comfortable when continuing working on it, it's better to have some :D

@s1gr1d s1gr1d requested review from Lms24, AbhiPrasad and Copilot June 5, 2025 07:36
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds tests for the Vue tracing mixins to improve confidence while continuing development.

  • Introduces tests for creating mixins with default and custom lifecycle hooks
  • Covers root component behavior, component span lifecycle, and tracking configuration options
Comments suppressed due to low confidence (1)

packages/vue/test/tracing/tracingMixin.test.ts:131

  • Consider addressing the todo/fixme by clarifying the intended behavior of the root span when trackComponents is false, or by updating the test to cover both scenarios.
      // todo/fixme: This root span is only finished if trackComponents is true --> it should probably be always finished

});

it('should finish root span on timer after component spans end', () => {
// todo/fixme: This root span is only finished if trackComponents is true --> it should probably be always finished
Copy link
Member Author

@s1gr1d s1gr1d Jun 5, 2025

Choose a reason for hiding this comment

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

maybe someone knows more here about the wanted behavior 🤔

Copy link
Member

Choose a reason for hiding this comment

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

hmm this looks like a bug then? according to this code trackComponents shouldn't influence the root component span. Feel free to fix directly or follow up with another PR. Whatever you prefer :) (let me know if I should fix it in case you're booked, also fine!)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's always starting the span, but not ending it

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 adding these tests! good to have this covered 🙏

My only ask would be to avoid confusion around "root span" vs. "root component span". We both know that "root span" here refers to the spans for the root component but the next person might confuse this with the actual trace root span.

});

describe('Root Component Behavior', () => {
it('should always create root span for root component regardless of tracking options', () => {
Copy link
Member

Choose a reason for hiding this comment

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

l: Just to avoid confusion: We're talking about a span for the root component, right? Not to confuse with a root (i.e. parentless) span?

Suggested change
it('should always create root span for root component regardless of tracking options', () => {
it('should always create root component span for root component regardless of tracking options', () => {

it('should always create root span for root component regardless of tracking options', () => {
const mixins = createTracingMixins({ trackComponents: false });

mixins.beforeMount.call(mockRootInstance);
Copy link
Member

Choose a reason for hiding this comment

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

q (for my understanding mostly): What happens if I call something like beforeCreate or another hook coming in prior to the mount hook? the span would end if the -ed hook emits, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Each operation (create, mount, ...) has its own independent span that is stored in the component's $_sentrySpans object. And only if this operation is stored in there (like create) it will end only if the created is emitted and the create span is available in the $_sentrySpans object.

Comment on lines 211 to 223
it('should respect tracking configuration options', () => {
// Test different tracking configurations with the same component
const runTracingTest = (trackComponents: boolean | string[] | undefined, shouldTrack: boolean) => {
vi.clearAllMocks();
const mixins = createTracingMixins({ trackComponents });
mixins.beforeMount.call(mockVueInstance);

if (shouldTrack) {
expect(startInactiveSpan).toHaveBeenCalled();
} else {
expect(startInactiveSpan).not.toHaveBeenCalled();
}
};
Copy link
Member

@Lms24 Lms24 Jun 5, 2025

Choose a reason for hiding this comment

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

l: It feels like we're running multiple scenarios within one test here which I think we can better illustrate by using it.each and/or splitting tests up a bit. For example, two scenarios should lead to a span being started, while two should not. Those are already two different branches.

The two advantages of running individual tests here are:

  • we can directly identify which scenario passes/fails
  • we can avoid the shouldTrack branching in the test all together. IMHO unit tests should almost never contain conditional assertions as this usually indicates testing different expected outcomes in one test. (Sometimes there's an argument for this in case there'd be a lot of code to repeat but in this case I think we can avoid repetition pretty well)

happy to let you make the call on this, so feel free to disregard. Also maybe I missed a reason why the current form makes more sense.

});

it('should finish root span on timer after component spans end', () => {
// todo/fixme: This root span is only finished if trackComponents is true --> it should probably be always finished
Copy link
Member

Choose a reason for hiding this comment

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

hmm this looks like a bug then? according to this code trackComponents shouldn't influence the root component span. Feel free to fix directly or follow up with another PR. Whatever you prefer :) (let me know if I should fix it in case you're booked, also fine!)

@s1gr1d s1gr1d merged commit b1fd4a1 into develop Jun 5, 2025
39 checks passed
@s1gr1d s1gr1d deleted the sig/vue-tracing-tests branch June 5, 2025 10:19
Lms24 added a commit that referenced this pull request Jun 12, 2025
This PR fixes a bug discovered in
#16486 (comment)
where the root component span would not end correctly if
`trackComponents` was `false`.

Also added a comment to explain the purpose of the root component
`ui.vue.render` span. We might want to look into renaming or removing
this span in the future but for now, let's fix the behaviour.
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