Skip to content

Conversation

@tammy-baylis-swi
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Nov 29, 2025

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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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

  • Added unit tests
  • Instrumentation with aiohttp test app with opt-in as default, http, and http/dup

Default span attributes

http.method: Str(GET)
http.scheme: Str(http)
net.host.name: Str(0.0.0.0)
http.host: Str(0.0.0.0)
net.host.port: Int(8080)
http.target: Str(/latency/)
http.user_agent: Str(curl/8.17.0)
http.flavor: Str(1.1)
http.route: Str(latency)
http.server_name: Str(0.0.0.0:8080)
http.status_code: Int(200)

http span attributes

http.request.method: Str(GET)
url.scheme: Str(http)
server.address: Str(0.0.0.0)
server.port: Int(8080)
url.path: Str(/latency/)
user_agent.original: Str(curl/8.17.0)
network.protocol.version: Str(1.1)
http.response.status_code: Int(200)

http/dup has both sets.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@tammy-baylis-swi tammy-baylis-swi changed the title TTP semantic convention stability migration for aiohttp-server HTTP semantic convention stability migration for aiohttp-server Nov 29, 2025
explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
)

meter_for_counter = meter_new if meter_new else meter_old
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
meter_for_counter = meter_new if meter_new else meter_old
meter_for_counter = meter_new or meter_old

Comment on lines +305 to +315
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
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines +318 to +322
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)
Copy link
Contributor

@herin049 herin049 Dec 5, 2025

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines +324 to +326
user_agent = request.headers.get("user-agent")
if user_agent:
_set_http_user_agent(result, user_agent, sem_conv_opt_in_mode)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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)

@herin049
Copy link
Contributor

herin049 commented Dec 5, 2025

Left a few more small comments, otherwise LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

opentelemetry-instrumentation-aiohttp-server: HTTP semantic convention stability migration

2 participants