Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds span.kind with values producer and consumer for delayed_job #2393

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/datadog/tracing/contrib/delayed_job/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def self.instrument_invoke(job, &block)
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_JOB)

span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CONSUMER)

yield job
end
end
Expand All @@ -59,6 +61,8 @@ def self.instrument_enqueue(job, &block)
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_ENQUEUE)

span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_PRODUCER)

yield job
end
end
Expand Down
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
8 changes: 8 additions & 0 deletions spec/datadog/tracing/contrib/delayed_job/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ def perform
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION))
.to eq(Datadog::Tracing::Contrib::DelayedJob::Ext::TAG_OPERATION_JOB)
end

it 'has span.kind tag with value consumer' do
expect(span.get_tag('span.kind')).to eq('consumer')
end
end

describe 'enqueue span' do
Expand Down Expand Up @@ -211,6 +215,10 @@ def perform
expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION))
.to eq(Datadog::Tracing::Contrib::DelayedJob::Ext::TAG_OPERATION_ENQUEUE)
end

it 'has span.kind tag with value producer' do
expect(span.get_tag('span.kind')).to eq('producer')
end
end

describe 'reserve_job span' do
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