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

Add Roda support for newrelic_ignore* #2267

Merged
merged 10 commits into from
Oct 17, 2023
Merged

Add Roda support for newrelic_ignore* #2267

merged 10 commits into from
Oct 17, 2023

Conversation

hannahramadan
Copy link
Contributor

Add the ability for New Relic to ignore particular requests within Roda applications using:

  • newrelic_ignore
  • newrelic_ignore_apdex
  • newrelic_ignore_enduser

Closes #2165

@hannahramadan hannahramadan marked this pull request as ready for review October 17, 2023 21:37
fallwith
fallwith previously approved these changes Oct 17, 2023

def test_regex_ignores_intended_route
get('/ignore_me')
get('/ignore_me_not')
Copy link
Contributor

Choose a reason for hiding this comment

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

Including both desired and undesired is a great approach!

return false if !app.opts.include?(:newrelic_ignores)

app.opts[:newrelic_ignores][type].any? do |pattern|
pattern === app.request.path_info
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why did you choose to use ===?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes pattern is a string when a user specifies a route. But if they don't specify a route, then pattern becomes a regexp /.*/.

So sometimes we get string === string. And in string land == and === are alias of one another.

But in regexp land, == is for comparing regexps and === is for comparing regexps to strings, which app.request.path_info should always be.

I think there may have been a more clever way to write this by always turning strings into regexps, but this is where I landed. Open to alt ideas ◡̈

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a very clever solution! Thanks for breaking it down! 🙂

Comment on lines 11 to 21
def assert_enduser_ignored(response)
refute_match(/#{JS_AGENT_LOADER}/o, response.body)
end

def refute_enduser_ignored(response)
assert_match(/#{JS_AGENT_LOADER}/o, response.body)
end

def fake_html_for_browser_timing_header
'<html><head><title></title></head><body></body></html>'
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it work for you to move these methods into the class that calls them? Optionally, you could make them private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made them private since more than one class uses them 0a4c140

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This looks better 😎 3b755c1


Rails 7.1 introduced the public API [`ActiveSupport::BroadcastLogger`](https://api.rubyonrails.org/classes/ActiveSupport/BroadcastLogger.html). This logger replaces a private API, `ActiveSupport::Logger.broadcast`. In Rails versions below 7.1, the agent uses the `broadcast` method to stop duplicate logs from being recoded by broadcasted loggers. Now, we've updated the code to provide a similar duplication fix for the `ActiveSupport::BroadcastLogger` class. [PR#2252](https://github.com/newrelic/newrelic-ruby-agent/pull/2252)

- **Fix: Resolve Sidekiq 8.0 error handler deprecation warning**
- **Bugfix: Resolve Sidekiq 8.0 error handler deprecation warning**
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

- `newrelic_ignore_apdex`: exclude a given route from consideration in overall Apdex calculations.
- `newrelic_ignore_enduser`: prevent automatic injection of the page load timing JavaScript when a route is rendered.

For more information, see [Roda Instrumentation](https://docs.newrelic.com/docs/apm/agents/ruby-agent/instrumented-gems/roda-instrumentation/). [PR#2267](https://github.com/newrelic/newrelic-ruby-agent/pull/2267)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have a separate issue to track updating these docs to include the ignore methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't yet, but it's next on the list! Happy to hold this merge until we can get a docs PR going.

@github-actions
Copy link
Contributor

SimpleCov Report

Coverage Threshold
Line 94.07% 94%
Branch 85.66% 85%

@hannahramadan hannahramadan merged commit 10e75d1 into dev Oct 17, 2023
@hannahramadan hannahramadan deleted the roda_newrelic_ignore branch October 17, 2023 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Roda: add support for newrelic_ignore_*
3 participants