Skip to content

Commit

Permalink
allow secure conns while retaining default insecure
Browse files Browse the repository at this point in the history
  • Loading branch information
graphaelli committed Feb 13, 2023
1 parent b311fd4 commit 09ef24b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion examples/hotrod/pkg/tracing/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package tracing
import (
"context"
"fmt"
"os"
"strings"
"sync"

"github.com/opentracing/opentracing-go"
Expand Down Expand Up @@ -72,6 +74,13 @@ func Init(serviceName string, exporterType string, metricsFactory metrics.Factor
return otTracer
}

// withSecure instructs the client to use HTTPS scheme, instead of hotrod's desired default HTTP
func withSecure() bool {
return strings.HasPrefix(os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"), "https://") ||
strings.ToLower(os.Getenv("OTEL_EXPORTER_OTLP_INSECURE")) == "false"

}

func createOtelExporter(exporterType string) (sdktrace.SpanExporter, error) {
var exporter sdktrace.SpanExporter
var err error
Expand All @@ -81,9 +90,13 @@ func createOtelExporter(exporterType string) (sdktrace.SpanExporter, error) {
jaeger.WithCollectorEndpoint(),
)
case "otlp":
var opts []otlptracehttp.Option
if !withSecure() {
opts = []otlptracehttp.Option{otlptracehttp.WithInsecure()}
}
exporter, err = otlptrace.New(
context.Background(),
otlptracehttp.NewClient(),
otlptracehttp.NewClient(opts...),
)
case "stdout":
exporter, err = stdouttrace.New()
Expand Down

0 comments on commit 09ef24b

Please sign in to comment.