Skip to content

Commit

Permalink
Configure OTLP URL correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Aug 23, 2023
1 parent 9ae4a04 commit 4fd1c3b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/base64"
"fmt"
"net/url"
"runtime/trace"

"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -75,9 +76,22 @@ func StartTask(ctx context.Context, name string) (context.Context, *Task) {

func ConfigureOTLP(otlpURL, otlpUser, otlpPass, version string) error {
ctx := context.Background()
parsedOTLPURL, err := url.Parse(otlpURL)
if err != nil {
return err
}
isInsecure := parsedOTLPURL.Scheme == "http" // e.g testing and development
if parsedOTLPURL.Path != "" {
return fmt.Errorf("OTLP URL %s cannot contain any path segments", otlpURL)
}

opts := []otlptracehttp.Option{
otlptracehttp.WithEndpoint(otlpURL),
otlptracehttp.WithEndpoint(parsedOTLPURL.Host),
}
if isInsecure {
opts = append(opts, otlptracehttp.WithInsecure())
}
fmt.Println("ConfigureOTLP: host=", parsedOTLPURL.Host, "insecure=", isInsecure)
if otlpPass != "" && otlpUser != "" {
opts = append(opts, otlptracehttp.WithHeaders(
map[string]string{
Expand Down

0 comments on commit 4fd1c3b

Please sign in to comment.