Skip to content

Conversation

tammy-baylis-swi
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Aug 13, 2025

Description

Adds new a Python instrumentation Labeler, inspired by Go's net/http instrumentation: open-telemetry/opentelemetry-go-contrib#306. It stores KVs added to it in the current request context. The add / add_attributes can be called by user's instrumented code manually, or by custom distros. The following instrumentors have been updated in this PR so that custom attributes are read from the Labeler in context, then merged into the other attributes (new or old semconv) that are passed to the record calls of the request duration histograms:

  1. opentelemetry-instrumentation-flask
  2. opentelemetry-instrumentation-django
  3. opentelemetry-instrumentation-falcon
  4. opentelemetry-instrumentation-wsgi
  5. opentelemetry-instrumentation-asgi

Example OTel Collector debug metrics from ASGI OpenTelemetryMiddleware instrumentation, with histograms including custom attributes: https://gist.github.com/tammy-baylis-swi/974ec71d5fb9e88968327b175f2b59a5

Addresses #3702, #3703

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

  • New unit tests
  • Local installation and manual instrumentation of Flask/Falcon/Django app, as per new doc
  • Local installation and manual instrumentation of web.py app (no instrumentation) with WSGI
  • Local installation and manual instrumentation of Quart app (no instrumentation) with ASGI

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 force-pushed the add-metrics-attributes-labeler branch from d676f55 to 6cec2f1 Compare August 20, 2025 22:54
@tammy-baylis-swi tammy-baylis-swi force-pushed the add-metrics-attributes-labeler branch from 6cec2f1 to ce12b1b Compare August 20, 2025 22:55
@tammy-baylis-swi tammy-baylis-swi changed the title [Don't merge][WIP][Prototype] Add Python instrumentation Labeler Add Labeler and instrumentation integration for custom attribute addition to duration metrics (Flask, Django, Falcon, WSGI, ASGI) Aug 26, 2025
@tammy-baylis-swi tammy-baylis-swi changed the title Add Labeler and instrumentation integration for custom attribute addition to duration metrics (Flask, Django, Falcon, WSGI, ASGI) Add Labeler and instrumentation integration for custom attribute addition to HTTP request duration metrics (Flask, Django, Falcon, WSGI, ASGI) Aug 26, 2025
@tammy-baylis-swi tammy-baylis-swi marked this pull request as ready for review August 27, 2025 22:57
@tammy-baylis-swi tammy-baylis-swi requested a review from a team as a code owner August 27, 2025 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant