diff --git a/contrib/gocql/gocql/gocql.go b/contrib/gocql/gocql/gocql.go index 48202098da..87b7a49d68 100644 --- a/contrib/gocql/gocql/gocql.go +++ b/contrib/gocql/gocql/gocql.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "strconv" + "strings" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext" @@ -49,7 +50,14 @@ func WrapQuery(q *gocql.Query, opts ...WrapOption) *Query { fn(cfg) } if cfg.resourceName == "" { - cfg.resourceName = q.Statement() + q := `"` + strings.SplitN(q.String(), "\"", 3)[1] + `"` + q, err := strconv.Unquote(q) + if err != nil { + // avoid having an empty resource as it will cause the trace + // to be dropped. + q = "_" + } + cfg.resourceName = q } tq := &Query{q, ¶ms{config: cfg}, context.Background()} return tq