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

chore: add telemetry to the proxy #26695

Merged
merged 48 commits into from
May 17, 2023
Merged

Conversation

mjhenkes
Copy link
Member

@mjhenkes mjhenkes commented May 9, 2023

  • Closes

Additional details

This PR adds telemetry spans to the proxy as well as enhancing telemetry itself by:

  • Adding a rough verbose mode enabled by: CYPRESS_INTERNAL_ENABLE_TELEMETRY_VERBOSE
  • Console logging of the current trace (at start and end)
  • propagating parent attributes to child spans, this isn't foolproof as spans will recursively collect attributes set on the parent chain up until the child span closes, or in the case of cross process parents, up until the parent context is sent.
  • Verbose spans have also been added for cypress commands.
  • Correctly setup ts so that the telemetry package will auto build. Edit: this caused build issues. Reverted until we have more time to investigate it.
  • Added a githubAction env detector
  • Spans may now be started with a key other than their name to allow for generic names but retrieval by a unique key.
  • Spans may be started with a parent span that is passed in and not set to active.
  • Fixed a bug where when a large amount of spans are queued in the batch span processor it no longer looses them.

Not all spans in the proxy are properly closed, the cost of chasing down these few spans started to outweigh the value of closing them so, i decided to get this pr in since it adds value in its current form.

Future consideration: It would be nice to rework verbose mode to work like our debug verbose mode to allow for fine grain tuning of what you want sent.

Steps to test

How has the user experience changed?

PR Tasks

@mjhenkes mjhenkes requested a review from AtofStryker May 16, 2023 12:55
@chrisbreiding chrisbreiding self-requested a review May 16, 2023 15:32
@@ -541,6 +541,7 @@ export class CommandQueue extends Queue<$Command> {
current.fail()
}

Cypress.action('cy:command:failed', current, err)
Copy link
Member

Choose a reason for hiding this comment

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

double checking - Should this be command:fails OR command:skipped dep on the command state of queued vs pending?

this would be primarily observers around cy.session spans and error handling if I remember corretly.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't expect skipped to count as an error. There is an explicit skipped:command:end message called. Even so, the span would be ended with the state logged, but it would also include the error.


function getRandomColorFn () {
return chalk.hex(`#${Number(
Math.floor(Math.random() * 0xFFFFFF),
).toString(16).padStart(6, 'F').toUpperCase()}`)
}

export const isVerboseTelemetry = true
Copy link
Member

Choose a reason for hiding this comment

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

Why is this exported and why is this hard-coded to true?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a single place to control the verbose telemetry flag for the proxy, the request and response middle-wares both import it.


const types = ['child', 'root'] as const
const SERVICE_NAME = 'cypress-app'
Copy link
Member

@emilyrohrbough emilyrohrbough May 16, 2023

Choose a reason for hiding this comment

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

Suggested change
const SERVICE_NAME = 'cypress-app'
const STAGING_ENV = 'cypress-app-staging'
const PRODUCTION_ENG = 'cypress-app'

Copy link
Member Author

Choose a reason for hiding this comment

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

The service name remains the same regardless of staging or prod, we flex cloud endpoint we send data too to separate staging and production.

Copy link
Member

Choose a reason for hiding this comment

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

oops yeah, this wasn't meant to replace the Service_name, more like should we pull this up so we can see face-up the names/envs we push data to.

opts = {},
key,
isVerbose = false,
Copy link
Member

Choose a reason for hiding this comment

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

did you consider creating a wrapper called createVerboseSpan which would remove the need to define isVerbose throughout the code?

const span = startVerboseSpan(spanOpts)

const startVerboseSpan = (opts) => {
  if (!this.verbose) return undefined

   return startSpan(opts)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I think how we have it is fine for now, a single command with options... In the future we should enhance verbose to allow targeted span creation (the real question there is how to filter and ensure parent spans are created).

Copy link
Member

Choose a reason for hiding this comment

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

My thought is it would remove the need to pass isVerbose throughout the code-base and need to export the isVerbose boolean

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean we could remove that need just by setting it in the proxy, that isVerbose export is just for filtering verbosity on an off within the proxy, not the entire code base. 🤷‍♂️ The better way to do that would be a better filtering mechanism like we have with debugging, but for now our cheap 'isVerbose' works well enough. (imo)


const doesTopNeedSimulation = doesTopNeedToBeSimulated(this)

// TODO: might not need these on the span as they are declared above and might trickle down
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this TODO be addressed?

this.res.redirect(this.config.clientRoute)

span?.end()

// TODO: where is this? Do we need to pass the span in here?
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this TODO be addressed?

this._uniqueTraces[traceId] = spanId

this._log(
`Trace start: [${span.name}] - ${this._traceUrl}=${span.spanContext().traceId}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`Trace start: [${span.name}] - ${this._traceUrl}=${span.spanContext().traceId}`,
`Trace start: [${span.name}] - ${this._traceUrl}=${span.spanContext().traceId}`,

@@ -0,0 +1,97 @@
import { expect } from 'chai'
Copy link
Contributor

Choose a reason for hiding this comment

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

This filename has a typo in it. Should be githubActionsDetectorSync.spec.ts?

@mjhenkes mjhenkes merged commit 50ffd5e into develop May 17, 2023
@mjhenkes mjhenkes deleted the matth/chore/proxy-telemetry branch May 17, 2023 13:32
@mjhenkes mjhenkes mentioned this pull request May 17, 2023
3 tasks
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 23, 2023

Released in 12.13.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v12.13.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants