<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _set_django_attributes(span, request):
 """Set the django related attributes."""

    django_user = getattr(request, 'user', None)

    if django_user is None:
        return

    user_id = django_user.pk
    try:
        user_name = django_user.get_username()
    except AttributeError:
        # AnonymousUser in some older versions of Django doesn't implement
        # get_username
        return

    # User id is the django autofield for User model as the primary key
    if user_id is not None:
        span.add_attribute('django.user.id', str(user_id))

    if user_name is not None:
        span.add_attribute('django.user.name', str(user_name))