Skip to content

Commit

Permalink
Merge pull request #2392 from DataDog/zarir/redis_span_kind_client
Browse files Browse the repository at this point in the history
Adds `span.kind` as `client` for `redis`
  • Loading branch information
TonyCTHsu authored Nov 22, 2022
2 parents a6a1bc5 + d1e7021 commit f6d57ad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/datadog/tracing/contrib/redis/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def call(*args, &block)
span.span_type = Contrib::Redis::Ext::TYPE
span.resource = get_command(args)
Contrib::Redis::Tags.set_common_tags(self, span)
span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)

response = super
end
Expand All @@ -43,6 +44,7 @@ def call_pipeline(*args, &block)
span.resource = commands.any? ? commands.join("\n") : '(none)'
span.set_metric Contrib::Redis::Ext::METRIC_PIPELINE_LEN, commands.length
Contrib::Redis::Tags.set_common_tags(self, span)
span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)

response = super
end
Expand Down
4 changes: 4 additions & 0 deletions spec/datadog/tracing/contrib/redis/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
port: test_port,
db: test_database
)

expect(span.get_tag('span.kind')).to eq('client')
end
end
end
Expand Down Expand Up @@ -147,6 +149,8 @@
port: test_port,
db: test_database
)

expect(span.get_tag('span.kind')).to eq('client')
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/datadog/tracing/contrib/redis/miniapp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@
expect(redis_cmd1_span.parent_id).to eq(process_span.span_id)
expect(redis_cmd1_span.trace_id).to eq(publish_span.trace_id)
expect(redis_cmd1_span.get_tag('db.system')).to eq('redis')
expect(redis_cmd2_span.get_tag('span.kind')).to eq('client')

expect(redis_cmd2_span.name).to eq('redis.command')
expect(redis_cmd2_span.service).to eq('test-service')
expect(redis_cmd2_span.parent_id).to eq(process_span.span_id)
expect(redis_cmd2_span.trace_id).to eq(publish_span.trace_id)
expect(redis_cmd2_span.get_tag('db.system')).to eq('redis')
expect(redis_cmd2_span.get_tag('span.kind')).to eq('client')
end

it_behaves_like 'a peer service span' do
Expand Down
11 changes: 11 additions & 0 deletions spec/datadog/tracing/contrib/redis/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
expect(span.resource).to eq('SET FOO bar')
expect(span.get_tag('redis.raw_command')).to eq('SET FOO bar')
expect(span.get_tag('db.system')).to eq('redis')
expect(span.get_tag('span.kind')).to eq('client')
end

it_behaves_like 'a span with common tags'
Expand All @@ -104,6 +105,7 @@
expect(span.resource).to eq('GET FOO')
expect(span.get_tag('redis.raw_command')).to eq('GET FOO')
expect(span.get_tag('db.system')).to eq('redis')
expect(span.get_tag('span.kind')).to eq('client')
end

it_behaves_like 'a span with common tags'
Expand All @@ -127,6 +129,7 @@
expect(span.resource).to eq('SET FOO bar')
expect(span.get_tag('redis.raw_command')).to eq('SET FOO bar')
expect(span.get_tag('db.system')).to eq('redis')
expect(span.get_tag('span.kind')).to eq('client')
end
end
end
Expand All @@ -147,6 +150,7 @@
expect(span.resource).to eq('SET')
expect(span.get_tag('redis.raw_command')).to be_nil
expect(span.get_tag('db.system')).to eq('redis')
expect(span.get_tag('span.kind')).to eq('client')
end
end
end
Expand Down Expand Up @@ -179,6 +183,7 @@
expect(span.resource).to eq("SET v1 0\nSET v2 0\nINCR v1\nINCR v2\nINCR v2")
expect(span.get_tag('redis.raw_command')).to eq("SET v1 0\nSET v2 0\nINCR v1\nINCR v2\nINCR v2")
expect(span.get_tag('db.system')).to eq('redis')
expect(span.get_tag('span.kind')).to eq('client')
end

it_behaves_like 'a span with common tags'
Expand All @@ -199,6 +204,7 @@
expect(span.resource).to eq("SET\nSET\nINCR\nINCR\nINCR")
expect(span.get_tag('redis.raw_command')).to be_nil
expect(span.get_tag('db.system')).to eq('redis')
expect(span.get_tag('span.kind')).to eq('client')
end
end
end
Expand All @@ -225,6 +231,7 @@
expect(span.resource).to eq('(none)')
expect(span.get_tag('redis.raw_command')).to eq('(none)')
expect(span.get_tag('db.system')).to eq('redis')
expect(span.get_tag('span.kind')).to eq('client')
end

it_behaves_like 'a span with common tags'
Expand Down Expand Up @@ -257,6 +264,7 @@
expect(span.get_tag('error.msg')).to match(/ERR unknown command/)
expect(span.get_tag('error.type')).to eq('Redis::CommandError')
expect(span.get_tag('error.stack').length).to be >= 3
expect(span.get_tag('span.kind')).to eq('client')
end

it_behaves_like 'a span with common tags'
Expand All @@ -276,6 +284,7 @@
expect(span.resource).to eq("SET K #{'x' * 47}...")
expect(span.get_tag('db.system')).to eq('redis')
expect(span.get_tag('redis.raw_command')).to eq("SET K #{'x' * 47}...")
expect(span.get_tag('span.kind')).to eq('client')
end

it_behaves_like 'a span with common tags'
Expand All @@ -299,6 +308,7 @@
expect(span.resource).to eq('GET K')
expect(span.get_tag('redis.raw_command')).to eq('GET K')
expect(span.get_tag('db.system')).to eq('redis')
expect(span.get_tag('span.kind')).to eq('client')
end

it_behaves_like 'a span with common tags'
Expand All @@ -318,6 +328,7 @@
expect(span.resource).to eq('AUTH ?')
expect(span.get_tag('redis.raw_command')).to eq('AUTH ?')
expect(span.get_tag('db.system')).to eq('redis')
expect(span.get_tag('span.kind')).to eq('client')
end

it_behaves_like 'a peer service span' do
Expand Down

0 comments on commit f6d57ad

Please sign in to comment.