-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
jaeger.go
59 lines (49 loc) · 1.52 KB
/
jaeger.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
package jaeger
import (
"net"
"os"
"strings"
"github.com/moby/buildkit/util/tracing/detect"
"go.opentelemetry.io/otel/exporters/trace/jaeger"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
func init() {
detect.Register("jaeger", jaegerExporter, 11)
}
func jaegerExporter() (sdktrace.SpanExporter, error) {
set := os.Getenv("OTEL_TRACES_EXPORTER") == "jaeger" || os.Getenv("JAEGER_TRACE") != "" || os.Getenv("OTEL_EXPORTER_JAEGER_AGENT_HOST") != "" || os.Getenv("OTEL_EXPORTER_JAEGER_ENDPOINT") != ""
if !set {
return nil, nil
}
endpoint := envOr("OTEL_EXPORTER_JAEGER_ENDPOINT", "http://localhost:14250")
host := envOr("OTEL_EXPORTER_JAEGER_HOST", "localhost")
port := envOr("OTEL_EXPORTER_JAEGER_PORT", "6831")
var isEndpoint bool
// JAEGER_TRACE is not env defined by opentelemetry spec but buildkit backward compatibility
if v := os.Getenv("JAEGER_TRACE"); v != "" {
if strings.HasPrefix(v, "http://") || strings.HasPrefix(v, "https://") {
isEndpoint = true
endpoint = v
} else {
h, p, err := net.SplitHostPort(v)
if err != nil {
return nil, err
}
host = h
port = p
}
} else {
isEndpoint = os.Getenv("OTEL_EXPORTER_JAEGER_ENDPOINT") != ""
}
epo := jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(endpoint))
if !isEndpoint {
epo = jaeger.WithAgentEndpoint(jaeger.WithAgentHost(host), jaeger.WithAgentPort(port))
}
return jaeger.NewRawExporter(epo)
}
func envOr(key, defaultValue string) string {
if v, ok := os.LookupEnv(key); ok && v != "" {
return v
}
return defaultValue
}