Skip to content

fix excluded_urls in instrumentation-asgi #3567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

CarlosRCDev
Copy link

@CarlosRCDev CarlosRCDev commented Jun 9, 2025

Description

If set value "excluded_urls" in OpenTelemetryMiddleware, in instrumentation-asgi. class fails: 'str' object has no attribute 'url_disabled'.

Fixes #3562
excluded_urls with parse_excluded_urls

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

In instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py

  • test_excluded_urls, fails if return span, with excluded_urls
  • test_no_excluded_urls, fails if not return span, with excluded_urls

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • [X ] Followed the style guidelines of this project
  • Unit tests have been added

Copy link

linux-foundation-easycla bot commented Jun 9, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

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.

CI is failing. Maybe we should instead check if excluded_urls is already an ExcludeList?

@CarlosRCDev
Copy link
Author

CI is failing. Maybe we should instead check if excluded_urls is already an ExcludeList?

My fault, you are right, the problem:
the class OpenTelemetryMiddleware, when is used directly for example, quart or django, need a string to be convert in ExcludeList class (using parse_excluded_urls function), but the instrumentor like fastapi, instance the class OpenTelemetryMiddleware with excluded_urls as ExcludeList class.

The fix check if excluded_urls isistance of string, if not use the object without changes:

if isinstance(excluded_urls, str):
    excluded_urls = parse_excluded_urls(excluded_urls)

@emdneto
Copy link
Member

emdneto commented Jun 9, 2025

CI is failing. Maybe we should instead check if excluded_urls is already an ExcludeList?

My fault, you are right, the problem: the class OpenTelemetryMiddleware, when is used directly for example, quart or django, need a string to be convert in ExcludeList class (using parse_excluded_urls function), but the instrumentor like fastapi, instance the class OpenTelemetryMiddleware with excluded_urls as ExcludeList class.

The fix check if excluded_urls isistance of string, if not use the object without changes:

if isinstance(excluded_urls, str):
    excluded_urls = parse_excluded_urls(excluded_urls)

Right. Can you add a changelog entry?

@CarlosRCDev CarlosRCDev requested a review from a team as a code owner June 10, 2025 06:53
@CarlosRCDev
Copy link
Author

CI is failing. Maybe we should instead check if excluded_urls is already an ExcludeList?

My fault, you are right, the problem: the class OpenTelemetryMiddleware, when is used directly for example, quart or django, need a string to be convert in ExcludeList class (using parse_excluded_urls function), but the instrumentor like fastapi, instance the class OpenTelemetryMiddleware with excluded_urls as ExcludeList class.
The fix check if excluded_urls isistance of string, if not use the object without changes:

if isinstance(excluded_urls, str):
    excluded_urls = parse_excluded_urls(excluded_urls)

Right. Can you add a changelog entry?

Sorry for the wait, I just did it.

Copy link

@schneider8357 schneider8357 left a comment

Choose a reason for hiding this comment

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

LGTM, the change is small and non-invasive. From what I understand, ExcludeList accepts Iterable[str], and it’s a common pattern to use strings in regex format for that. The helper function parse_excluded_urls splits the string accordingly, so the init function would now accept a string as well.
Two unit tests were added, covering the cases of an excluded URL and a non-excluded URL. I suggest adding tests with multiple exclusions in a single string, but I'm unsure if that is really necessary.

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.

(excluded_urls) 'str' object has no attribute 'url_disabled' in OpenTelemetryMiddleware
3 participants