-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracing.go
67 lines (53 loc) · 1.38 KB
/
tracing.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
package mojito_extension_tracing
import (
"fmt"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"log"
)
var (
serviceName string = "go-mojito"
envList map[string]any = make(map[string]any)
)
type ExporterConfig struct {
ProviderURL string
}
func Configure(exporterType Exporter, name string, env map[string]any, config ExporterConfig) error {
serviceName = name
envList = env
switch exporterType {
case JAEGER:
provider, err := configureJaegerTracer(config.ProviderURL)
if err != nil {
return err
}
err = ConfigureWithCustomTracerProvider(provider)
if err != nil {
return err
}
}
return nil
}
func ConfigureWithCustomTracerProvider(tracer *tracesdk.TracerProvider) error {
otel.SetTracerProvider(tracer)
return nil
}
func configureMapToSlice() []attribute.KeyValue {
values := make([]attribute.KeyValue, 0)
for key, val := range envList {
switch val.(type) {
case string:
values = append(values, attribute.String(key, val.(string)))
case bool:
values = append(values, attribute.Bool(key, val.(bool)))
case int64:
values = append(values, attribute.Int64(key, val.(int64)))
case int:
values = append(values, attribute.Int(key, val.(int)))
default:
log.Println(fmt.Sprintf("key '%s' with datatype '%T' currently not supported", key, val))
}
}
return values
}