-
Notifications
You must be signed in to change notification settings - Fork 822
HTTP semantic convention stability migration for aiohttp-server #3980
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
base: main
Are you sure you want to change the base?
HTTP semantic convention stability migration for aiohttp-server #3980
Conversation
...-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py
Outdated
Show resolved
Hide resolved
| explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW, | ||
| ) | ||
|
|
||
| meter_for_counter = meter_new if meter_new else meter_old |
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.
| meter_for_counter = meter_new if meter_new else meter_old | |
| meter_for_counter = meter_new or meter_old |
| path = request.path | ||
| query_string = request.query_string | ||
| if query_string and http_url: | ||
| if isinstance(query_string, bytes): | ||
| query_string = query_string.decode("utf8") | ||
| http_url += "?" + urllib.parse.unquote(query_string) | ||
|
|
||
| result = { | ||
| HTTP_SCHEME: request.scheme, | ||
| HTTP_HOST: server_host, | ||
| NET_HOST_PORT: port, | ||
| HTTP_ROUTE: _get_view_func(request), | ||
| HTTP_FLAVOR: f"{request.version.major}.{request.version.minor}", | ||
| HTTP_TARGET: request.path, | ||
| HTTP_URL: redact_url(http_url), | ||
| } | ||
|
|
||
| http_method = request.method | ||
| if http_method: | ||
| result[HTTP_METHOD] = http_method | ||
|
|
||
| http_host_value_list = ( | ||
| [request.host] if not isinstance(request.host, list) else request.host | ||
| ) | ||
| if http_host_value_list: | ||
| result[HTTP_SERVER_NAME] = ",".join(http_host_value_list) | ||
| http_user_agent = request.headers.get("user-agent") | ||
| if http_user_agent: | ||
| result[HTTP_USER_AGENT] = http_user_agent | ||
| target = path | ||
| if query_string: | ||
| target = f"{path}?{query_string}" | ||
| if target: | ||
| redacted_target = redact_query_parameters(target) | ||
| _, redacted_query = _parse_url_query(redacted_target) | ||
| _set_http_target( | ||
| result, redacted_target, path, redacted_query, sem_conv_opt_in_mode | ||
| ) |
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.
| path = request.path | |
| query_string = request.query_string | |
| if query_string and http_url: | |
| if isinstance(query_string, bytes): | |
| query_string = query_string.decode("utf8") | |
| http_url += "?" + urllib.parse.unquote(query_string) | |
| result = { | |
| HTTP_SCHEME: request.scheme, | |
| HTTP_HOST: server_host, | |
| NET_HOST_PORT: port, | |
| HTTP_ROUTE: _get_view_func(request), | |
| HTTP_FLAVOR: f"{request.version.major}.{request.version.minor}", | |
| HTTP_TARGET: request.path, | |
| HTTP_URL: redact_url(http_url), | |
| } | |
| http_method = request.method | |
| if http_method: | |
| result[HTTP_METHOD] = http_method | |
| http_host_value_list = ( | |
| [request.host] if not isinstance(request.host, list) else request.host | |
| ) | |
| if http_host_value_list: | |
| result[HTTP_SERVER_NAME] = ",".join(http_host_value_list) | |
| http_user_agent = request.headers.get("user-agent") | |
| if http_user_agent: | |
| result[HTTP_USER_AGENT] = http_user_agent | |
| target = path | |
| if query_string: | |
| target = f"{path}?{query_string}" | |
| if target: | |
| redacted_target = redact_query_parameters(target) | |
| _, redacted_query = _parse_url_query(redacted_target) | |
| _set_http_target( | |
| result, redacted_target, path, redacted_query, sem_conv_opt_in_mode | |
| ) | |
| if request.path_qs: | |
| redacted_target = redact_query_parameters(request.path_qs) | |
| _, redacted_query = _parse_url_query(redacted_target) | |
| _set_http_target( | |
| result, redacted_target, request.path, redacted_query, sem_conv_opt_in_mode | |
| ) |
Pretty sure you can use request.path_qs instead of manually constructing target with the path and query_string.
| if _report_old(sem_conv_opt_in_mode): | ||
| http_url = str(request.url) | ||
| if query_string: | ||
| http_url += "?" + urllib.parse.unquote(query_string) | ||
| result[HTTP_URL] = redact_url(http_url) |
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.
| if _report_old(sem_conv_opt_in_mode): | |
| http_url = str(request.url) | |
| if query_string: | |
| http_url += "?" + urllib.parse.unquote(query_string) | |
| result[HTTP_URL] = redact_url(http_url) | |
| if _report_old(sem_conv_opt_in_mode): | |
| result[HTTP_URL] = redact_url(str(request.url)) |
Pretty sure request.url already includes the query string.
| user_agent = request.headers.get("user-agent") | ||
| if user_agent: | ||
| _set_http_user_agent(result, user_agent, sem_conv_opt_in_mode) |
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.
| user_agent = request.headers.get("user-agent") | |
| if user_agent: | |
| _set_http_user_agent(result, user_agent, sem_conv_opt_in_mode) | |
| if user_agent := request.headers.get("user-agent"): | |
| _set_http_user_agent(result, user_agent, sem_conv_opt_in_mode) |
|
Left a few more small comments, otherwise LGTM |
Description
Adds HTTP semantic convention stability migration / opt-in for
opentelemetry-instrumentation-aiohttp-server.Fixes #3981
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
http, andhttp/dupDefault span attributes
httpspan attributeshttp/duphas both sets.Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.