Skip to content

Commit 0d834bc

Browse files
committed
Add data to all events sent, not just top level
1 parent ac5bfd3 commit 0d834bc

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

system-tests/lib/performance-reporter.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ class HoneycombReporter {
2929
suite.honeycombEvent = this.honey.newEvent()
3030
suite.honeycombEvent.timestamp = Date.now()
3131
suite.honeycombEvent.add({
32+
...suite.parent.honeycombEvent.data,
3233
suite: suite.title,
3334
specFile: path.basename(suite.file),
3435

3536
spanId: uuidv4(),
3637
parentId: suite.parent.honeycombEvent.data.spanId,
37-
traceId: suite.parent.honeycombEvent.data.traceId,
3838
})
39+
40+
this.addAsyncInfo(suite.honeycombEvent)
3941
})
4042

4143
runner.on('test', (test) => {
@@ -50,13 +52,15 @@ class HoneycombReporter {
5052
test.honeycombEvent = this.honey.newEvent()
5153
test.honeycombEvent.timestamp = Date.now()
5254
test.honeycombEvent.add({
55+
...test.parent.honeycombEvent.data,
5356
test: testTitle,
5457
browser,
5558

5659
spanId: uuidv4(),
5760
parentId: test.parent.honeycombEvent.data.spanId,
58-
traceId: test.parent.honeycombEvent.data.traceId,
5961
})
62+
63+
this.addAsyncInfo(test.honeycombEvent)
6064
})
6165

6266
runner.on('test end', (test) => {
@@ -72,7 +76,8 @@ class HoneycombReporter {
7276
durationMs: Date.now() - test.honeycombEvent.timestamp,
7377
})
7478

75-
test.honeycombEvent.send()
79+
console.log(test.honeycombEvent.data)
80+
// test.honeycombEvent.send()
7681
})
7782

7883
runner.on('suite end', (suite) => {
@@ -104,20 +109,31 @@ class HoneycombReporter {
104109
traceId: uuidv4(),
105110
})
106111

107-
commitInfo().then((commitInformation) => {
108-
const ciInformation = ciProvider.commitParams() || {}
112+
this.addAsyncInfo(honeycombEvent)
109113

110-
honeycombEvent.add({
111-
branch: commitInformation.branch || ciInformation.branch,
112-
commitSha: commitInformation.sha || ciInformation.sha,
113-
})
114-
})
114+
return honeycombEvent
115+
}
115116

116-
getNextVersionForPath('../../packages').then((next) => {
117-
honeycombEvent.add({ nextVersion: next })
118-
})
117+
// Because mocha has no way to wait on async functions inside hooks,
118+
// and we need to call various async functions to gather data about
119+
// the testing environment, we create a promise that can be used by each
120+
// honeycomb event to add async data that won't be initialized by the
121+
// time mocha starts running tests.
122+
addAsyncInfo (honeycombEvent) {
123+
if (!this.asyncInfo) {
124+
this.asyncInfo = Promise.all([getNextVersionForPath('../../packages'), commitInfo()])
125+
.then(([nextVersion, commitInformation]) => {
126+
const ciInformation = ciProvider.commitParams() || {}
127+
128+
return {
129+
nextVersion,
130+
branch: commitInformation.branch || ciInformation.branch,
131+
commitSha: commitInformation.sha || ciInformation.sha,
132+
}
133+
})
134+
}
119135

120-
return honeycombEvent
136+
this.asyncInfo.then((info) => honeycombEvent.add(info))
121137
}
122138
}
123139

0 commit comments

Comments
 (0)