Skip to content

Commit 6b7c840

Browse files
authored
test: add server SDK wire snapshots (#876)
* test: add server SDK wire snapshots * chore: remove test-only changeset
1 parent 91afeab commit 6b7c840

4 files changed

Lines changed: 505 additions & 0 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"body": {
3+
"api_key": "phc_snapshot_project",
4+
"batch": [
5+
{
6+
"distinct_id": "user-123",
7+
"event": "$exception",
8+
"properties": {
9+
"$exception_list": [
10+
{
11+
"mechanism": {
12+
"handled": true,
13+
"type": "generic"
14+
},
15+
"module": null,
16+
"stacktrace": {
17+
"frames": [
18+
{
19+
"abs_path": "<PROJECT_ROOT>/posthog/test/test_server_payload_snapshots.py",
20+
"context_line": " _raise_snapshot_exception()",
21+
"filename": "posthog/test/test_server_payload_snapshots.py",
22+
"function": "_exception_request",
23+
"in_app": true,
24+
"lineno": "<LINE_NUMBER>",
25+
"module": "posthog.test.test_server_payload_snapshots",
26+
"platform": "python",
27+
"post_context": [
28+
" except RuntimeError as error:",
29+
" client.capture_exception(",
30+
" error,",
31+
" distinct_id=\"user-123\",",
32+
" properties={\"component\": \"checkout\", \"severity\": \"high\"},"
33+
],
34+
"pre_context": [
35+
" project_root=str(Path(__file__).parents[2]),",
36+
" capture_exception_code_variables=False,",
37+
" )",
38+
" try:",
39+
" try:"
40+
]
41+
},
42+
{
43+
"abs_path": "<PROJECT_ROOT>/posthog/test/test_server_payload_snapshots.py",
44+
"context_line": " raise RuntimeError(\"checkout failed\") from cause",
45+
"filename": "posthog/test/test_server_payload_snapshots.py",
46+
"function": "_raise_snapshot_exception",
47+
"in_app": true,
48+
"lineno": "<LINE_NUMBER>",
49+
"module": "posthog.test.test_server_payload_snapshots",
50+
"platform": "python",
51+
"post_context": [
52+
"",
53+
"",
54+
"def _exception_request():",
55+
" session = mock.MagicMock()",
56+
" session.post.return_value = _successful_response()"
57+
],
58+
"pre_context": [
59+
"",
60+
"def _raise_snapshot_exception() -> None:",
61+
" try:",
62+
" raise ValueError(\"invalid order total\")",
63+
" except ValueError as cause:"
64+
]
65+
}
66+
],
67+
"type": "raw"
68+
},
69+
"type": "RuntimeError",
70+
"value": "checkout failed"
71+
},
72+
{
73+
"mechanism": {
74+
"handled": true,
75+
"type": "generic"
76+
},
77+
"module": null,
78+
"stacktrace": {
79+
"frames": [
80+
{
81+
"abs_path": "<PROJECT_ROOT>/posthog/test/test_server_payload_snapshots.py",
82+
"context_line": " raise ValueError(\"invalid order total\")",
83+
"filename": "posthog/test/test_server_payload_snapshots.py",
84+
"function": "_raise_snapshot_exception",
85+
"in_app": true,
86+
"lineno": "<LINE_NUMBER>",
87+
"module": "posthog.test.test_server_payload_snapshots",
88+
"platform": "python",
89+
"post_context": [
90+
" except ValueError as cause:",
91+
" raise RuntimeError(\"checkout failed\") from cause",
92+
"",
93+
"",
94+
"def _exception_request():"
95+
],
96+
"pre_context": [
97+
" return _transport_request(session.post.call_args)",
98+
"",
99+
"",
100+
"def _raise_snapshot_exception() -> None:",
101+
" try:"
102+
]
103+
}
104+
],
105+
"type": "raw"
106+
},
107+
"type": "ValueError",
108+
"value": "invalid order total"
109+
}
110+
],
111+
"$geoip_disable": true,
112+
"$groups": {
113+
"company": "company-456"
114+
},
115+
"$is_server": true,
116+
"$lib": "posthog-python",
117+
"$lib_version": "<SDK_VERSION>",
118+
"$os": "<OS>",
119+
"$os_distro": "<OS_DISTRO>",
120+
"$os_version": "<OS_VERSION>",
121+
"$python_runtime": "<PYTHON_RUNTIME>",
122+
"$python_version": "<PYTHON_VERSION>",
123+
"component": "checkout",
124+
"severity": "high"
125+
},
126+
"timestamp": "2026-01-02T03:04:05+00:00",
127+
"uuid": "00000000-0000-4000-8000-000000000005"
128+
}
129+
],
130+
"historical_migration": false,
131+
"sent_at": "2026-01-02T03:04:05+00:00"
132+
},
133+
"headers": {
134+
"Content-Type": "application/json",
135+
"User-Agent": "posthog-python/<SDK_VERSION>"
136+
},
137+
"timeout": 15,
138+
"url": "https://example.posthog.test/batch/"
139+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"body": {
3+
"api_key": "phc_snapshot_project",
4+
"device_id": "device-789",
5+
"distinct_id": "user-123",
6+
"flag_keys_to_evaluate": [
7+
"checkout-redesign",
8+
"new-billing"
9+
],
10+
"geoip_disable": false,
11+
"group_properties": {
12+
"company": {
13+
"employees": 42,
14+
"industry": "technology"
15+
}
16+
},
17+
"groups": {
18+
"company": "company-456"
19+
},
20+
"person_properties": {
21+
"email": "person@example.com",
22+
"plan": "pro"
23+
},
24+
"sent_at": "2026-01-02T03:04:05+00:00"
25+
},
26+
"headers": {
27+
"Content-Type": "application/json",
28+
"User-Agent": "posthog-python/<SDK_VERSION>"
29+
},
30+
"timeout": 3,
31+
"url": "https://example.posthog.test/flags/?v=2"
32+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"body": {
3+
"api_key": "phc_snapshot_project",
4+
"batch": [
5+
{
6+
"distinct_id": "user-123",
7+
"event": "order completed",
8+
"properties": {
9+
"$geoip_disable": true,
10+
"$groups": {
11+
"company": "company-456"
12+
},
13+
"$is_server": true,
14+
"$lib": "posthog-python",
15+
"$lib_version": "<SDK_VERSION>",
16+
"$os": "<OS>",
17+
"$os_distro": "<OS_DISTRO>",
18+
"$os_version": "<OS_VERSION>",
19+
"$python_runtime": "<PYTHON_RUNTIME>",
20+
"$python_version": "<PYTHON_VERSION>",
21+
"amount": 29.5,
22+
"items": [
23+
{
24+
"quantity": 1,
25+
"sku": "SKU-1"
26+
},
27+
{
28+
"quantity": 2,
29+
"sku": "SKU-2"
30+
}
31+
]
32+
},
33+
"timestamp": "2026-01-02T03:04:05+00:00",
34+
"uuid": "00000000-0000-4000-8000-000000000001"
35+
},
36+
{
37+
"$set": {
38+
"email": "person@example.com",
39+
"plan": "pro"
40+
},
41+
"distinct_id": "user-123",
42+
"event": "$set",
43+
"properties": {
44+
"$geoip_disable": true,
45+
"$is_server": true,
46+
"$lib": "posthog-python",
47+
"$lib_version": "<SDK_VERSION>"
48+
},
49+
"timestamp": "2026-01-02T03:04:05+00:00",
50+
"uuid": "00000000-0000-4000-8000-000000000002"
51+
},
52+
{
53+
"distinct_id": "anonymous-789",
54+
"event": "$create_alias",
55+
"properties": {
56+
"$geoip_disable": true,
57+
"$is_server": true,
58+
"$lib": "posthog-python",
59+
"$lib_version": "<SDK_VERSION>",
60+
"alias": "user-123",
61+
"distinct_id": "anonymous-789"
62+
},
63+
"timestamp": "2026-01-02T03:04:05+00:00",
64+
"uuid": "00000000-0000-4000-8000-000000000003"
65+
},
66+
{
67+
"distinct_id": "user-123",
68+
"event": "$groupidentify",
69+
"properties": {
70+
"$geoip_disable": true,
71+
"$group_key": "company-456",
72+
"$group_set": {
73+
"employees": 42,
74+
"name": "Example Corp"
75+
},
76+
"$group_type": "company",
77+
"$is_server": true,
78+
"$lib": "posthog-python",
79+
"$lib_version": "<SDK_VERSION>"
80+
},
81+
"timestamp": "2026-01-02T03:04:05+00:00",
82+
"uuid": "00000000-0000-4000-8000-000000000004"
83+
}
84+
],
85+
"historical_migration": false,
86+
"sent_at": "2026-01-02T03:04:05+00:00"
87+
},
88+
"headers": {
89+
"Content-Type": "application/json",
90+
"User-Agent": "posthog-python/<SDK_VERSION>"
91+
},
92+
"timeout": 15,
93+
"url": "https://example.posthog.test/batch/"
94+
}

0 commit comments

Comments
 (0)