-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-traces.js
80 lines (68 loc) · 2.29 KB
/
test-traces.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import generator from 'k6/x/opentelemetry';
import {
Writer,
SchemaRegistry,
SCHEMA_TYPE_BYTES,
} from 'k6/x/kafka';
const brokers = ["localhost:9092"]
const topic = "otel_traces"
const schemaRegistry = new SchemaRegistry();
const producer = new Writer({
brokers: brokers,
topic: topic,
});
export default function () {
var messages = []
const resourceAttributes = new Map()
resourceAttributes.set("pod", "test-abc")
// make sure to set a service name for correct visualization in Grafana Tempo
resourceAttributes.set("service.name", "service-1")
// optionally set static attributes for the resource
generator.setStaticResourceAttributes(resourceAttributes)
for (let idx = 0; idx < 10; idx++) {
var timeNow = generator.timeNowUnixNano()
var traceId = generator.newTraceID()
var span1Id = generator.newSpanID()
var span1 = {
"traceId": traceId,
"spanId": span1Id,
// root span has no parendSpanId
"name": "say-hello",
// "attributes": spanAttributes, // optionally create span specific attribute map
"startTimeUnixNano": timeNow - 1e8, // 100ms earlier
"endTimeUnixNano": timeNow,
}
var span2Id = generator.newSpanID()
var span2 = {
"traceId": traceId,
"spanId": span2Id,
"parentSpanId": span1Id,
"name": "random-name",
"kind": "client",
"startTimeUnixNano": timeNow - 9e7,
"endTimeUnixNano": timeNow - 4e7,
}
var span3Id = generator.newSpanID()
var span3 = {
"traceId": traceId,
"spanId": span3Id,
"parentSpanId": span1Id,
"name": "enrich",
"startTimeUnixNano": timeNow - 3e7,
"endTimeUnixNano": timeNow - 1e7,
}
messages[idx] = {
value: schemaRegistry.serialize({
data: Array.from(generator.exportTraceServiceRequest({
"data": [
span1,
span2,
span3,
],
})),
schemaType: SCHEMA_TYPE_BYTES,
})
}
}
producer.produce({ messages: messages })
}