Skip to content

Commit

Permalink
url parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Jayadeep KM <[email protected]>
  • Loading branch information
kmjayadeep committed Dec 17, 2023
1 parent a5435cb commit acff709
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package tracing

import (
"context"
"encoding/base64"
"fmt"
"net/url"

"github.com/tektoncd/pipeline/pkg/apis/config"
"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -150,17 +153,32 @@ func createTracerProvider(service string, cfg *config.Tracing, user, pass string
if !cfg.Enabled {
return noop.NewTracerProvider(), nil
}
u, err := url.Parse(cfg.Endpoint)
if err != nil {
return nil, err
}

opts := []otlptracehttp.Option{
otlptracehttp.WithEndpoint(u.Host),
otlptracehttp.WithURLPath(u.Path),
}

if u.Scheme == "http" {
opts = append(opts, otlptracehttp.WithInsecure())
}

if user != "" && pass != "" {
creds := fmt.Sprintf("%s:%s", user, pass)
enc := base64.StdEncoding.EncodeToString([]byte(creds))
o := otlptracehttp.WithHeaders(map[string]string{
"Authorization": fmt.Sprintf("Basic %s", enc),
})
opts = append(opts, o)
}

ctx := context.Background()
exp, err := otlptracehttp.New(ctx,
otlptracehttp.WithEndpoint(cfg.Endpoint),
)
exp, err := otlptracehttp.New(ctx, opts...)

// exp, err := jaeger.New(jaeger.WithCollectorEndpoint(
// jaeger.WithEndpoint(cfg.Endpoint),
// jaeger.WithUsername(user),
// jaeger.WithPassword(pass),
// ))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit acff709

Please sign in to comment.