Skip to content

Commit

Permalink
Use honeycomb tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWinds committed Feb 7, 2022
1 parent 304d8bd commit ac5bfd3
Showing 1 changed file with 74 additions and 35 deletions.
109 changes: 74 additions & 35 deletions system-tests/lib/performance-reporter.js
@@ -1,47 +1,44 @@
const path = require('path')
const chalk = require('chalk')
const Libhoney = require('libhoney')
const { v4: uuidv4 } = require('uuid')

const ciProvider = require('@packages/server/lib/util/ci_provider')
const { commitInfo } = require('@cypress/commit-info')
const { getNextVersionForPath } = require('../../scripts/get-next-version')

class StatsdReporter {
class HoneycombReporter {
constructor (runner) {
if (!process.env.HONEYCOMB_API_KEY) {
return
}

console.log(chalk.green('Reporting to honeycomb'))

let branch
let commitSha
let nextVersion

this.honey = new Libhoney({
dataset: 'systemtest-performance',
writeKey: process.env.HONEYCOMB_API_KEY,
})

commitInfo().then((commitInformation) => {
const ciInformation = ciProvider.commitParams() || {}
runner.on('suite', (suite) => {
if (suite.root) {
suite.honeycombEvent = this.rootEvent()

branch = commitInformation.branch || ciInformation.branch
commitSha = commitInformation.sha || ciInformation.sha
})
return
}

getNextVersionForPath('../../packages').then((next) => nextVersion = next)
suite.honeycombEvent = this.honey.newEvent()
suite.honeycombEvent.timestamp = Date.now()
suite.honeycombEvent.add({
suite: suite.title,
specFile: path.basename(suite.file),

runner.on('test', (test) => {
test.wallclockStart = Date.now()
spanId: uuidv4(),
parentId: suite.parent.honeycombEvent.data.spanId,
traceId: suite.parent.honeycombEvent.data.traceId,
})
})

runner.on('test end', (test) => {
// Skipped tests never get a 'start' event, but they still get 'test end' somehow.
if (!test.state || test.state === 'skipped') {
return
}

runner.on('test', (test) => {
const title = test.titlePath().join(' / ')
// This regex pulls apart a string like `e2e async timeouts / failing1 [electron]`
// into `e2e async timeouts / failing1` and `electron`, letting us use the same
Expand All @@ -50,27 +47,40 @@ class StatsdReporter {
// in which case it will be undefined and not passed as a field to honeycomb.
const [, testTitle, browser] = title.match(/(.+?)(?: \[([a-z]+)\])?$/)

const honeycombEvent = this.honey.newEvent()

honeycombEvent.timestamp = test.wallclockStart
honeycombEvent.add({
test.honeycombEvent = this.honey.newEvent()
test.honeycombEvent.timestamp = Date.now()
test.honeycombEvent.add({
test: testTitle,
specFile: path.basename(test.file),
browser,

spanId: uuidv4(),
parentId: test.parent.honeycombEvent.data.spanId,
traceId: test.parent.honeycombEvent.data.traceId,
})
})

runner.on('test end', (test) => {
// Skipped tests never get a 'start' event, but they still get 'test end' somehow.
if (!test.state || test.state === 'skipped') {
return
}

test.honeycombEvent.add({
state: test.state,
err: test.err && test.err.message,
errStack: test.err && test.err.stack,
durationMs: Date.now() - test.wallclockStart,
mochaDurationMs: test.duration,
branch,
commitSha,
buildUrl: process.env.CIRCLE_BUILD_URL,
platform: process.platform,
arch: process.arch,
version: nextVersion,
durationMs: Date.now() - test.honeycombEvent.timestamp,
})

test.honeycombEvent.send()
})

runner.on('suite end', (suite) => {
suite.honeycombEvent.add({
durationMs: Date.now() - suite.honeycombEvent.timestamp,
})

honeycombEvent.send()
suite.honeycombEvent.send()
})
}

Expand All @@ -80,6 +90,35 @@ class StatsdReporter {
this.honey.flush().then(callback)
}
}

rootEvent () {
const honeycombEvent = this.honey.newEvent()

honeycombEvent.timestamp = Date.now()
honeycombEvent.add({
buildUrl: process.env.CIRCLE_BUILD_URL,
platform: process.platform,
arch: process.arch,

spanId: uuidv4(),
traceId: uuidv4(),
})

commitInfo().then((commitInformation) => {
const ciInformation = ciProvider.commitParams() || {}

honeycombEvent.add({
branch: commitInformation.branch || ciInformation.branch,
commitSha: commitInformation.sha || ciInformation.sha,
})
})

getNextVersionForPath('../../packages').then((next) => {
honeycombEvent.add({ nextVersion: next })
})

return honeycombEvent
}
}

module.exports = StatsdReporter
module.exports = HoneycombReporter

0 comments on commit ac5bfd3

Please sign in to comment.