Skip to content

Commit 7ac63e1

Browse files
authored
feat: add in_app configuration for python SDK (#396)
* add in_app configuration for python SDK * bump version * add in_app_modules to init script as well
1 parent 14d1d0b commit 7ac63e1

File tree

5 files changed

+54
-26
lines changed

5 files changed

+54
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 7.4.2 - 2025-12-22
2+
3+
feat: add `in_app_modules` option to control code variables capturing
4+
15
# 7.4.1 - 2025-12-19
26

37
fix: extract model from response for OpenAI stored prompts

posthog/__init__.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
11
import datetime # noqa: F401
2-
from typing import Callable, Dict, Optional, Any # noqa: F401
2+
from typing import Any, Callable, Dict, Optional # noqa: F401
3+
34
from typing_extensions import Unpack
45

5-
from posthog.args import OptionalCaptureArgs, OptionalSetArgs, ExceptionArg
6+
from posthog.args import ExceptionArg, OptionalCaptureArgs, OptionalSetArgs
67
from posthog.client import Client
8+
from posthog.contexts import (
9+
identify_context as inner_identify_context,
10+
)
711
from posthog.contexts import (
812
new_context as inner_new_context,
13+
)
14+
from posthog.contexts import (
915
scoped as inner_scoped,
10-
tag as inner_tag,
11-
set_context_session as inner_set_context_session,
12-
identify_context as inner_identify_context,
16+
)
17+
from posthog.contexts import (
1318
set_capture_exception_code_variables_context as inner_set_capture_exception_code_variables_context,
14-
set_code_variables_mask_patterns_context as inner_set_code_variables_mask_patterns_context,
19+
)
20+
from posthog.contexts import (
1521
set_code_variables_ignore_patterns_context as inner_set_code_variables_ignore_patterns_context,
1622
)
23+
from posthog.contexts import (
24+
set_code_variables_mask_patterns_context as inner_set_code_variables_mask_patterns_context,
25+
)
26+
from posthog.contexts import (
27+
set_context_session as inner_set_context_session,
28+
)
29+
from posthog.contexts import (
30+
tag as inner_tag,
31+
)
1732
from posthog.exception_utils import (
1833
DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS,
1934
DEFAULT_CODE_VARIABLES_MASK_PATTERNS,
2035
)
2136
from posthog.feature_flags import (
2237
InconclusiveMatchError as InconclusiveMatchError,
38+
)
39+
from posthog.feature_flags import (
2340
RequiresServerEvaluation as RequiresServerEvaluation,
2441
)
2542
from posthog.flag_definition_cache import (
@@ -35,6 +52,8 @@
3552
from posthog.types import (
3653
FeatureFlag,
3754
FlagsAndPayloads,
55+
)
56+
from posthog.types import (
3857
FeatureFlagResult as FeatureFlagResult,
3958
)
4059
from posthog.version import VERSION
@@ -201,6 +220,7 @@ def tag(name: str, value: Any):
201220
capture_exception_code_variables = False
202221
code_variables_mask_patterns = DEFAULT_CODE_VARIABLES_MASK_PATTERNS
203222
code_variables_ignore_patterns = DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS
223+
in_app_modules = None # type: Optional[list[str]]
204224

205225

206226
# NOTE - this and following functions take unpacked kwargs because we needed to make
@@ -799,6 +819,7 @@ def setup() -> Client:
799819
capture_exception_code_variables=capture_exception_code_variables,
800820
code_variables_mask_patterns=code_variables_mask_patterns,
801821
code_variables_ignore_patterns=code_variables_ignore_patterns,
822+
in_app_modules=in_app_modules,
802823
)
803824

804825
# always set incase user changes it

posthog/client.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,33 @@
55
import warnings
66
from datetime import datetime, timedelta
77
from typing import Any, Dict, Optional, Union
8-
from typing_extensions import Unpack
98
from uuid import uuid4
109

1110
from dateutil.tz import tzutc
1211
from six import string_types
12+
from typing_extensions import Unpack
1313

14-
from posthog.args import OptionalCaptureArgs, OptionalSetArgs, ID_TYPES, ExceptionArg
14+
from posthog.args import ID_TYPES, ExceptionArg, OptionalCaptureArgs, OptionalSetArgs
1515
from posthog.consumer import Consumer
16+
from posthog.contexts import (
17+
_get_current_context,
18+
get_capture_exception_code_variables_context,
19+
get_code_variables_ignore_patterns_context,
20+
get_code_variables_mask_patterns_context,
21+
get_context_distinct_id,
22+
get_context_session_id,
23+
new_context,
24+
)
1625
from posthog.exception_capture import ExceptionCapture
1726
from posthog.exception_utils import (
27+
DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS,
28+
DEFAULT_CODE_VARIABLES_MASK_PATTERNS,
1829
exc_info_from_error,
30+
exception_is_already_captured,
1931
exceptions_from_error_tuple,
2032
handle_in_app,
21-
exception_is_already_captured,
2233
mark_exception_as_captured,
2334
try_attach_code_variables_to_frames,
24-
DEFAULT_CODE_VARIABLES_MASK_PATTERNS,
25-
DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS,
2635
)
2736
from posthog.feature_flags import (
2837
InconclusiveMatchError,
@@ -46,15 +55,6 @@
4655
get,
4756
remote_config,
4857
)
49-
from posthog.contexts import (
50-
_get_current_context,
51-
get_context_distinct_id,
52-
get_context_session_id,
53-
get_capture_exception_code_variables_context,
54-
get_code_variables_mask_patterns_context,
55-
get_code_variables_ignore_patterns_context,
56-
new_context,
57-
)
5858
from posthog.types import (
5959
FeatureFlag,
6060
FeatureFlagError,
@@ -197,6 +197,7 @@ def __init__(
197197
capture_exception_code_variables=False,
198198
code_variables_mask_patterns=None,
199199
code_variables_ignore_patterns=None,
200+
in_app_modules: list[str] | None = None,
200201
):
201202
"""
202203
Initialize a new PostHog client instance.
@@ -265,6 +266,7 @@ def __init__(
265266
if code_variables_ignore_patterns is not None
266267
else DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS
267268
)
269+
self.in_app_modules = in_app_modules
268270

269271
if project_root is None:
270272
try:
@@ -998,6 +1000,7 @@ def capture_exception(
9981000
"values": all_exceptions_with_trace,
9991001
},
10001002
},
1003+
in_app_include=self.in_app_modules,
10011004
project_root=self.project_root,
10021005
)
10031006
all_exceptions_with_trace_and_in_app = event["exception"]["values"]
@@ -2182,9 +2185,9 @@ def _initialize_flag_cache(self, cache_url):
21822185
return None
21832186

21842187
try:
2185-
from urllib.parse import urlparse, parse_qs
2188+
from urllib.parse import parse_qs, urlparse
21862189
except ImportError:
2187-
from urlparse import urlparse, parse_qs
2190+
from urlparse import parse_qs, urlparse
21882191

21892192
try:
21902193
parsed = urlparse(cache_url)

posthog/exception_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@
1414
from datetime import datetime
1515
from types import FrameType, TracebackType # noqa: F401
1616
from typing import ( # noqa: F401
17+
TYPE_CHECKING,
1718
Any,
1819
Dict,
1920
Iterator,
2021
List,
2122
Literal,
2223
Optional,
24+
Pattern,
2325
Set,
2426
Tuple,
2527
TypedDict,
2628
TypeVar,
2729
Union,
2830
cast,
29-
TYPE_CHECKING,
30-
Pattern,
3131
)
3232

33-
from posthog.args import ExcInfo, ExceptionArg # noqa: F401
33+
from posthog.args import ExceptionArg, ExcInfo # noqa: F401
3434

3535
try:
3636
# Python 3.11

posthog/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "7.4.1"
1+
VERSION = "7.4.2"
22

33
if __name__ == "__main__":
44
print(VERSION, end="") # noqa: T201

0 commit comments

Comments
 (0)