Skip to content

Conversation

@herin049
Copy link
Contributor

@herin049 herin049 commented Nov 12, 2025

Description

Fixes issue where all client requests reference the same collection of metric attributes, leading to scenarios where attributes used in one request can spill into attributes from another request.

Fixes #3756

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?

The original bug can be reproduced by running the following snippet

async with aiohttp.ClientSession(timeout=timeout) as session:
    try:
        async with session.get('http://localhost:8080/success') as response:
            text = await response.text()
            print(f"Success endpoint: {response.status} - {text}")
    except asyncio.TimeoutError:
        print("Success endpoint timed out")
    except Exception as e:
        print(f"Success endpoint error: {e}")

    try:
        async with session.get('http://localhost:8080/timeout') as response:
            text = await response.text()
            print(f"Timeout endpoint: {response.status} - {text}")
    except asyncio.TimeoutError:
        print("Timeout endpoint timed out")
    except Exception as e:
        print(f"Timeout endpoint error: {e}")

before the changes in this PR, the first metric data point will correctly have the http.status_code attribute set to 200, however the second metric data point (associated with the timeout request) also has http.status_code set to 200 due to the scenario described above. After implementing the changes the second metric data point no longer populates http.status_code as expected.

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

@xrmx
Copy link
Contributor

xrmx commented Nov 12, 2025

@herin049 could you please add the snippet as a test?

Also please update the number in the fixes since the current one is about a kafka version

@xrmx xrmx moved this to Reviewed PRs that need fixes in @xrmx's Python PR digest Nov 12, 2025
@herin049 herin049 force-pushed the fix-aiohttp-metrics-bug branch from 1282a2a to 92ab1b4 Compare November 12, 2025 19:54
@herin049
Copy link
Contributor Author

herin049 commented Nov 12, 2025

@herin049 could you please add the snippet as a test?

Also please update the number in the fixes since the current one is about a kafka version

@xrmx Just updated the number in the fixes portion of the README (not sure how this happened) and I added a test scenario.

@herin049 herin049 force-pushed the fix-aiohttp-metrics-bug branch from 92ab1b4 to aa74727 Compare November 13, 2025 16:36
@herin049 herin049 force-pushed the fix-aiohttp-metrics-bug branch from aa74727 to f9684c8 Compare November 15, 2025 17:39
Copy link
Member

@emdneto emdneto left a comment

Choose a reason for hiding this comment

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

thanks! Left a small comment about the test, other than that LGTM. Can you please add a changelog entry with the fix?

@herin049 herin049 requested a review from a team as a code owner November 17, 2025 18:46
@herin049 herin049 requested a review from emdneto November 18, 2025 02:30
@herin049
Copy link
Contributor Author

@emdneto or @xrmx do you mind merging this when you get the chance?

@xrmx xrmx enabled auto-merge (squash) November 20, 2025 15:35
@xrmx xrmx merged commit ccea42c into open-telemetry:main Nov 20, 2025
647 checks passed
@github-project-automation github-project-automation bot moved this from Reviewed PRs that need fixes to Done in @xrmx's Python PR digest Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

aiohttp client instrumentation: "leaking" attributes in metrics

3 participants