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

feat: log shadow mode through engine reporting API #3878

Merged
merged 4 commits into from
Dec 5, 2023

Conversation

jye-sf
Copy link
Contributor

@jye-sf jye-sf commented Nov 22, 2023

Details

Adds telemetry for shadow mode usage (synthetic vs native).

Due to the volume of logs this is going to generate (easily TBs), we'll want to report this as a metric rather than as logs. This will require updating our API to distinguish between logs and metrics (e.g. incrementCounter, log()). We may also want to refactor the existing report API into log.

This aligns the runtime reporting with our compiler instrumentation:
https://github.com/salesforce/lwc/blob/6e75634e16a21c500d5e3f45400d1db3da3f5346/packages/%40lwc/errors/src/compiler/instrumentation.ts

Alternatively, we can make this decision in the consuming app container. (e.g. if (reportName === 'ShadowModeUsage') { ... }). However, that would require each consuming app to know which reporting events require special handling. The app containers would also be taking a new dependency on the event names, which is not ideal.

To make it easier to backport, we can introduce only the new API in patch and do the refactoring only in master.

Note: this should be done before LWR picks up their dependency to add reporting to the LWR container.

Does this pull request introduce a breaking change?

  • ✅ No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • ✅ No, it does not introduce an observable change.

GUS work item

@jye-sf jye-sf marked this pull request as ready for review November 27, 2023 22:30
@jye-sf jye-sf requested a review from a team as a code owner November 27, 2023 22:30
@jye-sf
Copy link
Contributor Author

jye-sf commented Nov 28, 2023

/nucleus test

@jye-sf
Copy link
Contributor Author

jye-sf commented Nov 28, 2023

Triggered a rerun of the karma tests this morning and they all pass now: https://github.com/salesforce/lwc/actions/runs/6962982231

@jye-sf jye-sf changed the base branch from master to spring24 November 28, 2023 23:48
@jye-sf jye-sf changed the base branch from spring24 to master November 28, 2023 23:48
@jye-sf
Copy link
Contributor Author

jye-sf commented Nov 28, 2023

PR into master needs to be updated with the log/incrementCounter API changes, but this PR as it is now is backportable into spring24.

@jye-sf jye-sf added nomerge and removed nomerge labels Nov 29, 2023
@jye-sf
Copy link
Contributor Author

jye-sf commented Nov 29, 2023

We can merge as-is with the single reporting API and make the appropriate determinations on log vs incrementCounter at the app level.

Copy link
Contributor

@nolanlawson nolanlawson 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 overall, very minor feedback so I'm marking as ✅

mode: vm.shadowMode,
});
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I checked, and this gets tree-shaken if the customer is not using the reporting API! 🎉

@@ -10,11 +14,11 @@ if (process.env.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL) {

beforeEach(() => {
dispatcher = jasmine.createSpy();
reportingControl.attachDispatcher(dispatcher);
attachReportingControlDispatcher(dispatcher, ['NonStandardAriaReflection']);
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome!!

dispatch[1].tagName === 'x-aria-source' &&
dispatch[1].attributeName === 'aria-labelledby'
)
).toHaveSize(2);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is less clear than the previous (equivalent) code. I would prefer to change it back, but I also don't have a really strong opinion, since it's just test code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This variation is less strict about whether the dispatcher includes calls for other events. The previous code broke with the addition of new reporting events, while this one would not.

I'm fine changing it back since it's less critical to have that distinction with the new helper function. The previous behavior would still be asserting that the dispatcher is called twice for CrossRootAriaInSyntheticShadow AND zero times for NonStandardAriaReflection, but that's behavior less likely to break in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep that's exactly what I was thinking – let's use the new attachReportingControlDispatcher to control the filtering, rather than doing it here.

tagName: 'x-component',
mode: process.env.NATIVE_SHADOW ? ShadowMode.Native : ShadowMode.Synthetic,
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add a test here for CustomElementConstructor since it has its own slightly different code path (doesn't use lwc.createElement()).

It would also make sense to add a test for a light-DOM component, to ensure that it reports nothing.

@jye-sf jye-sf merged commit 0b04c8c into master Dec 5, 2023
9 checks passed
@jye-sf jye-sf deleted the jye/report-shadow-mode branch December 5, 2023 07:14
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.

None yet

2 participants