Skip to content

Fix handling of db system in xray exporter. #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exporter/awsxrayexporter/translator/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestClientSpanWithDbComponent(t *testing.T) {
parentSpanID := newSegmentID()
enterpriseAppID := "25F2E73B-4769-4C79-9DF3-7EBE85D571EA"
attributes := make(map[string]interface{})
attributes[semconventions.AttributeDBSystem] = "sql"
attributes[semconventions.AttributeDBSystem] = "mysql"
attributes[semconventions.AttributeDBName] = "customers"
attributes[semconventions.AttributeDBStatement] = spanName
attributes[semconventions.AttributeDBUser] = "userprefsvc"
Expand Down
37 changes: 33 additions & 4 deletions exporter/awsxrayexporter/translator/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func makeSQL(attributes map[string]string) (map[string]string, *SQLData) {
filtered = make(map[string]string)
sqlData SQLData
dbURL string
dbType string
dbSystem string
dbInstance string
dbStatement string
dbUser string
Expand All @@ -46,7 +46,7 @@ func makeSQL(attributes map[string]string) (map[string]string, *SQLData) {
case semconventions.AttributeDBConnectionString:
dbURL = value
case semconventions.AttributeDBSystem:
dbType = value
dbSystem = value
case semconventions.AttributeDBName:
dbInstance = value
case semconventions.AttributeDBStatement:
Expand All @@ -58,7 +58,7 @@ func makeSQL(attributes map[string]string) (map[string]string, *SQLData) {
}
}

if dbType != "sql" {
if !isSQL(dbSystem) {
// Either no DB attributes or this is not an SQL DB.
return attributes, nil
}
Expand All @@ -69,9 +69,38 @@ func makeSQL(attributes map[string]string) (map[string]string, *SQLData) {
url := dbURL + "/" + dbInstance
sqlData = SQLData{
URL: url,
DatabaseType: dbType,
DatabaseType: dbSystem,
User: dbUser,
SanitizedQuery: dbStatement,
}
return filtered, &sqlData
}

func isSQL(system string) bool {
switch system {
case "db2":
fallthrough
case "derby":
fallthrough
case "hive":
fallthrough
case "mariadb":
fallthrough
case "mssql":
fallthrough
case "mysql":
fallthrough
case "oracle":
fallthrough
case "postgresql":
fallthrough
case "sqlite":
fallthrough
case "teradata":
fallthrough
case "other_sql":
return true
default:
}
return false
}
4 changes: 2 additions & 2 deletions exporter/awsxrayexporter/translator/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func TestClientSpanWithStatementAttribute(t *testing.T) {
attributes := make(map[string]string)
attributes[semconventions.AttributeComponent] = "db"
attributes[semconventions.AttributeDBSystem] = "sql"
attributes[semconventions.AttributeDBSystem] = "mysql"
attributes[semconventions.AttributeDBName] = "customers"
attributes[semconventions.AttributeDBStatement] = "SELECT * FROM user WHERE user_id = ?"
attributes[semconventions.AttributeDBUser] = "readonly_user"
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestClientSpanWithNonSQLDatabase(t *testing.T) {
func TestClientSpanWithoutDBurlAttribute(t *testing.T) {
attributes := make(map[string]string)
attributes[semconventions.AttributeComponent] = "db"
attributes[semconventions.AttributeDBSystem] = "sql"
attributes[semconventions.AttributeDBSystem] = "postgresql"
attributes[semconventions.AttributeDBName] = "customers"
attributes[semconventions.AttributeDBStatement] = "SELECT * FROM user WHERE user_id = ?"
attributes[semconventions.AttributeDBUser] = "readonly_user"
Expand Down