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

Pass the service name to instantiation spans #3383

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions spec/datadog/tracing/contrib/rails/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could test also the fallback when

service_name: database_service

is not defined.

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)
Expand Down