From e5f064a9c18d30624c180bb2930befc4d9d24b57 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Tue, 16 Jan 2024 00:18:52 +0100 Subject: [PATCH] Pass the service name to instantiation spans Comment put at the time where not reflecting setup of a specific service_name. https://github.com/DataDog/dd-trace-rb/commit/f64a90c88369dad6bcf6109524f52a10361033fc#diff-480dabeac4cb83aeebfd219880fbbaafff3c0b3a83cef7b2fa0e3819e3b516a5R60-R61 --- .../contrib/active_record/events/instantiation.rb | 9 +++++++++ spec/datadog/tracing/contrib/rails/database_spec.rb | 5 ++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/datadog/tracing/contrib/active_record/events/instantiation.rb b/lib/datadog/tracing/contrib/active_record/events/instantiation.rb index 7e529c1e78d..d1553bd7f0f 100644 --- a/lib/datadog/tracing/contrib/active_record/events/instantiation.rb +++ b/lib/datadog/tracing/contrib/active_record/events/instantiation.rb @@ -30,6 +30,15 @@ def span_name end def process(span, event, _id, payload) + config = Utils.connection_config(payload[:connection], payload[:connection_id]) + settings = Datadog.configuration.tracing[:active_record, config] + adapter_name = Contrib::Utils::Database.normalize_vendor(config[:adapter]) + service_name = if settings.service_name != Contrib::Utils::Database::VENDOR_DEFAULT + settings.service_name + else + adapter_name + end + span.service = service_name span.resource = payload.fetch(:class_name) span.span_type = Ext::SPAN_TYPE_INSTANTIATION span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT) diff --git a/spec/datadog/tracing/contrib/rails/database_spec.rb b/spec/datadog/tracing/contrib/rails/database_spec.rb index 24fa1715786..e879f0c3471 100644 --- a/spec/datadog/tracing/contrib/rails/database_spec.rb +++ b/spec/datadog/tracing/contrib/rails/database_spec.rb @@ -82,8 +82,7 @@ span, = spans expect(span.name).to eq('active_record.instantiation') expect(span.span_type).to eq('custom') - # Because no parent, and doesn't belong to database service - expect(span.service).to eq(tracer.default_service) + expect(span.service).to eq(database_service) expect(span.resource).to eq('Article') expect(span.get_tag('active_record.instantiation.class_name')).to eq('Article') expect(span.get_tag('active_record.instantiation.record_count')).to eq(1) @@ -110,7 +109,7 @@ expect(instantiation_span.name).to eq('active_record.instantiation') expect(instantiation_span.span_type).to eq('custom') - expect(instantiation_span.service).to eq(tracer.default_service) # Because within parent + expect(instantiation_span.service).to eq(database_service) expect(instantiation_span.resource).to eq('Article') expect(instantiation_span.get_tag('active_record.instantiation.class_name')).to eq('Article') expect(instantiation_span.get_tag('active_record.instantiation.record_count')).to eq(1)