From b92c0ef80686bedf0aeda64271bf5e734fdce751 Mon Sep 17 00:00:00 2001 From: Alex Normand Date: Fri, 10 Jun 2022 12:10:59 -0700 Subject: [PATCH] Make SQLCommentInjection mode a string --- contrib/database/sql/option.go | 3 ++- contrib/database/sql/sql.go | 4 ++-- ddtrace/tracer/sqlcomment.go | 12 ++++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/contrib/database/sql/option.go b/contrib/database/sql/option.go index 1861549c61..ca887772f1 100644 --- a/contrib/database/sql/option.go +++ b/contrib/database/sql/option.go @@ -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" @@ -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, diff --git a/contrib/database/sql/sql.go b/contrib/database/sql/sql.go index 857d768093..1c23d22858 100644 --- a/contrib/database/sql/sql.go +++ b/contrib/database/sql/sql.go @@ -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" ) @@ -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 diff --git a/ddtrace/tracer/sqlcomment.go b/ddtrace/tracer/sqlcomment.go index 97cc7dc303..05cd0263da 100644 --- a/ddtrace/tracer/sqlcomment.go +++ b/ddtrace/tracer/sqlcomment.go @@ -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. @@ -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: