Skip to content

Commit c088e8e

Browse files
authored
Refactor templated event and link generation (#28)
* Consistent naming for internal event and link templates * Initialize link attribute values during initialization * Rename EventParam.Rate and remove unused generateExceptionOnError: * Initialize event attribute values during initialization * Update example template.js * Upgrade Go and golangci-lint versions * Change package name to clienttracing
1 parent 1f223eb commit c088e8e

File tree

8 files changed

+215
-237
lines changed

8 files changed

+215
-237
lines changed

.github/workflows/lint-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212
- name: Set-up Go
1313
uses: actions/setup-go@v3
1414
with:
15-
go-version: ^1.21
15+
go-version: ^1.22
1616
cache: true
1717

1818
- name: Lint
1919
uses: golangci/golangci-lint-action@v3
2020
with:
21-
version: v1.55.2
21+
version: v1.59.0
2222
args: --config ./golangci.yml
2323

2424
- name: Test

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Set-up Go
1515
uses: actions/setup-go@v3
1616
with:
17-
go-version: ^1.19
17+
go-version: ^1.22
1818
cache: true
1919

2020
- name: Test

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21-alpine AS xk6-client-tracing-build
1+
FROM golang:1.22-alpine AS xk6-client-tracing-build
22

33
RUN apk add --no-cache \
44
build-base \
@@ -7,7 +7,7 @@ RUN apk add --no-cache \
77
make
88

99
RUN go install go.k6.io/xk6/cmd/xk6@latest \
10-
&& wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.50.0 \
10+
&& wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.59.0 \
1111
&& golangci-lint --version
1212

1313
WORKDIR /opt/xk6-client-tracing

examples/template/template.js

+27-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const client = new tracing.Client({
1313
endpoint,
1414
exporter: tracing.EXPORTER_OTLP,
1515
tls: {
16-
insecure: true,
16+
insecure: true,
1717
},
1818
headers: {
1919
"X-Scope-Orgid": orgid
@@ -24,8 +24,7 @@ const traceDefaults = {
2424
attributeSemantics: tracing.SEMANTICS_HTTP,
2525
attributes: {"one": "three"},
2626
randomAttributes: {count: 2, cardinality: 5},
27-
randomEvents: {generateExceptionOnError: true, rate: 1.0, randomAttributes: {count: 2, cardinality: 3}},
28-
randomLinks: {rate: 1.0, randomAttributes: {count: 2, cardinality: 3}},
27+
randomEvents: {count: 0.1, exceptionCount: 0.2, randomAttributes: {count: 6, cardinality: 20}},
2928
}
3029

3130
const traceTemplates = [
@@ -36,7 +35,11 @@ const traceTemplates = [
3635
{service: "shop-backend", name: "authenticate", duration: {min: 50, max: 100}},
3736
{service: "auth-service", name: "authenticate"},
3837
{service: "shop-backend", name: "fetch-articles", parentIdx: 0},
39-
{service: "article-service", name: "list-articles"},
38+
{
39+
service: "article-service",
40+
name: "list-articles",
41+
links: [{attributes: {"link-type": "parent-child"}, randomAttributes: {count: 2, cardinality: 5}}]
42+
},
4043
{service: "article-service", name: "select-articles", attributeSemantics: tracing.SEMANTICS_DB},
4144
{service: "postgres", name: "query-articles", attributeSemantics: tracing.SEMANTICS_DB, randomAttributes: {count: 5}},
4245
]
@@ -45,6 +48,7 @@ const traceTemplates = [
4548
defaults: {
4649
attributes: {"numbers": ["one", "two", "three"]},
4750
attributeSemantics: tracing.SEMANTICS_HTTP,
51+
randomEvents: {count: 2, randomAttributes: {count: 3, cardinality: 10}},
4852
},
4953
spans: [
5054
{service: "shop-backend", name: "article-to-cart", duration: {min: 400, max: 1200}},
@@ -64,17 +68,30 @@ const traceTemplates = [
6468
spans: [
6569
{service: "shop-backend", attributes: {"http.status_code": 403}},
6670
{service: "shop-backend", name: "authenticate", attributes: {"http.request.header.accept": ["application/json"]}},
67-
{service: "auth-service", name: "authenticate", attributes: {"http.status_code": 403}},
71+
{
72+
service: "auth-service",
73+
name: "authenticate",
74+
attributes: {"http.status_code": 403},
75+
randomEvents: {count: 0.5, exceptionCount: 2, randomAttributes: {count: 5, cardinality: 5}}
76+
},
6877
]
6978
},
7079
{
7180
defaults: traceDefaults,
7281
spans: [
73-
{service: "shop-backend", attributes: {"http.status_code": 403}},
82+
{service: "shop-backend"},
7483
{service: "shop-backend", name: "authenticate", attributes: {"http.request.header.accept": ["application/json"]}},
75-
{service: "auth-service", name: "authenticate", attributes: {"http.status_code": 403}},
76-
{service: "cart-service", name: "checkout", randomEvents: {exceptionRate: 1, rate: 2, randomAttributes: {count: 5, cardinality: 2}}},
77-
{service: "billing-service", name: "payment", randomLinks: {rate: 2, randomAttributes: {count: 3, cardinality: 2}}}
84+
{service: "auth-service", name: "authenticate"},
85+
{
86+
service: "cart-service",
87+
name: "checkout",
88+
randomEvents: {count: 0.5, exceptionCount: 2, exceptionOnError: true, randomAttributes: {count: 5, cardinality: 5}}
89+
},
90+
{
91+
service: "billing-service",
92+
name: "payment",
93+
randomLinks: {count: 0.5, randomAttributes: {count: 3, cardinality: 10}},
94+
randomEvents: {exceptionOnError: true, randomAttributes: {count: 4}}}
7895
]
7996
},
8097
]
@@ -89,4 +106,4 @@ export default function () {
89106

90107
export function teardown() {
91108
client.shutdown();
92-
}
109+
}

pkg/random/random.go

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func init() {
3232
rnd = rand.New(rand.NewSource(seed.Int64()))
3333
}
3434

35+
func Rand() *rand.Rand {
36+
return rnd
37+
}
38+
3539
func SelectElement[T any](elements []T) T {
3640
return elements[rnd.Intn(len(elements))]
3741
}
@@ -121,3 +125,7 @@ func SpanID() pcommon.SpanID {
121125
_, _ = rnd.Read(b[:]) // always returns nil error
122126
return b
123127
}
128+
129+
func EventName() string {
130+
return "event_k6." + String(10)
131+
}

0 commit comments

Comments
 (0)