Commit b179280
authored
feature: Add
* Add $feature_flag_error property to track flag evaluation failures
Track errors in feature flag evaluation by adding a `$feature_flag_error` property to the `$feature_flag_called` event.
* Refactor requests exception imports through request.py
Export RequestsTimeout and RequestsConnectionError from posthog/request.py
to keep all requests library imports in one place and avoid mypy issues.
* Address PR review feedback
- Fix fallback logic to only trigger on actual exceptions, not when
errors_while_computing or flag_missing is set from a successful API response
- Change log.exception() to log.warning() for expected operational errors
(quota limits, timeouts, connection errors, API errors) to reduce log noise
- Keep log.exception() only for truly unexpected errors (unknown_error)
- Extract stale cache fallback into _get_stale_flag_fallback() helper method
* Add tests for stale cache fallback and error absence
- Add TestFeatureFlagErrorWithStaleCacheFallback test class with 4 tests:
- test_timeout_error_returns_stale_cached_value
- test_connection_error_returns_stale_cached_value
- test_api_error_returns_stale_cached_value
- test_error_without_cache_returns_none
- Add negative assertions to verify $feature_flag_error is absent on success:
- test_get_feature_flag_result_boolean_local_evaluation
- test_get_feature_flag_result_variant_local_evaluation
- test_get_feature_flag_result_boolean_decide
- test_get_feature_flag_result_variant_decide
* Report combined errors when both errors_while_computing and flag_missing
When the server returns errorsWhileComputingFlags=true AND the requested
flag is not in the response, report both conditions as a comma-separated
string: "errors_while_computing_flags,flag_missing"
This provides better debugging context when both conditions occur.
* Add FeatureFlagError constants class for error type values
- Add FeatureFlagError class to types.py with constants:
- ERRORS_WHILE_COMPUTING, FLAG_MISSING, QUOTA_LIMITED
- TIMEOUT, CONNECTION_ERROR, UNKNOWN_ERROR
- api_error(status) static method for dynamic error strings
- Update client.py to use FeatureFlagError constants instead of
magic strings
- Update all tests to use constants for maintainability
This improves maintainability by:
- Single source of truth for error values
- IDE autocomplete and typo detection
- Documentation of analytics-stable values
* Remove print statements from test failure handlers
* Fix mypy type error in FeatureFlagError.api_error method
Accept Union[int, str] to match APIError.status type.$feature_flag_error property to track flag evaluation failures (#390)1 parent b6dbff1 commit b179280
File tree
4 files changed
+540
-17
lines changed- posthog
- test
4 files changed
+540
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
| |||
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
| |||
1506 | 1510 | | |
1507 | 1511 | | |
1508 | 1512 | | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
1509 | 1526 | | |
1510 | 1527 | | |
1511 | 1528 | | |
| |||
1539 | 1556 | | |
1540 | 1557 | | |
1541 | 1558 | | |
| 1559 | + | |
1542 | 1560 | | |
1543 | 1561 | | |
1544 | 1562 | | |
| |||
1563 | 1581 | | |
1564 | 1582 | | |
1565 | 1583 | | |
1566 | | - | |
| 1584 | + | |
1567 | 1585 | | |
1568 | 1586 | | |
1569 | 1587 | | |
| |||
1573 | 1591 | | |
1574 | 1592 | | |
1575 | 1593 | | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
1576 | 1602 | | |
1577 | 1603 | | |
1578 | 1604 | | |
| |||
1586 | 1612 | | |
1587 | 1613 | | |
1588 | 1614 | | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
1589 | 1631 | | |
1590 | 1632 | | |
1591 | | - | |
1592 | | - | |
1593 | | - | |
1594 | | - | |
1595 | | - | |
1596 | | - | |
1597 | | - | |
1598 | | - | |
1599 | | - | |
1600 | | - | |
1601 | | - | |
| 1633 | + | |
| 1634 | + | |
1602 | 1635 | | |
1603 | 1636 | | |
1604 | 1637 | | |
| |||
1612 | 1645 | | |
1613 | 1646 | | |
1614 | 1647 | | |
| 1648 | + | |
1615 | 1649 | | |
1616 | 1650 | | |
1617 | 1651 | | |
| |||
1814 | 1848 | | |
1815 | 1849 | | |
1816 | 1850 | | |
1817 | | - | |
| 1851 | + | |
1818 | 1852 | | |
1819 | | - | |
| 1853 | + | |
| 1854 | + | |
1820 | 1855 | | |
1821 | 1856 | | |
1822 | 1857 | | |
| |||
1828 | 1863 | | |
1829 | 1864 | | |
1830 | 1865 | | |
| 1866 | + | |
1831 | 1867 | | |
1832 | 1868 | | |
1833 | | - | |
| 1869 | + | |
1834 | 1870 | | |
1835 | 1871 | | |
1836 | 1872 | | |
| |||
1844 | 1880 | | |
1845 | 1881 | | |
1846 | 1882 | | |
| 1883 | + | |
1847 | 1884 | | |
1848 | 1885 | | |
1849 | 1886 | | |
| |||
1878 | 1915 | | |
1879 | 1916 | | |
1880 | 1917 | | |
| 1918 | + | |
| 1919 | + | |
1881 | 1920 | | |
1882 | 1921 | | |
1883 | 1922 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
315 | 321 | | |
316 | 322 | | |
317 | 323 | | |
| |||
0 commit comments