-
Notifications
You must be signed in to change notification settings - Fork 375
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
Improve rack resource names #285
Conversation
c68a070
to
b54a109
Compare
|
||
def resource_name_for(env, status) | ||
if Datadog.configuration[:rack][:middleware_names] | ||
return "#{env['RESPONSE_MIDDLEWARE']}##{env['REQUEST_METHOD']}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, non-blocking thing: would it be cleaner to do a simple if else
instead of a return
? Usually I see return
only if you need to short-circuit a lot of code quickly (Opting not to use return
is usually out of the general concern of return
's side effects.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll make that change 👍
lib/ddtrace/contrib/rack/patcher.rb
Outdated
end | ||
|
||
def patched? | ||
return @patched if defined?(@patched) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow this... "Return patched if patched defined, otherwise return... patched"? Redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for having a memoized value that can be false
.
Ideally we should have:
def patched?
@patched ||= false
end
But that obviously doesn't work for falsey values.
2531c27
to
f5a0551
Compare
f5a0551
to
f1e0eea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This PR is an attempt to provide better resource names for
rack
.Currently, rack resource names are
<REQUEST_METHOD> <RESPONSE_STATUS>
.We're providing an alternative that should generate more meaningful names. The approach taken here is to return the name of the middleware that effectively generated the response.
Let's say you have an
AuthenticationMiddleware
. In a Rails application context, an unauthorized request would never hit the Rails stack and it would surface as something like aGET 401
resource name.By enabling the
middleware_names
option will you get aAuthenticationMiddleware#GET
resource name instead.Also worth noting here that in case the HTTP request ever "hits" your Sinatra/Rails routing layer you will still get the resource names provided by them (e.g,
MailerController#create
)