-
Notifications
You must be signed in to change notification settings - Fork 4
/
tracing_cypress.js
62 lines (55 loc) · 1.64 KB
/
tracing_cypress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { context, trace } from '@opentelemetry/api'
import { initTracer } from './init_tracing'
export default class TracingCypress {
constructor() {
this.webTracerWithZone = initTracer('cypress-tests-wrapper')
this.mainSpan = undefined
this.currentSpan = undefined
}
_createChildSpan(name) {
const ctx = trace.setSpan(context.active(), this.currentSpan)
const span = this.webTracerWithZone.startSpan(name, undefined, ctx)
trace.setSpan(context.active(), span)
return span
}
initTracing(name) {
this.mainSpan = this.webTracerWithZone.startSpan(name)
this.currentSpan = this.mainSpan
trace.setSpan(context.active(), this.mainSpan)
this.mainSpan.end()
}
visit(url, options) {
this.currentSpan = this.mainSpan
const span = this._createChildSpan(`visit: ${url}`)
this.currentSpan = span
const result = cy.visit(url, options)
span.end()
return result
}
get(selector, options) {
const span = this._createChildSpan(`get: ${selector}`)
this.currentSpan = span
const result = cy.get(selector, options)
span.end()
return result
}
click(subject, options) {
const span = this._createChildSpan('click')
subject.then(element =>
element[0].ownerDocument.defaultView.startBindingSpan(
span.spanContext().traceId,
span.spanContext().spanId,
span.spanContext().traceFlags
)
)
const result = subject.click(options)
span.end()
return result
}
type(subject, text, options) {
const span = this._createChildSpan(`type: ${text}`)
const result = subject.type(text, options)
span.end()
return result
}
}