6
6
7
7
This extension provides k6 with the required functionality required to load test distributed tracing backends.
8
8
9
+ ## Usage
10
+
11
+ Generating traces and sending them to an agent or backend requires two things: a client and a trace generator.
12
+ Generators have a method called ` traces() ` that can be used to generate traces.
13
+ The client provides a method ` push() ` which receives the generated traces as first parameter and sends them to the configured collector.
14
+
15
+ Creating a client requires a client configuration:
16
+
17
+ ``` javascript
18
+ const config = {
19
+ endpoint: " localhost:4317" ,
20
+ exporter: tracing .EXPORTER_OTLP ,
21
+ };
22
+ let client = new tracing.Client (config);
23
+ ```
24
+
25
+ The configuration is an object with the following schema:
26
+
27
+ ``` javascript
28
+ {
29
+ // The endpoint to which the traces are sent in the form of <hostname>:<port>
30
+ endpoint: string,
31
+ // The exporter protocol used for sending the traces: tracing.EXPORTER_OTLP or tracing.EXPORTER_JAEGER
32
+ exporter: string,
33
+ // Whether insecure connections are allowed (optional, default: false)
34
+ insecure: bool,
35
+ // Credentials used for authentication
36
+ authentication: { user: string, password: string },
37
+ // Additional headers sent by the client
38
+ headers: { string : string }
39
+ }
40
+ ```
41
+
42
+ There are two different types of generators which are described in the following sections.
43
+
44
+ ### Parameterized trace generator
45
+
46
+ This generator creates traces consisting of completely randomized spans.
47
+ The spans contain a configurable number of random attributes with randomly assigned values.
48
+ The main purpose of this generator is to create a large amount of spans with few lines of code.
49
+
50
+ An example can be found in [ ./examples/param] ( ./examples/param ) .
51
+
52
+ ### Templated trace generator
53
+
54
+ This generator creates realistically looking and traces that contain spans with span name, span kind, and attributes.
55
+ The trace is generated from a template configurations that describes how each should be generated.
56
+
57
+ The following listing creates a generator that creates traces with a single span:
58
+
59
+ ``` javascript
60
+ const template = {
61
+ spans: [
62
+ {service: " article-service" , name: " get-articles" , attributes: {" http.method" : " GET" }}
63
+ ]
64
+ };
65
+ let gen = new tracing.TemplatedGenerator (template);
66
+ client .push (gen .traces ());
67
+ ```
68
+
69
+ The generated span will have the name ` get-articles ` .
70
+ The generator will further assign a span kind as well as some commonly used attributes.
71
+ There will also be a corresponding resource span with the respective ` service.name ` attribute.
72
+
73
+ The template has the following schema:
74
+
75
+ ``` javascript
76
+ {
77
+ // The defaults can be used to configure parameters that are applied to all spans (optional)
78
+ defaults: {
79
+ // Fixed attributes that are added to every generated span (optional)
80
+ attributes: { string : any },
81
+ // attributeSemantics can be set in order to generate attributes that follow a certain OpenTelemetry
82
+ // semantic convention. For example tracing.SEMANTICS_HTTP (optional)
83
+ attributeSemantics: string,
84
+ // Parameters to configure the creation of random attributes. If missing, no random attributes
85
+ // are added to the spans (optional)
86
+ randomAttributes: {
87
+ // The number of random attributes to generate
88
+ count: int,
89
+ // The number of distinct values to generate for each attribute (optional, default: 50)
90
+ cardinality: int
91
+ }
92
+ },
93
+ // Templates for the individual spans
94
+ spans: [
95
+ {
96
+ // Is used to set the service.name attribute of the corresponding resource span
97
+ service: string,
98
+ // The name of the span. If empty, the name will be randomly generated (optional)
99
+ name: string,
100
+ // The index of the parent span in `spans`. The index must be smaller than the
101
+ // own index. If empty, the parent is the span with the position directly before
102
+ // this span in `spans` (optional)
103
+ parentIdx: int,
104
+ // The interval for the generated span duration. If missing, a random duration is
105
+ // generated that is shorter than the duration of the parent span (optional)
106
+ duration: { min: int, max: int },
107
+ // Fixed attributes that are added to this (optional)
108
+ attributes: { string : any },
109
+ // attributeSemantics can be set in order to generate attributes that follow a certain OpenTelemetry
110
+ // semantic convention. For example tracing.SEMANTICS_HTTP (optional)
111
+ attributeSemantics: string,
112
+ // Parameters to configure the creation of random attributes. If missing, no random attributes
113
+ // are added to the span (optional)
114
+ randomAttributes: {
115
+ // The number of random attributes to generate
116
+ count: int,
117
+ // The number of distinct values to generate for each attribute (optional, default: 50)
118
+ cardinality: int
119
+ }
120
+ },
121
+ ...
122
+ ]
123
+ }
124
+ ```
125
+
126
+ An example with a templated generator can be found in [ ./examples/template] ( ./examples/template ) .
127
+
9
128
## Getting started
10
129
11
130
To start using the k6 tracing extension, ensure you have the following prerequisites installed:
@@ -29,21 +148,21 @@ After the command completed successfully the image `grafana/xk6-client-tracing:l
29
148
30
149
> Note: before running the docker-compose example, make sure to complete the docker image build step above!
31
150
32
- To run the example ` cd ` into the directory ` examples/basic ` and run:
151
+ To run the example ` cd ` into the directory ` examples/param ` and run:
33
152
34
153
``` shell
35
154
docker-compose up -d
36
155
```
37
156
38
- In the example ` k6-tracing ` uses the script ` basic .js` to generate spans and sends them to the ` otel-collector ` .
157
+ In the example ` k6-tracing ` uses the script ` param .js` to generate spans and sends them to the ` otel-collector ` .
39
158
The generated spans can be observed by inspecting the collector's logs:
40
159
41
160
``` shell
42
161
docker-compose logs -f otel-collector
43
162
```
44
163
45
164
The example uses the OTLP gRPC exporter.
46
- If you want to use Jaeger gRPC, you can change ` basic .js` and use the following settings:
165
+ If you want to use Jaeger gRPC, you can change ` param .js` and use the following settings:
47
166
48
167
``` javascript
49
168
const client = new tracing.Client ({
@@ -75,7 +194,7 @@ make build
75
194
```
76
195
77
196
The build step produces the ` k6-tracing ` binary.
78
- To test the binary you first need to change the endpoint in the client configuration in ` examples/basic/basic.js ` :
197
+ To test the binary you first need to change the endpoint in the client configuration to :
79
198
80
199
``` javascript
81
200
const client = new tracing.Client ({
@@ -96,7 +215,7 @@ docker run --rm -p 13133:13133 -p 14250:14250 -p 14268:14268 \
96
215
97
216
Once that's done, you can run a test like:
98
217
```
99
- ./k6-tracing run examples/basic/basic .js
218
+ ./k6-tracing run examples/basic/param .js
100
219
```
101
220
102
221
And see the generated spans in the OTEL collector logs!
0 commit comments