-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
16 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters