Skip to content

fix(flask): align http.server.active_requests metric with semconv helper#4094

Open
rite7sh wants to merge 17 commits intoopen-telemetry:mainfrom
rite7sh:fix/flask-active-requests-metric
Open

fix(flask): align http.server.active_requests metric with semconv helper#4094
rite7sh wants to merge 17 commits intoopen-telemetry:mainfrom
rite7sh:fix/flask-active-requests-metric

Conversation

@rite7sh
Copy link
Contributor

@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.

@rite7sh
Copy link
Contributor 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
Contributor 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
@xrmx xrmx moved this to Ready for review in @xrmx's Python PR digest Jan 13, 2026
Copy link
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

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

The issue here is that the two instrumentor methods we have in this instrumentation use two different semconv for the same metric: one as old as the default implementation and one that does follow the stable one. The PR is changing the older one to use the stable semconv too so both in the default older semconv and when output of the stable one is configured. That's a behaviour change. Since the difference is only on unit and description I'm not sure that's a big deal.

@rite7sh
Copy link
Contributor Author

rite7sh commented Jan 13, 2026

@xrmx Thanks for the clarification, I agree this is a small behavior change limited to unit and description, and I’m glad it aligns both paths on the same semconv, I’ve updated the branch and am happy to tweak anything if needed. :)

Comment on lines 695 to 697
active_requests_counter = meter.create_up_down_counter(
name=MetricInstruments.HTTP_SERVER_ACTIVE_REQUESTS,
unit="requests",
description="measures the number of concurrent HTTP requests that are currently in-flight",
)
active_requests_counter = create_http_server_active_requests(meter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do something like

if newsemconv:
   active_requests_counter = create_http_server_active_requests(meter)
else:
   active_requests_counter = meter.create_up_down_counter(
            name=MetricInstruments.HTTP_SERVER_ACTIVE_REQUESTS,
            unit="requests",
            description="measures the number of concurrent HTTP requests that are currently in-flight",
        )

in both hunks so that the metrics matches the semconv?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xrmx I’ve updated both paths to use the explicit semconv split as suggested. Let me know if this looks good now, thanks for suggestion.

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.

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

4 participants