Skip to content

Commit 01f6cff

Browse files
committed
chore: more dsn tests
1 parent 75b898d commit 01f6cff

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

uptrace/client.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ func (c *client) ForceFlush(ctx context.Context) (lastErr error) {
5454

5555
// TraceURL returns the trace URL for the span.
5656
func (c *client) TraceURL(span trace.Span) string {
57-
return fmt.Sprintf(
58-
"%s://%s/traces/%s",
59-
c.dsn.Scheme, c.dsn.AppHost(), span.SpanContext().TraceID(),
60-
)
57+
return fmt.Sprintf("%s/traces/%s", c.dsn.AppAddr(), span.SpanContext().TraceID())
6158
}
6259

6360
// ReportError reports an error as a span event creating a dummy span if necessary.

uptrace/dsn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ func (dsn *DSN) String() string {
2020
return dsn.original
2121
}
2222

23-
func (dsn *DSN) AppHost() string {
23+
func (dsn *DSN) AppAddr() string {
2424
if dsn.Host == "uptrace.dev" {
25-
return "app.uptrace.dev"
25+
return "https://app.uptrace.dev"
2626
}
2727
host, _, err := net.SplitHostPort(dsn.Host)
2828
if err != nil {
2929
return dsn.Host
3030
}
31-
return net.JoinHostPort(host, "15678")
31+
return dsn.Scheme + "://" + net.JoinHostPort(host, "14318")
3232
}
3333

3434
func (dsn *DSN) OTLPHost() string {

uptrace/dsn_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@ func TestParseDSN(t *testing.T) {
2424
require.NoError(t, err)
2525
require.Equal(t, test.otlp, dsn.OTLPHost())
2626
}
27+
28+
dsn, err := uptrace.ParseDSN("http://localhost:14317")
29+
require.NoError(t, err)
30+
require.Equal(t, "localhost:14317", dsn.OTLPHost())
31+
require.Equal(t, "http://localhost:14318", dsn.AppAddr())
32+
33+
dsn, err = uptrace.ParseDSN("https://key@uptrace.dev/project_id")
34+
require.NoError(t, err)
35+
require.Equal(t, "otlp.uptrace.dev:4317", dsn.OTLPHost())
36+
require.Equal(t, "https://app.uptrace.dev", dsn.AppAddr())
2737
}

0 commit comments

Comments
 (0)