Skip to content

fix python package distrubution name case-sensitive issue in client span code attr…#546

Merged
wangzlei merged 1 commit intoaws-observability:mainfrom
wangzlei:main
Nov 25, 2025
Merged

fix python package distrubution name case-sensitive issue in client span code attr…#546
wangzlei merged 1 commit intoaws-observability:mainfrom
wangzlei:main

Conversation

@wangzlei
Copy link
Contributor

…ibutes

Issue

When Django ORM triggers a database query and generates corresponding OTel client span, the client span contains wrong code attributes:

  "code.function.name": "django.db.backends.utils.CursorDebugWrapper._execute",
  "code.file.path": "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py",
  "db.query.text": "SELECT \"billing_service_billing\".\"id\", \"billing_service_billing\".\"owner_id\", \"billing_service_billing\".\"type\", \"billing_service_billing\".\"type_name\", \"billing_service_billing\".\"pet_id\", \"billing_service_billing\".\"payment\", \"billing_service_billing\".\"status\" FROM \"billing_service_billing\" WHERE NOT (\"billing_service_billing\".\"type_name\" IN (SELECT DISTINCT U0.\"invalid_name\" AS \"invalid_name\" FROM \"check_list\" U0 LIMIT 100)) LIMIT 3810",

Function name django.db.backends.utils.CursorDebugWrapper._execute and file path /usr/local/lib/python3.10/site-packages/django/db/backends/utils.py are from Django, not user code.

Description of changes

The root cause is django distribute name is Django(Distribution(name='Django', version='5.2.7')), does not match with the package name django.
The bug can be fixed by using a case-insensitive string comparison.

Testing

After fix:

"attributes": {
        "code.function.name": "views.orm_example_view",
        "code.file.path": "/Volumes/workplace/extension/aws-otel-python-instrumentation/samples/django/views.py",
        "code.line.number": 278,
        "db.system": "sqlite",
        "db.name": "",
        "db.statement": "SELECT \"auth_user\".\"id\", \"auth_user\".\"password\", \"auth_user\".\"last_login\", \"auth_user\".\"is_superuser\", \"auth_user\".\"username\", \"auth_user\".\"first_name\", \"auth_user\".\"last_name\", \"auth_user\".\"email\", \"auth_user\".\"is_staff\", \"auth_user\".\"is_active\", \"auth_user\".\"date_joined\" FROM \"auth_user\" WHERE \"auth_user\".\"is_active\" LIMIT 10"
    },

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@wangzlei wangzlei requested a review from a team as a code owner November 25, 2025 02:15
@wangzlei wangzlei added the skip changelog doesn't need a CHANGELOG entry label Nov 25, 2025
@wangzlei wangzlei changed the title fix python package name case-sensitive issue in client span code attr… fix python package distrubution name case-sensitive issue in client span code attr… Nov 25, 2025
@wangzlei wangzlei merged commit 54c5f11 into aws-observability:main Nov 25, 2025
25 of 27 checks passed
yiyuan-he pushed a commit to yiyuan-he/aws-otel-python-instrumentation that referenced this pull request Dec 12, 2025
…pan code attr… (aws-observability#546)

…ibutes

### Issue

When Django ORM triggers a database query and generates corresponding
OTel client span, the client span contains wrong code attributes:
```
  "code.function.name": "django.db.backends.utils.CursorDebugWrapper._execute",
  "code.file.path": "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py",
  "db.query.text": "SELECT \"billing_service_billing\".\"id\", \"billing_service_billing\".\"owner_id\", \"billing_service_billing\".\"type\", \"billing_service_billing\".\"type_name\", \"billing_service_billing\".\"pet_id\", \"billing_service_billing\".\"payment\", \"billing_service_billing\".\"status\" FROM \"billing_service_billing\" WHERE NOT (\"billing_service_billing\".\"type_name\" IN (SELECT DISTINCT U0.\"invalid_name\" AS \"invalid_name\" FROM \"check_list\" U0 LIMIT 100)) LIMIT 3810",
```

Function name `django.db.backends.utils.CursorDebugWrapper._execute` and
file path
`/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py`
are from Django, not user code.

### Description of changes
The root cause is django distribute name is
`Django`(Distribution(name='Django', version='5.2.7')), does not match
with the package name `django`.
The bug can be fixed by using a case-insensitive string comparison.

### Testing
After fix:
```
"attributes": {
        "code.function.name": "views.orm_example_view",
        "code.file.path": "/Volumes/workplace/extension/aws-otel-python-instrumentation/samples/django/views.py",
        "code.line.number": 278,
        "db.system": "sqlite",
        "db.name": "",
        "db.statement": "SELECT \"auth_user\".\"id\", \"auth_user\".\"password\", \"auth_user\".\"last_login\", \"auth_user\".\"is_superuser\", \"auth_user\".\"username\", \"auth_user\".\"first_name\", \"auth_user\".\"last_name\", \"auth_user\".\"email\", \"auth_user\".\"is_staff\", \"auth_user\".\"is_active\", \"auth_user\".\"date_joined\" FROM \"auth_user\" WHERE \"auth_user\".\"is_active\" LIMIT 10"
    },
```


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
@yiyuan-he yiyuan-he mentioned this pull request Dec 12, 2025
yiyuan-he added a commit that referenced this pull request Dec 12, 2025
*Issue #, if available:*
N/A - Patch release preparation

**Description of changes:**

Cherry-pick commits from main to prepare v0.14.1 patch release:
  - #554 - Add custom ADOT UserAgent for OTLP Spans Exporter
- #552 - Refactor configuration for Application Signals Dimensions to
EMF exporter
  - #551 - CVE-2025-66471 fix (urllib3 dependency bump)
- #549 - Disable django instrumentation if DJANGO_SETTINGS_MODULE is not
set
  - #548 - Add Service and Environment dimensions to EMF metrics
  - #547 - Add safety check for bedrock ConverseStream responses
  - #546 - Fix python package distribution name case-sensitive issue

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Lei Wang <66336933+wangzlei@users.noreply.github.com>
Co-authored-by: Steve Liu <liustve@amazon.com>
Co-authored-by: Syed Ahsan Ishtiaque <176968742+syed-ahsan-ishtiaque@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip changelog doesn't need a CHANGELOG entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants