Skip to content

Conversation

@rite7sh
Copy link

@rite7sh rite7sh commented Jan 8, 2026

Description

This PR fixes inconsistent initialization of the http.server.active_requests
metric in Flask instrumentation by aligning it with the semantic conventions
helper used by other instrumentations.

Depending on how Flask is instrumented, different units and descriptions were
being used for the same metric. This change ensures consistent behavior by
using the semconv helper everywhere.

Fixes #4093

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • python -m ruff check instrumentation/opentelemetry-instrumentation-flask
  • Existing Flask instrumentation tests
  • Verified no lint or formatting issues after changes

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated (not required for this fix)
  • Unit tests have been added (existing coverage is sufficient)
  • Documentation has been updated (no user-facing changes)

Copy link

@JWinermaSplunk JWinermaSplunk left a comment

Choose a reason for hiding this comment

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

Left a small comment, but it looks simple enough if the helper functions suffice. Also, this change probably requires a changelog entry, otherwise LGTM.

if _report_old(_InstrumentedFlask._sem_conv_opt_in_mode):
duration_histogram_old = meter.create_histogram(
name=MetricInstruments.HTTP_SERVER_DURATION,
name="http.server.duration",

Choose a reason for hiding this comment

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

Are we sure we want the names here and line #815 to be hardcoded and not a constant?

Copy link
Author

Choose a reason for hiding this comment

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

oh i am sorry, I can switch this to use a constant for consistency if one is available. I’ll check the existing semconv metrics helpers and update accordingly so we’re not introducing a new hardcoded string.

Choose a reason for hiding this comment

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

I am probably missing something but why are we changing the name value from MetricInstruments.HTTP_SERVER_DURATION at all?

Copy link
Author

Choose a reason for hiding this comment

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

@JWinermaSplunk sorry if that wasn’t clear from the diff.
The intent here isn’t to change the metric name or semantics. The legacy metric remains http.server.duration.
This follow-up was only to avoid introducing a new hardcoded string and instead make that legacy name explicit via a local constant, similar to how other legacy/compat paths are handled.

If you’d prefer, I’m also happy to keep using MetricInstruments.HTTP_SERVER_DURATION directly here I mainly wanted to avoid adding another literal string while keeping behavior unchanged.
hopefully i was able to explain the intent :)

Choose a reason for hiding this comment

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

Yes, let's go ahead and keep using MetricInstruments.HTTP_SERVER_DURATION in the meantime. I would be happy to approve the PR after that :)

Copy link
Author

Choose a reason for hiding this comment

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

@JWinermaSplunk I’ve rolled back to using MetricInstruments.HTTP_SERVER_DURATION as suggested and updated the PR accordingly.
Everything should be good to go now, but please feel free to ping me if you’d like any further tweaks before approval.
Thanks for these suggestions btw :P

@rite7sh
Copy link
Author

rite7sh commented Jan 8, 2026

@JWinermaSplunk I’ve pushed a small follow-up commit that replaces the hardcoded legacy metric name with a constant, keeping it consistent with the existing semantic convention helpers.
Please let me know if this approach looks good to you, and whether you’d like me to add a changelog entry as well, given that this doesn’t introduce any behavioral changes.

@JWinermaSplunk
Copy link

A changelog entry never hurts. It is simple enough and even the current PR name would be fine as an entry, but it isn't up to me in the end :)

@rite7sh
Copy link
Author

rite7sh commented Jan 8, 2026

@JWinermaSplunk you got a point, i surely will add a changelog update.
thanks for the suggestion.

@rite7sh rite7sh requested a review from a team as a code owner January 8, 2026 21:08
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.

flask: different http.server.active_requests metrics description and unit

2 participants