Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tabgok committed Feb 16, 2024
1 parent e9567ef commit 134e57c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ddtrace/tracer/sqlcomment.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (c *SQLCommentCarrier) Inject(spanCtx ddtrace.SpanContext) error {
if v, ok := ctx.meta(ext.Version); ok && v != "" {
tags[sqlCommentParentVersion] = v
}
if c.PeerDBHostname != "" {
if c.PeerDBName != "" {
tags[sqlCommentPeerDBName] = c.PeerDBName
}

Expand Down
25 changes: 20 additions & 5 deletions ddtrace/tracer/sqlcomment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func TestSQLCommentCarrier(t *testing.T) {
mode DBMPropagationMode
injectSpan bool
samplingPriority int
spanTags map[string]string
peerDBHostname string
peerDBName string
expectedQuery string
expectedSpanIDGen bool
expectedExtractErr error
Expand All @@ -36,6 +37,8 @@ func TestSQLCommentCarrier(t *testing.T) {
query: "SELECT * from FOO",
mode: DBMPropagationModeFull,
injectSpan: true,
peerDBHostname: "",
peerDBName: "",
expectedQuery: "/*dddbs='whiskey-db',dde='test-env',ddps='whiskey-service%20%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D',ddpv='1.0.0',traceparent='00-0000000000000000000000000000000a-<span_id>-00'*/ SELECT * from FOO",
expectedSpanIDGen: true,
expectedExtractErr: nil,
Expand All @@ -45,6 +48,8 @@ func TestSQLCommentCarrier(t *testing.T) {
query: "SELECT * from FOO",
mode: DBMPropagationModeService,
injectSpan: true,
peerDBHostname: "",
peerDBName: "",
expectedQuery: "/*dddbs='whiskey-db',dde='test-env',ddps='whiskey-service%20%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D',ddpv='1.0.0'*/ SELECT * from FOO",
expectedSpanIDGen: false,
expectedExtractErr: ErrSpanContextNotFound,
Expand All @@ -53,6 +58,8 @@ func TestSQLCommentCarrier(t *testing.T) {
name: "no-trace",
query: "SELECT * from FOO",
mode: DBMPropagationModeFull,
peerDBHostname: "",
peerDBName: "",
expectedQuery: "/*dddbs='whiskey-db',ddps='whiskey-service%20%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D',traceparent='00-0000000000000000<span_id>-<span_id>-00'*/ SELECT * from FOO",
expectedSpanIDGen: true,
expectedExtractErr: nil,
Expand All @@ -62,6 +69,8 @@ func TestSQLCommentCarrier(t *testing.T) {
query: "",
mode: DBMPropagationModeFull,
injectSpan: true,
peerDBHostname: "",
peerDBName: "",
expectedQuery: "/*dddbs='whiskey-db',dde='test-env',ddps='whiskey-service%20%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D',ddpv='1.0.0',traceparent='00-0000000000000000000000000000000a-<span_id>-00'*/",
expectedSpanIDGen: true,
expectedExtractErr: nil,
Expand Down Expand Up @@ -92,6 +101,8 @@ func TestSQLCommentCarrier(t *testing.T) {
mode: DBMPropagationModeFull,
injectSpan: true,
samplingPriority: 1,
peerDBHostname: "",
peerDBName: "",
expectedQuery: "/*dddbs='whiskey-db',dde='test-env',ddps='whiskey-service%20%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D',ddpv='1.0.0',traceparent='00-0000000000000000000000000000000a-<span_id>-01'*/ /* c */ SELECT * from FOO /**/",
expectedSpanIDGen: true,
expectedExtractErr: nil,
Expand All @@ -102,7 +113,8 @@ func TestSQLCommentCarrier(t *testing.T) {
mode: DBMPropagationModeFull,
injectSpan: true,
samplingPriority: 1,
spanTags: map[string]string{ext.DBName: "fake-database"},
peerDBName: "fake-database",
peerDBHostname: "",
expectedQuery: "/*dddbs='whiskey-db',dde='test-env',ddps='whiskey-service%20%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D',ddpv='1.0.0',traceparent='00-0000000000000000000000000000000a-<span_id>-01',dddb='fake-database'*/ /* c */ SELECT * from FOO /**/",
expectedSpanIDGen: true,
expectedExtractErr: nil,
Expand All @@ -113,7 +125,8 @@ func TestSQLCommentCarrier(t *testing.T) {
mode: DBMPropagationModeFull,
injectSpan: true,
samplingPriority: 1,
spanTags: map[string]string{ext.TargetHost: "fake-hostname"},
peerDBHostname: "fake-hostname",
peerDBName: "",
expectedQuery: "/*dddbs='whiskey-db',dde='test-env',ddps='whiskey-service%20%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D',ddpv='1.0.0',traceparent='00-0000000000000000000000000000000a-<span_id>-01',ddh='fake-hostname'*/ /* c */ SELECT * from FOO /**/",
expectedSpanIDGen: true,
expectedExtractErr: nil,
Expand All @@ -124,7 +137,8 @@ func TestSQLCommentCarrier(t *testing.T) {
mode: DBMPropagationModeFull,
injectSpan: true,
samplingPriority: 1,
spanTags: map[string]string{ext.TargetHost: "fake-hostname", ext.DBName: "fake-database"},
peerDBHostname: "fake-hostname",
peerDBName: "fake-database",
expectedQuery: "/*dddbs='whiskey-db',dde='test-env',ddps='whiskey-service%20%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D',ddpv='1.0.0',traceparent='00-0000000000000000000000000000000a-<span_id>-01',ddh='fake-hostname',dddb='fake-database'*/ /* c */ SELECT * from FOO /**/",
expectedSpanIDGen: true,
expectedExtractErr: nil,
Expand All @@ -148,7 +162,8 @@ func TestSQLCommentCarrier(t *testing.T) {
spanCtx = root.Context()
}

carrier := SQLCommentCarrier{Query: tc.query, Mode: tc.mode, DBServiceName: "whiskey-db"}
//carrier := SQLCommentCarrier{Query: tc.query, Mode: tc.mode, DBServiceName: "whiskey-db"}
carrier := SQLCommentCarrier{Query: tc.query, Mode: tc.mode, DBServiceName: "whiskey-db", PeerDBHostname: tc.peerDBHostname, PeerDBName: tc.peerDBName}
err := carrier.Inject(spanCtx)
require.NoError(t, err)
expected := strings.ReplaceAll(tc.expectedQuery, "<span_id>", fmt.Sprintf("%016s", strconv.FormatUint(carrier.SpanID, 16)))
Expand Down

0 comments on commit 134e57c

Please sign in to comment.