Skip to content

Commit

Permalink
Cleanup and logic refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tabgok committed Feb 14, 2024
1 parent 822a758 commit fde064d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
12 changes: 11 additions & 1 deletion contrib/database/sql/internal/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package internal // import "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql

import (
"net"
"net/url"
"strings"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
Expand Down Expand Up @@ -37,7 +38,16 @@ func ParseDSN(driverName, dsn string) (meta map[string]string, err error) {
return
}
default:
// not supported
// Try to parse the DSN and see if the scheme contains a known driver name.
u, err := url.Parse(dsn)
if err != nil {
// dsn is not a valid URL, so just ignore
break
}

if driverName != u.Scheme {
return ParseDSN(u.Scheme, dsn)
}
}
return reduceKeys(meta), nil
}
Expand Down
7 changes: 4 additions & 3 deletions contrib/database/sql/propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ func TestDBMPropagation(t *testing.T) {
var db *sql.DB
var err error

dsn := "dn"
if tc.dsn != "" {
db, err = Open("test", tc.dsn)
} else {
db, err = Open("test", "dn")
dsn = tc.dsn
}

db, err = Open("test", dsn)

require.NoError(t, err)

s, ctx := tracer.StartSpanFromContext(context.Background(), "test.call", tracer.WithSpanID(1))
Expand Down
5 changes: 1 addition & 4 deletions ddtrace/tracer/sqlcomment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func TestSQLCommentCarrier(t *testing.T) {
mode DBMPropagationMode
injectSpan bool
samplingPriority int
spanTags map[string]string
expectedQuery string
expectedSpanIDGen bool
expectedExtractErr error
spanTags map[string]string
}{
{
name: "default",
Expand Down Expand Up @@ -146,9 +146,6 @@ func TestSQLCommentCarrier(t *testing.T) {
root := tracer.StartSpan("service.calling.db", WithSpanID(traceID)).(*span)
root.SetTag(ext.SamplingPriority, tc.samplingPriority)
spanCtx = root.Context()
for k, v := range tc.spanTags {
root.SetTag(k, v)
}
}

carrier := SQLCommentCarrier{Query: tc.query, Mode: tc.mode, DBServiceName: "whiskey-db"}
Expand Down

0 comments on commit fde064d

Please sign in to comment.