Skip to content

Commit 75dc6a3

Browse files
committed
feat: we should capture which properties were added as tags
1 parent 68e78c8 commit 75dc6a3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

posthog/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def add_context_tags(properties):
8787
current_context = _get_current_context()
8888
if current_context:
8989
context_tags = current_context.collect_tags()
90+
properties["$context_tags"] = set(context_tags.keys())
9091
# We want explicitly passed properties to override context tags
9192
context_tags.update(properties)
9293
properties = context_tags

posthog/test/test_client.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from posthog.test.test_utils import FAKE_TEST_API_KEY
1414
from posthog.types import FeatureFlag, LegacyFlagMetadata
1515
from posthog.version import VERSION
16+
from posthog.contexts import tag
1617

1718

1819
class TestClient(unittest.TestCase):
@@ -2282,9 +2283,7 @@ def test_get_feature_flag_result_with_empty_string_payload(self, patch_batch_pos
22822283
}
22832284
]
22842285
},
2285-
"payloads": {
2286-
"empty-variant": "" # Empty string payload
2287-
},
2286+
"payloads": {"empty-variant": ""}, # Empty string payload
22882287
},
22892288
}
22902289
]
@@ -2355,3 +2354,15 @@ def test_get_all_flags_and_payloads_with_empty_string(self, patch_batch_post):
23552354
self.assertEqual(
23562355
result["featureFlagPayloads"]["normal-payload-flag"], "normal payload"
23572356
)
2357+
2358+
def test_context_tags_added(self):
2359+
with mock.patch("posthog.client.batch_post") as mock_post:
2360+
client = Client(FAKE_TEST_API_KEY, on_error=self.set_fail, sync_mode=True)
2361+
2362+
with new_context():
2363+
tag("random_tag", 12345)
2364+
client.capture("python test event", distinct_id="distinct_id")
2365+
2366+
batch_data = mock_post.call_args[1]["batch"]
2367+
msg = batch_data[0]
2368+
self.assertEqual(msg["properties"]["$context_tags"], ["random_tag"])

0 commit comments

Comments
 (0)