-
Notifications
You must be signed in to change notification settings - Fork 3.4k
misc: write command durations to a csv file #32938
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
Draft
cacieprins
wants to merge
18
commits into
develop
Choose a base branch
from
csv-benchmark
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+785
−91
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a92cd96
perf log automation command
cacieprins b938ad7
write a performance log entry for each command
cacieprins 6ca1bb1
better log entries
cacieprins ef2acf7
changelog
cacieprins b66121a
Merge branch 'develop' into csv-benchmark
cacieprins 39aa6f2
esc
cacieprins 0aa7f21
fail with debug entry if error thrown initializing perf log
cacieprins 8b2e515
reduce serialization
cacieprins 32afcfb
Merge branch 'develop' into csv-benchmark
cacieprins d80bf84
ts
cacieprins 7d56e1b
Merge branch 'develop' into csv-benchmark
cacieprins 39d87cb
back out of async/await modification to command queue
cacieprins 8b4879c
dont throw if automation throws
cacieprins d0af3eb
Merge branch 'develop' into csv-benchmark
cacieprins 0e83ccc
rm numElements - causes serialization issues??
cacieprins 7084eaf
refactor to performance marks, clean up telemetry on the client, make…
cacieprins 6c79da7
fix automation spy assertion to be more precise, fix ts err
cacieprins 40c2e5f
Merge branch 'develop' into csv-benchmark
cacieprins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,104 +1,149 @@ | ||
| import { telemetry } from '@packages/telemetry/browser/client' | ||
|
|
||
| export const addTelemetryListeners = (Cypress: Cypress.Cypress) => { | ||
| Cypress.on('test:before:run', (attributes, test) => { | ||
| // we emit the 'test:before:run' events within various driver tests | ||
| try { | ||
| // If a span for a previous test hasn't been ended, end it before starting the new test span | ||
| const previousTestSpan = telemetry.findActiveSpan((span) => { | ||
| return span.name.startsWith('test:') | ||
| }) | ||
|
|
||
| if (previousTestSpan) { | ||
| telemetry.endActiveSpanAndChildren(previousTestSpan) | ||
| } | ||
| function startTestOtelSpan (attributes: Cypress.ObjectLike, test: Mocha.Test) { | ||
| // we emit the 'test:before:run' events within various driver tests | ||
| try { | ||
| // If a span for a previous test hasn't been ended, end it before starting the new test span | ||
| const previousTestSpan = telemetry.findActiveSpan((span) => { | ||
| return span.name.startsWith('test:') | ||
| }) | ||
|
|
||
| if (previousTestSpan) { | ||
| telemetry.endActiveSpanAndChildren(previousTestSpan) | ||
| } | ||
|
|
||
| const span = telemetry.startSpan({ name: `test:${test.fullTitle()}`, active: true }) | ||
| const span = telemetry.startSpan({ name: `test:${test.fullTitle()}`, active: true }) | ||
|
|
||
| span?.setAttributes({ | ||
| currentRetry: attributes.currentRetry, | ||
| }) | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| } | ||
| }) | ||
| span?.setAttributes({ | ||
| currentRetry: attributes.currentRetry, | ||
| }) | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| } | ||
| } | ||
|
|
||
| Cypress.on('test:after:run', (attributes, test) => { | ||
| try { | ||
| const span = telemetry.getSpan(`test:${test.fullTitle()}`) | ||
| function endTestOtelSpan (attributes: Cypress.ObjectLike, test: Mocha.Test) { | ||
| try { | ||
| const span = telemetry.getSpan(`test:${test.fullTitle()}`) | ||
|
|
||
| span?.setAttributes({ | ||
| timings: JSON.stringify(attributes.timings), | ||
| }) | ||
| span?.setAttributes({ | ||
| timings: JSON.stringify(attributes.timings), | ||
| }) | ||
|
|
||
| span?.end() | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| } | ||
| }) | ||
| span?.end() | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| } | ||
| } | ||
|
|
||
| const commandSpanInfo = (command: Cypress.CommandQueue) => { | ||
| const runnable = Cypress.state('runnable') | ||
| const runnableType = runnable.type === 'hook' ? runnable.hookName : runnable.type | ||
| const commandSpanInfo = (command: Cypress.CommandQueue) => { | ||
| const runnable = Cypress.state('runnable') | ||
| const runnableType = runnable.type === 'hook' ? runnable.hookName : runnable.type | ||
|
|
||
| return { | ||
| name: `${runnableType}: ${command.attributes.name}(${command.attributes.args.join(',')})`, | ||
| runnable, | ||
| runnableType, | ||
| } | ||
| return { | ||
| name: `${runnableType}: ${command.attributes.name}(${command.attributes.args.join(',')})`, | ||
| runnable, | ||
| runnableType, | ||
| } | ||
| } | ||
|
|
||
| Cypress.on('command:start', (command: Cypress.CommandQueue) => { | ||
| try { | ||
| const test = Cypress.state('test') | ||
|
|
||
| const { name, runnable, runnableType } = commandSpanInfo(command) | ||
|
|
||
| const span = telemetry.startSpan({ | ||
| name, | ||
| opts: { | ||
| attributes: { | ||
| spec: runnable.invocationDetails.relativeFile, | ||
| test: `test:${test.fullTitle()}`, | ||
| 'runnable-type': runnableType, | ||
| }, | ||
| function startCommandOtelSpan (command: Cypress.CommandQueue) { | ||
| try { | ||
| const test = Cypress.state('test') | ||
|
|
||
| const { name, runnable, runnableType } = commandSpanInfo(command) | ||
|
|
||
| const span = telemetry.startSpan({ | ||
| name, | ||
| opts: { | ||
| attributes: { | ||
| spec: runnable.invocationDetails.relativeFile, | ||
| test: `test:${test.fullTitle()}`, | ||
| 'runnable-type': runnableType, | ||
| }, | ||
| isVerbose: true, | ||
| }) | ||
| }, | ||
| isVerbose: true, | ||
| }) | ||
|
|
||
| span?.setAttribute('command-name', command.attributes.name) | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| } | ||
| }) | ||
| span?.setAttribute('command-name', command.attributes.name) | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| } | ||
| } | ||
|
|
||
| const onCommandEnd = (command: Cypress.CommandQueue) => { | ||
| try { | ||
| const span = telemetry.getSpan(commandSpanInfo(command).name) | ||
| function endCommandOtelSpan (command: Cypress.CommandQueue) { | ||
| try { | ||
| const span = telemetry.getSpan(commandSpanInfo(command).name) | ||
|
|
||
| span?.setAttribute('state', command.state) | ||
| span?.setAttribute('numLogs', command.logs?.length || 0) | ||
| span?.end() | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| } | ||
| span?.setAttribute('state', command.state) | ||
| span?.setAttribute('numLogs', command.logs?.length || 0) | ||
| span?.end() | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| } | ||
| } | ||
|
|
||
| Cypress.on('command:end', onCommandEnd) | ||
| function failCommandOtelSpan (command: Cypress.CommandQueue, error: Error) { | ||
| try { | ||
| const span = telemetry.getSpan(commandSpanInfo(command).name) | ||
|
|
||
| Cypress.on('skipped:command:end', onCommandEnd) | ||
| span?.setAttribute('state', command.state) | ||
| span?.setAttribute('numLogs', command.logs?.length || 0) | ||
| span?.setAttribute('error.name', error.name) | ||
| span?.setAttribute('error.message', error.message) | ||
| span?.end() | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| } | ||
| } | ||
|
|
||
| Cypress.on('command:failed', (command: Cypress.CommandQueue, error: Error) => { | ||
| function startCommandPerformanceMark (command: Cypress.CommandQueue) { | ||
| try { | ||
| performance.mark(`cy:command:${command.attributes.id}:start`) | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| } | ||
| } | ||
|
|
||
| function endCommandPerformanceMark (Cypress: Cypress.Cypress) { | ||
| return (command: Cypress.CommandQueue) => { | ||
| try { | ||
| const span = telemetry.getSpan(commandSpanInfo(command).name) | ||
| const { id } = command.attributes | ||
|
|
||
| performance.mark(`cy:command:${id}:end`) | ||
| const measure = performance.measure(`cy:command:${id}:measure`, { | ||
| start: `cy:command:${id}:start`, | ||
| end: `cy:command:${id}:end`, | ||
| }) | ||
|
|
||
| if (!measure) { | ||
| return | ||
| } | ||
|
|
||
| span?.setAttribute('state', command.state) | ||
| span?.setAttribute('numLogs', command.logs?.length || 0) | ||
| span?.setAttribute('error.name', error.name) | ||
| span?.setAttribute('error.message', error.message) | ||
| span?.end() | ||
| Cypress.automation('log:command:performance', { | ||
| name: command.attributes.name, | ||
| startTime: measure.startTime, | ||
| duration: measure.duration, | ||
| }).catch(() => {}).finally(() => { | ||
| performance.clearMarks(`cy:command:${id}:start`) | ||
| performance.clearMarks(`cy:command:${id}:end`) | ||
| performance.clearMeasures(`cy:command:${id}:measure`) | ||
| }) | ||
| } catch (error) { | ||
| // TODO: log error when client side debug logging is available | ||
| // noop | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| export const addTelemetryListeners = (Cypress: Cypress.Cypress) => { | ||
| Cypress.on('test:before:run', startTestOtelSpan) | ||
| Cypress.on('test:after:run', endTestOtelSpan) | ||
| Cypress.on('command:start', startCommandOtelSpan) | ||
| Cypress.on('command:end', endCommandOtelSpan) | ||
| Cypress.on('command:failed', failCommandOtelSpan) | ||
| Cypress.on('skipped:command:end', endCommandOtelSpan) | ||
|
|
||
| Cypress.on('command:start', startCommandPerformanceMark) | ||
| Cypress.on('command:end', endCommandPerformanceMark(Cypress)) | ||
| Cypress.on('skipped:command:end', endCommandPerformanceMark(Cypress)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cacieprins If this is meant to be a user facing feature - I would not prefix this with
CYPRESS_INTERNALas that is used for truly internal env vars that users should never set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if it's something we want user-facing, it should be a config entry - but that's out of scope for this, I think. This is to prep for benchmarking visibility approaches