-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwiring.go
79 lines (70 loc) · 3.46 KB
/
wiring.go
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
// Package jaeger provides a plugin to generate and include a jaeger collector instance in a Blueprint application.
//
// # Wiring Spec Usage
//
// To instantiate a Jaeger container:
//
// collector := jaeger.Collector(spec, "jaeger")
//
// The returned `collector` must be used as an argument to the `opentelemetry.Instrument(spec, serviceName, collector)` to ensure the spans generated by instrumented services are correctly exported to the instantiated server.
//
// # Artifacts Generated
//
// 1. The package generates a jaeger docker container that provides the server-side implementation of the Jaeger collector.
// 2. Instantiates a [JaegerTracer] instance for configuring the opentelemetry runtime libraries to export all generated traces to the Jaeger collector.
//
// [JaegerTracer]: https://github.com/Blueprint-uServices/blueprint/tree/main/runtime/plugins/jaeger
package jaeger
import (
"github.com/blueprint-uservices/blueprint/blueprint/pkg/coreplugins/address"
"github.com/blueprint-uservices/blueprint/blueprint/pkg/coreplugins/pointer"
"github.com/blueprint-uservices/blueprint/blueprint/pkg/ir"
"github.com/blueprint-uservices/blueprint/blueprint/pkg/wiring"
)
// [Collector] can be used by wiring specs to instantiate a jaeger docker container named `collectorName` that uses the latest jaeger:all-in-one container
// and generates the clients needed by the generated application to communicate with the server.
//
// The returned collectorName must be used as an argument to the opentelemetry.Instrument(spec, serviceName, `collectorName`) to ensure the spans generated by instrumented services are correctly exported to the instantiated server.
//
// # Wiring Spec Usage
//
// jaeger.Collector(spec, "jaeger")
func Collector(spec wiring.WiringSpec, collectorName string) string {
// The nodes that we are defining
collectorAddr := collectorName + ".addr"
collectorUIAddr := collectorName + ".ui.addr"
collectorCtr := collectorName + ".ctr"
collectorClient := collectorName + ".client"
// Define the Jaeger collector
spec.Define(collectorCtr, &JaegerCollectorContainer{}, func(ns wiring.Namespace) (ir.IRNode, error) {
collector, err := newJaegerCollectorContainer(collectorCtr)
if err != nil {
return nil, err
}
err = address.Bind[*JaegerCollectorContainer](ns, collectorAddr, collector, &collector.BindAddr)
if err != nil {
return nil, err
}
err = address.Bind[*JaegerCollectorContainer](ns, collectorUIAddr, collector, &collector.UIBindAddr)
return collector, err
})
// Create a pointer to the collector
ptr := pointer.CreatePointer[*JaegerCollectorClient](spec, collectorName, collectorCtr)
// Define the address that points to the Jaeger collector
address.Define[*JaegerCollectorContainer](spec, collectorUIAddr, collectorCtr)
address.Define[*JaegerCollectorContainer](spec, collectorAddr, collectorCtr)
// Add the addresses to the pointer
ptr.AddAddrModifier(spec, collectorUIAddr)
ptr.AddAddrModifier(spec, collectorAddr)
// Define the Jaeger client and add it to the client side of the pointer
clientNext := ptr.AddSrcModifier(spec, collectorClient)
spec.Define(collectorClient, &JaegerCollectorClient{}, func(ns wiring.Namespace) (ir.IRNode, error) {
addr, err := address.Dial[*JaegerCollectorContainer](ns, clientNext)
if err != nil {
return nil, err
}
return newJaegerCollectorClient(collectorClient, addr.Dial)
})
// Return the pointer; anybody who wants to access the Jaeger collector should do so through the pointer
return collectorName
}