Skip to content

Commit

Permalink
Support secure OTLP exporter config for hotrod (jaegertracing#4231)
Browse files Browse the repository at this point in the history
## 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>
  • Loading branch information
graphaelli authored and shubbham1215 committed Mar 5, 2023
1 parent 76fe4dc commit 4654b73
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 4654b73

Please sign in to comment.