@@ -18,6 +18,8 @@ package tracing
18
18
import (
19
19
"context"
20
20
"fmt"
21
+ "os"
22
+ "strings"
21
23
"sync"
22
24
23
25
"github.com/opentracing/opentracing-go"
@@ -72,6 +74,13 @@ func Init(serviceName string, exporterType string, metricsFactory metrics.Factor
72
74
return otTracer
73
75
}
74
76
77
+ // withSecure instructs the client to use HTTPS scheme, instead of hotrod's desired default HTTP
78
+ func withSecure () bool {
79
+ return strings .HasPrefix (os .Getenv ("OTEL_EXPORTER_OTLP_ENDPOINT" ), "https://" ) ||
80
+ strings .ToLower (os .Getenv ("OTEL_EXPORTER_OTLP_INSECURE" )) == "false"
81
+
82
+ }
83
+
75
84
func createOtelExporter (exporterType string ) (sdktrace.SpanExporter , error ) {
76
85
var exporter sdktrace.SpanExporter
77
86
var err error
@@ -81,10 +90,14 @@ func createOtelExporter(exporterType string) (sdktrace.SpanExporter, error) {
81
90
jaeger .WithCollectorEndpoint (),
82
91
)
83
92
case "otlp" :
84
- client := otlptracehttp .NewClient (
85
- otlptracehttp .WithInsecure (),
93
+ var opts []otlptracehttp.Option
94
+ if ! withSecure () {
95
+ opts = []otlptracehttp.Option {otlptracehttp .WithInsecure ()}
96
+ }
97
+ exporter , err = otlptrace .New (
98
+ context .Background (),
99
+ otlptracehttp .NewClient (opts ... ),
86
100
)
87
- exporter , err = otlptrace .New (context .Background (), client )
88
101
case "stdout" :
89
102
exporter , err = stdouttrace .New ()
90
103
default :
0 commit comments