Skip to content

Commit

Permalink
support secure OTLP exporter for hotrod
Browse files Browse the repository at this point in the history
Signed-off-by: Gil Raphaelli <graphaelli@gmail.com>
  • Loading branch information
graphaelli committed Feb 13, 2023
1 parent 5b58370 commit 527608b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions 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,10 +90,14 @@ func createOtelExporter(exporterType string) (sdktrace.SpanExporter, error) {
jaeger.WithCollectorEndpoint(),
)
case "otlp":
client := otlptracehttp.NewClient(
otlptracehttp.WithInsecure(),
var opts []otlptracehttp.Option
if !withSecure() {
opts = []otlptracehttp.Option{otlptracehttp.WithInsecure()}
}
exporter, err = otlptrace.New(
context.Background(),
otlptracehttp.NewClient(opts...),
)
exporter, err = otlptrace.New(context.Background(), client)
case "stdout":
exporter, err = stdouttrace.New()
default:
Expand Down

0 comments on commit 527608b

Please sign in to comment.