diff --git a/ddtrace/tracer/sqlcomment.go b/ddtrace/tracer/sqlcomment.go index 0dab6ccf02..f6ffbdef5d 100644 --- a/ddtrace/tracer/sqlcomment.go +++ b/ddtrace/tracer/sqlcomment.go @@ -7,10 +7,19 @@ import ( "strings" ) +// SQLCommentCarrier holds tags to be serialized as a SQL Comment type SQLCommentCarrier struct { tags map[string]string } +// Set implements TextMapWriter. +func (c *SQLCommentCarrier) Set(key, val string) { + if c.tags == nil { + c.tags = make(map[string]string) + } + c.tags[key] = val +} + func commentWithTags(tags map[string]string) (comment string) { if len(tags) == 0 { return "" @@ -26,14 +35,8 @@ func commentWithTags(tags map[string]string) (comment string) { return fmt.Sprintf("/* %s */", comment) } -// Set implements TextMapWriter. -func (c *SQLCommentCarrier) Set(key, val string) { - if c.tags == nil { - c.tags = make(map[string]string) - } - c.tags[key] = val -} - +// CommentedQuery returns the given query with the tags from the SQLCommentCarrier applied to it as a +// prepended SQL comment func (c *SQLCommentCarrier) CommentedQuery(query string) (commented string) { comment := commentWithTags(c.tags)