diff --git a/uptrace/dsn.go b/uptrace/dsn.go index 875ea2e8..6a5d90a3 100644 --- a/uptrace/dsn.go +++ b/uptrace/dsn.go @@ -76,6 +76,14 @@ func ParseDSN(dsnStr string) (*DSN, error) { if dsn.Host == "api.uptrace.dev" { dsn.Host = "uptrace.dev" } + if dsn.HTTPPort == "" { + switch dsn.Scheme { + case "http": + dsn.HTTPPort = "80" + case "https": + dsn.HTTPPort = "443" + } + } query := u.Query() if grpc := query.Get("grpc"); grpc != "" { diff --git a/uptrace/dsn_test.go b/uptrace/dsn_test.go index eea2a696..e3887331 100644 --- a/uptrace/dsn_test.go +++ b/uptrace/dsn_test.go @@ -12,28 +12,52 @@ import ( func TestParseDSN(t *testing.T) { type Test struct { dsn string - otlp string + grpc string + http string siteURL string } tests := []Test{ - {"https://token@uptrace.dev/1", "otlp.uptrace.dev:4317", "https://app.uptrace.dev"}, - {"https://token@api.uptrace.dev/1", "otlp.uptrace.dev:4317", "https://app.uptrace.dev"}, + { + "https://token@uptrace.dev/1", + "otlp.uptrace.dev:4317", + "otlp.uptrace.dev:443", + "https://app.uptrace.dev", + }, + { + "https://token@api.uptrace.dev/1", + "otlp.uptrace.dev:4317", + "otlp.uptrace.dev:443", + "https://app.uptrace.dev", + }, { "https://token@demo.uptrace.dev/1?grpc=4317", "demo.uptrace.dev:4317", - "https://demo.uptrace.dev", + "demo.uptrace.dev:443", + "https://demo.uptrace.dev:443", + }, + { + "https://token@localhost:1234/1", + "localhost:1234", + "localhost:1234", + "https://localhost:1234", + }, + { + "http://token@localhost:14317/project_id", + "localhost:14317", + "localhost:14318", + "http://localhost:14318", }, - {"https://token@localhost:1234/1", "localhost:1234", "https://localhost:1234"}, - {"http://token@localhost:14317/project_id", "localhost:14317", "http://localhost:14318"}, { "https://AQDan_E_EPe3QAF9fMP0PiVr5UWOu4q5@demo-api.uptrace.dev:4317/1", "demo-api.uptrace.dev:4317", + "demo-api.uptrace.dev:4317", "https://demo-api.uptrace.dev:4317", }, { "http://Qcn7rcwWO_w0ePo7WmeUtw@localhost:14318?grpc=14317", "localhost:14317", + "localhost:14318", "http://localhost:14318", }, } @@ -41,7 +65,8 @@ func TestParseDSN(t *testing.T) { t.Run(fmt.Sprint(i), func(t *testing.T) { dsn, err := uptrace.ParseDSN(test.dsn) require.NoError(t, err) - require.Equal(t, test.otlp, dsn.OTLPEndpoint()) + require.Equal(t, test.grpc, dsn.OTLPGrpcEndpoint()) + require.Equal(t, test.http, dsn.OTLPHttpEndpoint()) require.Equal(t, test.siteURL, dsn.SiteURL()) }) }