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

Tweak rack resource name #2180

Merged
merged 12 commits into from
Aug 2, 2022
Merged

Tweak rack resource name #2180

merged 12 commits into from
Aug 2, 2022

Conversation

TonyCTHsu
Copy link
Contributor

What does this PR do?
Resource of rack span is not really useful in terms of aggregation, should be overwritten by its nested app, namely Rails.

Rails w/ request_queuing enabled

Screenshot 2022-07-25 at 12 49 13
quest_queuing enabled

Rails w/o request_queuing enabled
Screenshot 2022-07-25 at 12 53 13

Additional Notes

How to test the change?

@TonyCTHsu TonyCTHsu self-assigned this Jul 25, 2022
@TonyCTHsu TonyCTHsu added this to the 1.3.0 milestone Jul 25, 2022
Comment on lines 44 to 45
# Will be set later, avoid setting the trace.resource to propagate to rack span resource
frontend_span.resource = nil
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious, does this do anything? Tracing.trace delegates to Tracer#trace which appears to me to use resource: nil as a default.

Copy link
Contributor Author

@TonyCTHsu TonyCTHsu Jul 26, 2022

Choose a reason for hiding this comment

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

Yes, it makes a difference, in terms of delaying the decision of setting resource for TraceOperation. When a TraceOperation initialize without an explicit resource, resource would be delegate to its root span. (see here)

      def resource
        @resource || (root_span && root_span.resource)
      end

Usually rack span is the root span, but proxy span becomes the root span when request_queuing enabled. While I want to make sure resource of root span is nil.

My train of thoughts of this implementation is to allow the downstream tracing behaviour(namely Rails controller) to determine the rack resource by setting the trace.resource, hence I want to avoid upstream tracing (proxy span) writing to resource just like the rack span.

So, in short, delay setting resource for both rack and proxy span, while

  1. Resource of rack span could be overwritten by nested app, such as Rails controller
  2. Resource of proxy span remains to be the same and got assigned before finishing

Copy link
Member

Choose a reason for hiding this comment

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

I see, thanks for clarifying this 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After discussion, I've change the implementation. Instead of setting proxy span's resource as nil, implement TraceOperation#resource_override? to answer whether trace.resource has been explicitly set, to distinguish the delegation in TraceOperation#resource

The priority of rack span resource is

  1. User overrides span.resource
  2. Configuration
  3. Nested App override trace.resource, eq UsersController#show
  4. Fallback with verb + status, eq GET 200

https://github.com/DataDog/dd-trace-rb/pull/2180/files#diff-5934ebefd042f70e1c83157584faa0f1d97f1777aa9621d089e0dc3273108c79R139-R151

@TonyCTHsu TonyCTHsu marked this pull request as ready for review July 27, 2022 06:39
@TonyCTHsu TonyCTHsu requested a review from a team July 27, 2022 06:39
@codecov-commenter
Copy link

Codecov Report

Merging #2180 (ecb35be) into master (17aac0c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2180   +/-   ##
=======================================
  Coverage   97.46%   97.46%           
=======================================
  Files        1043     1043           
  Lines       54265    54347   +82     
=======================================
+ Hits        52889    52970   +81     
- Misses       1376     1377    +1     
Impacted Files Coverage Δ
lib/datadog/tracing/contrib/rack/middlewares.rb 99.02% <100.00%> (ø)
lib/datadog/tracing/trace_operation.rb 98.83% <100.00%> (+0.01%) ⬆️
...acing/contrib/action_cable/instrumentation_spec.rb 97.43% <100.00%> (ø)
spec/datadog/tracing/contrib/grape/tracer_spec.rb 99.81% <100.00%> (ø)
...adog/tracing/contrib/rack/integration_test_spec.rb 100.00% <100.00%> (ø)
...c/datadog/tracing/contrib/rails/middleware_spec.rb 97.25% <100.00%> (ø)
spec/datadog/tracing/contrib/rails/rack_spec.rb 100.00% <100.00%> (ø)
spec/datadog/tracing/trace_operation_spec.rb 100.00% <100.00%> (ø)
...adog/tracing/contrib/sidekiq/server_tracer_spec.rb 99.16% <0.00%> (-0.84%) ⬇️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@TonyCTHsu TonyCTHsu merged commit 8c9806d into master Aug 2, 2022
@TonyCTHsu TonyCTHsu deleted the feature/rack-resource-name branch August 2, 2022 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants