-
Notifications
You must be signed in to change notification settings - Fork 476
Description
Tracer Version(s)
3.18.1
Python Version(s)
3.13.2
Pip Version(s)
pip 24.3.1
Bug Report
The Django integration fails to track user IDs when the user model uses a UUID primary key instead of an integer primary key. This is due to an overly restrictive type check in the user tracking logic introduced here.
The code currently checks if the user primary key is an integer before setting user ID tags:
dd-trace-py/ddtrace/contrib/internal/django/utils.py
Lines 331 to 334 in fdd8fed
| uid = getattr(user, "pk", None) | |
| if uid and isinstance(uid, int): | |
| span._set_tag_str("django.user.id", str(uid)) | |
| span._set_tag_str(_user.ID, str(uid)) |
This means that when a Django user model uses a UUIDField as the primary key, the user ID is never tracked in spans.
Reproduction Code
-
Create a Django project with a custom user model that uses UUID as primary key:
from django.contrib.auth.models import AbstractUser import uuid from django.db import models class User(AbstractUser): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
-
Install and configure ddtrace for Django
-
Make an authenticated request
-
Check the span tags - django.user.id will be missing
Error Logs
No response
Libraries in Use
No response
Operating System
Darwin Kernel Version 24.6.0