Skip to content

Commit

Permalink
fix: dsn without a HTTP port
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Nov 5, 2023
1 parent d9d517a commit e641455
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 9 additions & 2 deletions uptrace/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func (dsn *DSN) SiteURL() string {
if dsn.Host == "uptrace.dev" {
return "https://app.uptrace.dev"
}
return dsn.Scheme + "://" + net.JoinHostPort(dsn.Host, dsn.HTTPPort)
return dsn.Scheme + "://" + joinHostPort(dsn.Host, dsn.HTTPPort)
}

func (dsn *DSN) OTLPEndpoint() string {
if dsn.Host == "uptrace.dev" {
return "otlp.uptrace.dev:4317"
}
return net.JoinHostPort(dsn.Host, dsn.GRPCPort)
return joinHostPort(dsn.Host, dsn.GRPCPort)
}

func ParseDSN(dsnStr string) (*DSN, error) {
Expand Down Expand Up @@ -84,3 +84,10 @@ func ParseDSN(dsnStr string) (*DSN, error) {

return &dsn, nil
}

func joinHostPort(host, port string) string {
if port == "" {
return host
}
return net.JoinHostPort(host, port)
}
11 changes: 8 additions & 3 deletions uptrace/dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ func TestParseDSN(t *testing.T) {
}

tests := []Test{
{"https://key@uptrace.dev/1", "otlp.uptrace.dev:4317", "https://app.uptrace.dev"},
{"https://key@api.uptrace.dev/1", "otlp.uptrace.dev:4317", "https://app.uptrace.dev"},
{"https://key@localhost:1234/1", "localhost:1234", "https://localhost:1234"},
{"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@demo.uptrace.dev/1?grpc=4317",
"demo.uptrace.dev:4317",
"https://demo.uptrace.dev",
},
{"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",
Expand Down

0 comments on commit e641455

Please sign in to comment.