Skip to content

Add optional http.client.response.body.size span attribute & metric to Aiohttp-client instrumentation.#4572

Open
weizhikuan wants to merge 5 commits into
open-telemetry:mainfrom
weizhikuan:i3623
Open

Add optional http.client.response.body.size span attribute & metric to Aiohttp-client instrumentation.#4572
weizhikuan wants to merge 5 commits into
open-telemetry:mainfrom
weizhikuan:i3623

Conversation

@weizhikuan
Copy link
Copy Markdown

@weizhikuan weizhikuan commented May 12, 2026

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #3623

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.

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

@weizhikuan weizhikuan requested a review from a team as a code owner May 12, 2026 03:34
@github-actions github-actions Bot requested a review from herin049 May 12, 2026 03:34
@weizhikuan
Copy link
Copy Markdown
Author

As per the semconv spec v1.41.0, the span attribute and metric are both optional. So I added both of them and only enabled when semconv stability contains http and the env var OTEL_PYTHON_INSTRUMENTATION_HTTP_RESPONSE_BODY_SIZE is set as true.

@emdneto
Copy link
Copy Markdown
Member

emdneto commented May 12, 2026

Thanks for the PR!

Just a heads-up: we no longer update CHANGELOG.md directly. The changelog is now generated from changelog fragments using Towncrier.

Please add the appropriate changelog fragment for this change instead of editing CHANGELOG.md manually. You can find the instructions and expected format in CONTRIBUTING.md.

@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Thank you for this @weizhikuan . The way to opt into this makes sense. Please do a quick tox -e precommit to fix some formatting.

@weizhikuan
Copy link
Copy Markdown
Author

weizhikuan commented May 14, 2026

Thanks for the PR!

Just a heads-up: we no longer update CHANGELOG.md directly. The changelog is now generated from changelog fragments using Towncrier.

Please add the appropriate changelog fragment for this change instead of editing CHANGELOG.md manually. You can find the instructions and expected format in CONTRIBUTING.md.

Gotcha, will add the fragment.

@aabmass aabmass moved this to Ready for review in Python PR digest May 14, 2026
****************************
To capture the ``http.response.body.size`` span attribute and record the
``http.client.response.body.size`` metric histogram, set the environment variable
``OTEL_PYTHON_INSTRUMENTATION_HTTP_RESPONSE_BODY_SIZE`` to ``"true"``.
Copy link
Copy Markdown
Contributor

@herin049 herin049 May 17, 2026

Choose a reason for hiding this comment

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

Personally, I don't think that having an opt-in is really needed here. From my understanding, when the Spec states that a metric or attribute is "optional", it usually indicates that library authors can optionally add it - not necessarily that users need the ability to enable/disable it. Typically, the spec will explicitly state if behavior should be opt-in only.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same understanding here.

@herin049 herin049 moved this from Ready for review to Reviewed PRs that need fixes in Python PR digest May 17, 2026
):
return

trace_config_ctx.start_time = default_timer()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should probably add the following, just to ensure that the response body size doesn't accidentally leak into another request (e.g. if follow-up requests don't end up setting the attribute)

Suggested change
trace_config_ctx.start_time = default_timer()
trace_config_ctx.response_body_size = None

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

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

aiohttp-client add http.response.body.size span attribute

5 participants