-
-
Notifications
You must be signed in to change notification settings - Fork 540
feat(data-collection): Port redis, net:http, faraday and excon #3032
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,39 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "uri" | ||
|
|
||
| module Sentry | ||
| module Utils | ||
| module HttpTracing | ||
| def filter_query_params(query) | ||
| return nil unless query | ||
| return nil unless query.is_a?(String) || query.is_a?(Hash) | ||
|
|
||
| query_hash = if query.is_a?(String) | ||
| URI.decode_www_form(query).each_with_object({}) do |(key, value), params| | ||
| params[key] = params.key?(key) ? Array(params[key]) + [value] : value | ||
| end | ||
| else | ||
| query | ||
| end | ||
|
|
||
| filtered_query_hash = Sentry.configuration.data_collection.url_query_params.filter(query_hash) | ||
| return nil if filtered_query_hash.empty? | ||
|
sl0thentr0py marked this conversation as resolved.
|
||
|
|
||
| format_query(filtered_query_hash) | ||
| rescue | ||
| nil | ||
| end | ||
|
sl0thentr0py marked this conversation as resolved.
|
||
|
|
||
| def format_query(query) | ||
| query.flat_map do |key, value| | ||
| Array(value).map { |item| "#{key}=#{item}" } | ||
| end.join("&") | ||
|
sl0thentr0py marked this conversation as resolved.
|
||
| end | ||
|
sl0thentr0py marked this conversation as resolved.
Comment on lines
+28
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The new Suggested FixUpdate the Prompt for AI Agent |
||
|
|
||
| def set_span_info(sentry_span, request_info, response_status) | ||
| sentry_span.set_description("#{request_info[:method]} #{request_info[:url]}") | ||
| sentry_span.set_data(Span::DataConventions::URL, request_info[:url]) | ||
| sentry_span.set_data(Span::DataConventions::URL, url_with_query(request_info)) | ||
| sentry_span.set_data(Span::DataConventions::HTTP_METHOD, request_info[:method]) | ||
| sentry_span.set_data(Span::DataConventions::HTTP_QUERY, request_info[:query]) if request_info[:query] | ||
| sentry_span.set_data(Span::DataConventions::HTTP_STATUS_CODE, response_status) | ||
|
|
@@ -43,37 +71,25 @@ def propagate_trace?(url) | |
| Sentry.configuration.trace_propagation_targets.any? { |target| url.match?(target) } | ||
| end | ||
|
|
||
| # Kindly borrowed from Rack::Utils | ||
| def build_nested_query(value, prefix = nil) | ||
| case value | ||
| when Array | ||
| value.map { |v| | ||
| build_nested_query(v, "#{prefix}[]") | ||
| }.join("&") | ||
| when Hash | ||
| value.map { |k, v| | ||
| build_nested_query(v, prefix ? "#{prefix}[#{k}]" : k) | ||
| }.delete_if(&:empty?).join("&") | ||
| when nil | ||
| URI.encode_www_form_component(prefix) | ||
| else | ||
| raise ArgumentError, "value must be a Hash" if prefix.nil? | ||
| "#{URI.encode_www_form_component(prefix)}=#{URI.encode_www_form_component(value)}" | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def url_with_query(request_info) | ||
| return request_info[:url] unless request_info[:query] | ||
|
|
||
| "#{request_info[:url]}?#{request_info[:query]}" | ||
| end | ||
|
|
||
| def get_level(status) | ||
| return :info unless status && status.is_a?(Integer) | ||
|
|
||
| if status >= 500 | ||
| :error | ||
| elsif status >= 400 | ||
| :warning | ||
| else | ||
| :info | ||
| end | ||
| if status >= 500 | ||
| :error | ||
| elsif status >= 400 | ||
| :warning | ||
| else | ||
| :info | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.