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 URL query string quantization to Rack #371

Merged
merged 1 commit into from
Mar 27, 2018

Conversation

delner
Copy link
Contributor

@delner delner commented Mar 19, 2018

Adds quantization for Rack URL query string parameters. This behavior is activated by default, but can be configured with:

Datadog.configure do |c|
  # Default behavior: all values are quantized, fragment is removed.
  # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path?category_id&sort_by
  # http://example.com/path?categories[]=1&categories[]=2 --> http://example.com/path?categories[]

  # Show values for any query string parameter matching 'category_id' exactly
  # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path?category_id=1&sort_by
  c.use :rack, quantize: { query: { show: ['category_id'] } }

  # Show all values for all query string parameters
  # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path?category_id=1&sort_by=asc
  c.use :rack, quantize: { query: { show: :all } }

  # Totally exclude any query string parameter matching 'sort_by' exactly
  # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path?category_id
  c.use :rack, quantize: { query: { exclude: ['sort_by'] } }

  # Remove the query string entirely
  # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path
  c.use :rack, quantize: { query: { exclude: :all } }

  # Show URL fragments
  # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path?category_id&sort_by#featured
  c.use :rack, quantize: { fragment: :show }
end

@delner delner added integrations Involves tracing integrations feature Involves a product feature labels Mar 19, 2018
@delner delner added this to the 0.12.0 milestone Mar 19, 2018
@delner delner self-assigned this Mar 19, 2018
@delner delner added the breaking-change Involves a breaking change label Mar 19, 2018
@delner delner force-pushed the feature/quantize_http_query_strings branch 2 times, most recently from a72564b to 4cfa5d0 Compare March 20, 2018 18:40
Copy link
Contributor

@palazzem palazzem left a comment

Choose a reason for hiding this comment

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

couple of things, but I think it's great in the overall!

Configuring URL quantization behavior:

```
Datadog.configure do |c|
Copy link
Contributor

Choose a reason for hiding this comment

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

nice write up!

module Datadog
module Contrib
module Rack
# Quantize contains Rack-specic quantization tools.
Copy link
Contributor

Choose a reason for hiding this comment

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

specific

Copy link
Contributor Author

Choose a reason for hiding this comment

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

facepalm

@@ -104,7 +105,8 @@ def set_request_tags!(request_span, env, status, headers, response, original_env
request_span.set_tag(Datadog::Ext::HTTP::METHOD, env['REQUEST_METHOD'])
end
if request_span.get_tag(Datadog::Ext::HTTP::URL).nil?
request_span.set_tag(Datadog::Ext::HTTP::URL, url)
options = Datadog.configuration[:rack][:quantize]
request_span.set_tag(Datadog::Ext::HTTP::URL, Quantize.format_url(url, options))
Copy link
Contributor

Choose a reason for hiding this comment

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

can we handle any kind of exception here? since it's the first middleware, in case of an issue (i.e. encoding/decoding/filtering problem) would be great to avoid propagating our internal exception. I think it's enough to handle the exception somewhere, and log it as debug().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@palazzem are you talking about this tagging function in general? Or specifically the use of quantization here?

it { is_expected.to eq('foo[]=bar&foo[]=baz') }

context 'that contains encoded braces' do
let(:query_string) { 'foo[]=%5Bbar%5D&foo[]=%5Bbaz%5D' }
Copy link
Contributor

Choose a reason for hiding this comment

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

since it's a free function and can be used somewhere else, can we add a test without using URL encoding? so a query string such as value=繋がってて.

Copy link
Contributor Author

@delner delner Mar 22, 2018

Choose a reason for hiding this comment

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

Great idea. I'll add in some more edge case tests around encoding and Unicode characters.

@delner delner force-pushed the feature/quantize_http_query_strings branch from 4cfa5d0 to 1d5f17c Compare March 26, 2018 21:29
@delner delner added do-not-merge/WIP Not ready for merge and removed breaking-change Involves a breaking change labels Mar 26, 2018
@delner
Copy link
Contributor Author

delner commented Mar 26, 2018

This feature is dependent on #384 and should be rebased and merged after that PR is merged.

Do we want to consider this a breaking change? Requires no action on the user's part, but will change their URLs/query strings.

@palazzem
Copy link
Contributor

@delner not really since it doesn't impact the API or anything else. I think it's enough to mention this in our migration guide just to let them know the new behavior. Metrics and anything else is not impacted.

@delner delner force-pushed the feature/quantize_http_query_strings branch from 1d5f17c to dacba60 Compare March 27, 2018 15:43
@delner delner removed the do-not-merge/WIP Not ready for merge label Mar 27, 2018
@delner delner merged commit f9cd181 into 0.12-dev Mar 27, 2018
@delner delner deleted the feature/quantize_http_query_strings branch April 5, 2018 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Involves a product feature integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants