Skip to content

Commit

Permalink
fix: better url parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Sep 11, 2024
1 parent 18ea2c4 commit bb6b59a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ services:
VELA_REPO_ALLOWLIST: '*'
VELA_SCHEDULE_ALLOWLIST: '*'
VELA_OTEL_TRACING_ENABLE: true
OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4318
VELA_OTEL_TRACING_ENDPOINT: jaeger:4318
VELA_OTEL_TRACING_SAMPLER_RATELIMIT_PER_SECOND: 0.2
VELA_OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4318
VELA_OTEL_TRACING_SAMPLER_RATELIMIT_PER_SECOND: 100
env_file:
- .env
restart: always
Expand Down
4 changes: 2 additions & 2 deletions tracing/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ var Flags = []cli.Flag{
Value: "vela-server",
},
&cli.StringFlag{
EnvVars: []string{"VELA_OTEL_TRACING_ENDPOINT"},
EnvVars: []string{"VELA_OTEL_EXPORTER_OTLP_ENDPOINT"},
Name: "tracing.exporter.endpoint",
Usage: "set the otel exporter endpoint",
Usage: "set the otel exporter endpoint (ex. scheme://host:port)",
},
&cli.StringFlag{
EnvVars: []string{"VELA_OTEL_TRACING_EXPORTER_SSL_CERT_PATH"},
Expand Down
22 changes: 21 additions & 1 deletion tracing/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"net/url"
"os"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -63,8 +65,26 @@ func initTracer(ctx context.Context, cfg Config) (*sdktrace.TracerProvider, erro
logrus.Warn("no otel cert path set, exporting traces insecurely")
}

if len(cfg.ExporterURL) == 0 {
return nil, errors.New("no otel exporter URL set (ex. scheme://host:port)")
}

exporterURL, err := url.Parse(cfg.ExporterURL)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("unable to parse otel exporter URL (ex. scheme://host:port): %s", cfg.ExporterURL))
}

if len(exporterURL.Hostname()) == 0 {
return nil, fmt.Errorf("unable to parse host from otel exporter URL (ex. scheme://host:port): %s", cfg.ExporterURL)
}

exporterEndpoint := exporterURL.Hostname()
if len(exporterURL.Port()) > 0 {
exporterEndpoint = fmt.Sprintf("%s:%s", exporterEndpoint, exporterURL.Port())
}

client := otlptracehttp.NewClient(
otlptracehttp.WithEndpoint(cfg.ExporterURL),
otlptracehttp.WithEndpoint(exporterEndpoint),
withTLS,
)

Expand Down

0 comments on commit bb6b59a

Please sign in to comment.