|
10 | 10 |
|
11 | 11 | from dateutil.tz import tzutc |
12 | 12 | from six import string_types |
| 13 | +import distro # For Linux OS detection |
13 | 14 |
|
14 | 15 | from posthog.consumer import Consumer |
15 | 16 | from posthog.exception_capture import ExceptionCapture |
@@ -38,55 +39,31 @@ def get_os_info(): |
38 | 39 | os_name = "" |
39 | 40 | os_version = "" |
40 | 41 |
|
41 | | - # Windows |
42 | 42 | if sys.platform.startswith("win"): |
43 | 43 | os_name = "Windows" |
44 | 44 | if hasattr(platform, "win32_ver"): |
45 | 45 | win_version = platform.win32_ver()[0] |
46 | 46 | if win_version: |
47 | 47 | os_version = win_version |
48 | 48 |
|
49 | | - # macOS/Mac OS X |
50 | 49 | elif sys.platform == "darwin": |
51 | 50 | os_name = "Mac OS X" |
52 | 51 | if hasattr(platform, "mac_ver"): |
53 | 52 | mac_version = platform.mac_ver()[0] |
54 | 53 | if mac_version: |
55 | 54 | os_version = mac_version |
56 | 55 |
|
57 | | - # iOS (unlikely in standard Python but included for completeness) |
58 | | - elif sys.platform == "ios": |
59 | | - os_name = "iOS" |
60 | | - # iOS version would need a specific approach |
61 | | - |
62 | | - # Linux |
63 | 56 | elif sys.platform.startswith("linux"): |
64 | 57 | os_name = "Linux" |
65 | | - if hasattr(platform, "linux_distribution"): |
66 | | - # Deprecated in Python 3.8+ |
67 | | - try: |
68 | | - linux_info = platform.linux_distribution() |
69 | | - if linux_info[0] and linux_info[1]: |
70 | | - os_version = linux_info[1] |
71 | | - except: |
72 | | - pass |
73 | | - # For newer Python versions |
74 | | - try: |
75 | | - import distro |
| 58 | + linux_info = distro.info() |
| 59 | + if linux_info["version"]: |
| 60 | + os_version = linux_info["version"] |
76 | 61 |
|
77 | | - linux_info = distro.info() |
78 | | - if linux_info["version"]: |
79 | | - os_version = linux_info["version"] |
80 | | - except ImportError: |
81 | | - pass |
82 | | - |
83 | | - # FreeBSD |
84 | 62 | elif sys.platform.startswith("freebsd"): |
85 | 63 | os_name = "FreeBSD" |
86 | 64 | if hasattr(platform, "release"): |
87 | 65 | os_version = platform.release() |
88 | 66 |
|
89 | | - # Other platforms |
90 | 67 | else: |
91 | 68 | os_name = sys.platform |
92 | 69 | if hasattr(platform, "release"): |
@@ -308,11 +285,13 @@ def capture( |
308 | 285 | stacklevel=2, |
309 | 286 | ) |
310 | 287 |
|
311 | | - properties = properties or {} |
| 288 | + properties = {**(properties or {}), **system_context()} |
| 289 | + |
312 | 290 | require("distinct_id", distinct_id, ID_TYPES) |
313 | 291 | require("properties", properties, dict) |
314 | 292 | require("event", event, string_types) |
315 | 293 |
|
| 294 | + |
316 | 295 | msg = { |
317 | 296 | "properties": properties, |
318 | 297 | "timestamp": timestamp, |
@@ -347,7 +326,7 @@ def capture( |
347 | 326 | extra_properties["$active_feature_flags"] = active_feature_flags |
348 | 327 |
|
349 | 328 | if extra_properties: |
350 | | - msg["properties"] = {**extra_properties, **msg["properties"], **system_context()} |
| 329 | + msg["properties"] = {**extra_properties, **msg["properties"]} |
351 | 330 |
|
352 | 331 | return self._enqueue(msg, disable_geoip) |
353 | 332 |
|
|
0 commit comments