Skip to content

Commit

Permalink
AWS X-Ray exporter: Only convert SQL information for SQL databases. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuraag Agrawal authored Jul 7, 2020
1 parent 3df6a48 commit 4162d00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions exporter/awsxrayexporter/translator/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func makeSQL(attributes map[string]string) (map[string]string, *SQLData) {
}
}

if len(filtered) == len(attributes) {
// Didn't filter any attributes meaning didn't have any SQL information.
if dbType != "sql" {
// Either no DB attributes or this is not an SQL DB.
return attributes, nil
}

Expand Down
16 changes: 16 additions & 0 deletions exporter/awsxrayexporter/translator/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,19 @@ func TestClientSpanWithStatementAttribute(t *testing.T) {
testWriters.release(w)
assert.True(t, strings.Contains(jsonStr, "mysql://db.example.com:3306/customers"))
}

func TestClientSpanWithNonSQLDatabase(t *testing.T) {
attributes := make(map[string]string)
attributes[semconventions.AttributeComponent] = "db"
attributes[semconventions.AttributeDBType] = "redis"
attributes[semconventions.AttributeDBInstance] = "0"
attributes[semconventions.AttributeDBStatement] = "SET key value"
attributes[semconventions.AttributeDBUser] = "readonly_user"
attributes[semconventions.AttributeDBURL] = "redis://db.example.com:3306"
attributes[semconventions.AttributeNetPeerName] = "db.example.com"
attributes[semconventions.AttributeNetPeerPort] = "3306"

filtered, sqlData := makeSQL(attributes)
assert.Nil(t, sqlData)
assert.NotNil(t, filtered)
}

0 comments on commit 4162d00

Please sign in to comment.