Skip to content

Commit

Permalink
Make SQLCommentInjection mode a string
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-normand committed Jun 15, 2022
1 parent 6b53e19 commit b92c0ef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion contrib/database/sql/option.go
Expand Up @@ -7,6 +7,7 @@ package sql

import (
"math"
"os"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/internal"
Expand Down Expand Up @@ -36,7 +37,7 @@ func defaults(cfg *config) {
} else {
cfg.analyticsRate = math.NaN()
}
cfg.commentInjectionMode = tracer.SQLCommentInjectionMode(internal.IntEnv("DD_TRACE_SQL_COMMENT_INJECTION_MODE", int(tracer.SQLInjectionDisabled)))
cfg.commentInjectionMode = tracer.SQLCommentInjectionMode(os.Getenv("DD_TRACE_SQL_COMMENT_INJECTION_MODE"))
}

// WithServiceName sets the given service name when registering a driver,
Expand Down
4 changes: 2 additions & 2 deletions contrib/database/sql/sql.go
Expand Up @@ -21,12 +21,12 @@ import (
"database/sql"
"database/sql/driver"
"errors"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"math"
"reflect"
"time"

"gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql/internal"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
)

Expand Down Expand Up @@ -187,7 +187,7 @@ func OpenDB(c driver.Connector, opts ...Option) *sql.DB {
if math.IsNaN(cfg.analyticsRate) {
cfg.analyticsRate = rc.analyticsRate
}
if cfg.commentInjectionMode == tracer.SQLInjectionDisabled {
if cfg.commentInjectionMode == tracer.SQLInjectionUndefined {
cfg.commentInjectionMode = rc.commentInjectionMode
}
cfg.childSpansOnly = rc.childSpansOnly
Expand Down
12 changes: 8 additions & 4 deletions ddtrace/tracer/sqlcomment.go
Expand Up @@ -15,15 +15,17 @@ import (
)

// SQLCommentInjectionMode represents the mode of SQL comment injection.
type SQLCommentInjectionMode int
type SQLCommentInjectionMode string

const (
// SQLInjectionUndefined represents the comment injection mode is not set. This is the same as SQLInjectionDisabled.
SQLInjectionUndefined SQLCommentInjectionMode = ""
// SQLInjectionDisabled represents the comment injection mode where all injection is disabled.
SQLInjectionDisabled SQLCommentInjectionMode = 0
SQLInjectionDisabled SQLCommentInjectionMode = "disabled"
// SQLInjectionModeService represents the comment injection mode where only service tags (name, env, version) are injected.
SQLInjectionModeService SQLCommentInjectionMode = 1
SQLInjectionModeService SQLCommentInjectionMode = "service"
// SQLInjectionModeFull represents the comment injection mode where both service tags and tracing tags. Tracing tags include span id, trace id and sampling priority.
SQLInjectionModeFull SQLCommentInjectionMode = 2
SQLInjectionModeFull SQLCommentInjectionMode = "full"
)

// Key names for SQL comment tags.
Expand All @@ -50,6 +52,8 @@ func (c *SQLCommentCarrier) Inject(spanCtx ddtrace.SpanContext) error {
c.SpanID = random.Uint64()
tags := make(map[string]string)
switch c.Mode {
case SQLInjectionUndefined:
fallthrough
case SQLInjectionDisabled:
return nil
case SQLInjectionModeFull:
Expand Down

0 comments on commit b92c0ef

Please sign in to comment.