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(tracing) Adding groups to trace via pw-api #33081

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Snooz82
Copy link

@Snooz82 Snooz82 commented Oct 14, 2024

This PR implements #33047 .

It shall be possible to add groups to trace logs so that also users that do not use Playwright-Test, like Playwright Python, Robot Framework, Cucumber etc., can also group their traces.
Similar to test.step visually.

This comment has been minimized.

This comment has been minimized.

@Snooz82
Copy link
Author

Snooz82 commented Oct 14, 2024

@microsoft-github-policy-service agree

Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

I agree with your choice of ignoring group()/groupEnd() calls when not tracing or when groupEnd() is unbalanced. That seems like the easiest one for the user.

We would need tests that should go into trace-viewer.spec.ts.
Take a look at testd like should have correct stack trace, should show action source and should open simple trace viewer. In the last one, I'd click on a group to expand/collapse it and check the actions list.

I think this should automatically work with the test runner if you follow my other comments. Adding a test similar to this one will ensure that.

Overall, this looks very promising, thank you!

packages/protocol/src/protocol.yml Outdated Show resolved Hide resolved
docs/src/api/class-tracing.md Outdated Show resolved Hide resolved
docs/src/api/class-tracing.md Outdated Show resolved Hide resolved
@@ -51,6 +52,18 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements ap
await this._startCollectingStacks(traceName);
}

async group(name: string, options: { location?: { file: string, line?: number, column?: number } } = {}) {
if (!options.location) {
const filteredStack = filteredStackTrace(captureRawStack());
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of handling the stack manually, we should fall back to the default machinery. That probably means calling _wrapApiCall() and introducing an extra parameter to pass a custom location to it, instead of taking the stack trace. This way you'll get source collection and other goodies for free.

You would also need to opt-out of this._isInternalType check inside to make this particular tracing.group() call public. I think that making isInternal argument be boolean | undefined will allow to differentiate explicit false to opt-into public call from default undefined which aligns with this._isInternalType.

Copy link
Author

Choose a reason for hiding this comment

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

Actually i do not really understand what you are talking about here, but can it be that this is all irrelevant when using metadata.location as i described in my comment before?

packages/playwright-core/src/utils/stackTrace.ts Outdated Show resolved Hide resolved

This comment has been minimized.

@Snooz82
Copy link
Author

Snooz82 commented Oct 14, 2024

@dgozman
Hi Dmitry,
Thanks for your feedback.
Yes i will of course write some test cases. With the hints you provided, i should be able to do them.

Update: Test written

This comment has been minimized.

@Snooz82 Snooz82 requested a review from dgozman October 14, 2024 22:07
@Snooz82 Snooz82 marked this pull request as ready for review October 14, 2024 22:07

This comment has been minimized.

@Snooz82
Copy link
Author

Snooz82 commented Oct 15, 2024

PS: It seems to me that you also have some flaky tests?

Is it possible to give the users that do PRs the right, to re-run failed actions?

@Snooz82
Copy link
Author

Snooz82 commented Oct 16, 2024

@pavelfeldman @dgozman
Would be really appreciated if someone could check my questions and give feedback what is missing.
This week i have still some time to do fixes or requested changes.

We would really love to see that in next Playwright Release, so that we could implement it in Robot Framework Browser as well.

Thank you.

@dgozman
Copy link
Contributor

dgozman commented Oct 16, 2024

@Snooz82 Sorry, I didn't get to this PR today, but I will tomorrow.

  • The Firefox bot will recover if you rebase your PR.
  • Re: protocol - yes, I was only talking about the internal client-server protocol, not the public API.
  • I still think that you'd need to follow my comment about location and _wrapApiCall, but I will be able to apply and try things myself tomorrow.

This comment has been minimized.

@Snooz82
Copy link
Author

Snooz82 commented Oct 16, 2024

@dgozman Thanks for the feedback.

  • fixed internal protocol to have location directly and not typed, but inline definition
  • improved docs (I do not know how to link to test.step from api docs.)

You may review again.
In my testing the metadata.location worked absolutely flawless but if you want to change to _wrapApiCall go ahead.

There is one limitation though.
Traces generated by Playwright Test do not correctly show the groups. They interfere with test.step but also without, they are not correctly handled in the actions tree. If i remove the test.trace and rename the 0-trace.trace etc. so that it is a normal trace, all groups work perfectly. I added therefore a hint to the docs.
Imho this limitation is mostly irrelevant, because Playwright Test users should use test.step anyway and Playwright Python, Java, C# and Robot Framework will not use Playwright Test at all.

Thanks for reviewing!
We are pretty exited about this coming into the core! ❤️

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Snooz82
Copy link
Author

Snooz82 commented Oct 18, 2024

Hi @dgozman,

I am sorry that i might be annoying.
But if there is anything that i need to do, i could do it at the weekend.
Otherwise, if you want to take over and improve it to a mergeable state, that is also fine.

Thank you.

Signed-off-by: René <[email protected]>
Signed-off-by: René <[email protected]>
Signed-off-by: René <[email protected]>
Signed-off-by: René <[email protected]>

This comment has been minimized.

Copy link
Contributor

Test results for "tests 1"

3 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-3.spec.ts:171:7 › cli codegen › should generate frame locators (4) @firefox-ubuntu-22.04-node18
⚠️ [webkit-library] › library/screenshot.spec.ts:42:14 › page screenshot › should work with a mobile viewport @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/screenshot.spec.ts:64:14 › page screenshot › should work with a mobile viewport and fullPage @webkit-ubuntu-22.04-node18

36402 passed, 639 skipped
✔️✔️✔️

Merge workflow run.

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