Skip to content

Commit

Permalink
Responding to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tabgok committed Feb 22, 2024
1 parent 2138e10 commit b51d551
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 12 additions & 3 deletions contrib/database/sql/internal/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
)

// ParseDSN parses various supported DSN types into a map of key/value pairs which can be used as valid tags.
Expand All @@ -20,26 +21,34 @@ func ParseDSN(driverName, dsn string) (meta map[string]string, err error) {
case "mysql":
meta, err = parseMySQLDSN(dsn)
if err != nil {
log.Debug("Error parsing DSN for mysql: %v", err)
return
}
case "postgres", "pgx":
meta, err = parsePostgresDSN(dsn)
if err != nil {
log.Debug("Error parsing DSN for postgres: %v", err)
return
}
case "sqlserver":
meta, err = parseSQLServerDSN(dsn)
if err != nil {
log.Debug("Error parsing DSN for sqlserver: %v", err)
return
}
default:
// Try to parse the DSN and see if the scheme contains a known driver name.
u, err := url.Parse(dsn)
if err != nil {
u, e := url.Parse(dsn)
if e != nil {
// dsn is not a valid URL, so just ignore
break
log.Debug("Error parsing driver name from DSN: %v", e)
return
}
if driverName != u.Scheme {
// In some cases the driver is registered under a non-official name.
// For example, "Test" may be the registered name with a DSN of "postgres://postgres:[email protected]:5432/fakepreparedb"
// for the purposes of testing/mocking.
// In these cases, we try to parse the DSN based upon the DSN itself, instead of the registered driver name
return ParseDSN(u.Scheme, dsn)
}
}
Expand Down
6 changes: 4 additions & 2 deletions ddtrace/tracer/sqlcomment.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ const (
sqlCommentDBService = "dddbs"
sqlCommentParentVersion = "ddpv"
sqlCommentEnv = "dde"
sqlCommentPeerHostname = "ddh"
sqlCommentPeerDBName = "dddb"
// These keys are for the database we are connecting to, instead of the service we are running in.
// "Peer" is the OpenTelemetry nomenclature for "thing I am talking to"
sqlCommentPeerHostname = "ddh"
sqlCommentPeerDBName = "dddb"
)

// Current trace context version (see https://www.w3.org/TR/trace-context/#version)
Expand Down

0 comments on commit b51d551

Please sign in to comment.