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

Use media_type instead of content_type when avaliable #2855

Merged
merged 6 commits into from
Sep 25, 2024

Conversation

hannahramadan
Copy link
Contributor

@hannahramadan hannahramadan commented Sep 23, 2024

Rails 7.0 changed the behavior of ActionDispatch::Request#content_type, adding extra request-related details the agent wasn't expecting to collect, such as charset. Additionally, the agent's use of content_type was triggering deprecation warnings. This PR updated the agent to use ActionDispatch::Request#media_type to capture the MIME type when available.

Closes #2506

@hannahramadan hannahramadan changed the title Use media_type instead of content_type for Rails 7.1+ Use media_type instead of content_type when avaliable Sep 23, 2024
CHANGELOG.md Outdated
@@ -56,6 +56,10 @@ Version <dev> adds Apache Kafka instrumentation for the rdkafka and ruby-kafka g

[PR#2851](https://github.com/newrelic/newrelic-ruby-agent/pull/2851)

- **Feature: Collect just MIME type from AcionDispatch requests**
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe at a byline to the summary for this version as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking for version in title? 60dcfc9

@@ -24,7 +24,7 @@ def initialize(request)
@referer = referer_from_request(request)
@accept = attribute_from_env(request, HTTP_ACCEPT_HEADER_KEY)
@content_length = content_length_from_request(request)
@content_type = attribute_from_request(request, :content_type)
@content_type = content_type_attribute_from_request(request)
Copy link
Contributor

Choose a reason for hiding this comment

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

Optionally, you could simply leverage the existing attribute_from_method's functionality instead of creating a special one-off method for content-type.

Suggested change
@content_type = content_type_attribute_from_request(request)
@content_type = content_type_attribute_from_request(request)
@content_type = attribute_from_request(request, :media_type) || attribute_from_request(request, :content_type)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I love the simplicity of just using one method, I liked having that longer comment + link explaining the change and it looked a bit off here.

@hannahramadan hannahramadan marked this pull request as ready for review September 24, 2024 20:47
Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

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

👏

CHANGELOG.md Show resolved Hide resolved
Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

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

🌻

Copy link
Contributor

SimpleCov Report

Coverage Threshold
Line 93.8% 93%
Branch 69.67% 50%

@hannahramadan hannahramadan merged commit 2dfd223 into dev Sep 25, 2024
32 checks passed
@hannahramadan hannahramadan deleted the will_you_be_mime branch September 25, 2024 19:00
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.

Replace Rails content_type header with media_type
3 participants