Skip to content

Commit 4654b73

Browse files
graphaellishubbham1215
authored andcommitted
Support secure OTLP exporter config for hotrod (jaegertracing#4231)
## Which problem is this PR solving? hotrod currently forces all connections to insecure in https://github.com/jaegertracing/jaeger/blob/fedeb4cab75399e4672b77efe6a067a7bd148ddf/examples/hotrod/pkg/tracing/init.go#L85 preventing SSL connections from succeeding. For example: ``` $ OTEL_EXPORTER_OTLP_ENDPOINT=https://hotrod.apm.us-east4.gcp.elastic-cloud.com:443 ./hotrod all -x otlp 2023/02/10 13:00:04 traces export: failed to send to http://hotrod.apm.us-east4.gcp.elastic-cloud.com:443/v1/traces: 400 Bad Request ``` ## Short description of the changes - use secure connections when env var `OTEL_EXPORTER_OTLP_ENDPOINT` uses `https` scheme or `OTEL_EXPORTER_OTLP_INSECURE=false` Signed-off-by: Gil Raphaelli <graphaelli@gmail.com> Signed-off-by: shubbham1215 <sawaikershubham@gmail.com>
1 parent 76fe4dc commit 4654b73

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

examples/hotrod/pkg/tracing/init.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package tracing
1818
import (
1919
"context"
2020
"fmt"
21+
"os"
22+
"strings"
2123
"sync"
2224

2325
"github.com/opentracing/opentracing-go"
@@ -72,6 +74,13 @@ func Init(serviceName string, exporterType string, metricsFactory metrics.Factor
7274
return otTracer
7375
}
7476

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+
7584
func createOtelExporter(exporterType string) (sdktrace.SpanExporter, error) {
7685
var exporter sdktrace.SpanExporter
7786
var err error
@@ -81,10 +90,14 @@ func createOtelExporter(exporterType string) (sdktrace.SpanExporter, error) {
8190
jaeger.WithCollectorEndpoint(),
8291
)
8392
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...),
86100
)
87-
exporter, err = otlptrace.New(context.Background(), client)
88101
case "stdout":
89102
exporter, err = stdouttrace.New()
90103
default:

0 commit comments

Comments
 (0)