-
Notifications
You must be signed in to change notification settings - Fork 48
feat: more django context #252
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
Changes from all commits
325a3a5
6cfc1f5
877ec64
36cb535
46fa59f
3f8b06a
5f74391
c3bb290
c36dbf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,8 +67,8 @@ def extract_person_data(self): | |
| headers = self.headers() | ||
|
|
||
| # Extract traceparent and tracestate headers | ||
| traceparent = headers.get("traceparent") | ||
| tracestate = headers.get("tracestate") | ||
| traceparent = headers.get("Traceparent") | ||
| tracestate = headers.get("Tracestate") | ||
|
Comment on lines
+70
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Header case sensitivity change may break existing integrations. HTTP headers should be case-insensitive per RFC 2616. Use case-insensitive lookup like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests were failing with |
||
|
|
||
| # Extract the distinct_id from tracestate | ||
| distinct_id = None | ||
|
|
@@ -80,12 +80,38 @@ def extract_person_data(self): | |
| distinct_id = match.group(1) | ||
|
|
||
| return { | ||
| **self.user(), | ||
| "distinct_id": distinct_id, | ||
| "ip": headers.get("X-Forwarded-For"), | ||
| "user_agent": headers.get("User-Agent"), | ||
| "traceparent": traceparent, | ||
| "$request_path": self.request.path, | ||
| } | ||
|
|
||
| def user(self): | ||
| user_data: dict[str, str] = {} | ||
|
|
||
| user = getattr(self.request, "user", None) | ||
|
|
||
| if user is None or not user.is_authenticated: | ||
| return user_data | ||
|
|
||
| try: | ||
| user_id = str(user.pk) | ||
| if user_id: | ||
| user_data.setdefault("$user_id", user_id) | ||
| except Exception: | ||
| pass | ||
|
|
||
| try: | ||
| email = str(user.email) | ||
| if email: | ||
| user_data.setdefault("email", email) | ||
| except Exception: | ||
| pass | ||
|
|
||
| return user_data | ||
|
|
||
| def headers(self): | ||
| # type: () -> Dict[str, str] | ||
| return dict(self.request.headers) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| VERSION = "4.5.0" | ||
| VERSION = "4.6.0" | ||
|
|
||
| if __name__ == "__main__": | ||
| print(VERSION, end="") # noqa: T201 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Django has been normalizing header keys since 2.2 (source: ChatGPT)