Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(activity-log): attribute bearer-token API writes to the key's user (#73120)

Juraj Majerik83d43639bb07
diff --git a/ee/api/test/test_insight.py b/ee/api/test/test_insight.py
index 65a89e942437..a2fab79d4e29 100644
--- a/ee/api/test/test_insight.py
+++ b/ee/api/test/test_insight.py
@@ -679,6 +679,8 @@ class TestInsightEnterpriseAPI(APILicensedTest):
activity: list[dict] = activity_response["results"]
for item in activity:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.maxDiff = None
assert activity == expected
diff --git a/ee/api/test/test_team.py b/ee/api/test/test_team.py
index aeb04f8b4987..0909911a61bd 100644
--- a/ee/api/test/test_team.py
+++ b/ee/api/test/test_team.py
@@ -42,6 +42,8 @@ def team_enterprise_api_test_factory():
activity = starting_log_response.json()["results"]
for item in activity:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
assert activity == expected
# Deleting projects
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 3382bdbad57c..e75d6d1f9d56 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -33,25 +33,25 @@ snapshots:
components-activitylog--data-management-activity--light:
hash: v1.k794b7964.c8098e6f319eac0f111a7699e90b8339c8fa22f1a450159bde643fd569c016fe.IqMEw51ZcqMn3s5rAfRHj_sbyzWoMfK1LOp5zgmQNd0
components-activitylog--feature-flag-activity--dark:
- hash: v1.k794b7964.f730919bc3a071c61d8c76af76c542c034b7a150106dd9fe1e1ac4df1095ed9e.bj35XVjYLa0jIyTMepGH-FqaIY-m9qJUINaLnSkhFRM
+ hash: v1.k794b7964.c50aafdb46bf983f33df0daaa56957997bffcbc7a744dd044127c04d88102125.w2ylz_uEGIEYNAdzFm01XLwEb5nSscju_qU8Wk7Zb_E
components-activitylog--feature-flag-activity--light:
- hash: v1.k794b7964.51b62a37edfd474ea52723fd9c5620714bf3cdf1691979f85475923170102139.RcyJNykM1vGOfQvCfh-wKf_R0mi_BdjSXFDvu35h_JU
+ hash: v1.k794b7964.5a8358a3bb67728abcc71ec423255206af014e13d1d95aaeaf2daba16bc96b45.tMsr51f9bhJSycyXPJYsOjM-kNAGQI2hFI3CbJBoyOk
components-activitylog--insight-activity--dark:
- hash: v1.k794b7964.eb8ab4a5d64e457bee89250de013f864c2efe412e7fb1fe894a21d7f48fc17ae.ec1cWLJcewr1-INmGxIgqKzISclVawlNI23e6wT0qKU
+ hash: v1.k794b7964.41b2c011efcf7aa3223a71cfec6444fba566bd2b39ee41166320907844b0ceae.5HLSP_ex1j65lKKvsc5brJ3sK5TNdqwoJJkJy_QGmj4
components-activitylog--insight-activity--light:
- hash: v1.k794b7964.595bb496d671f88da116938ab1e9313b24335d502568c152af72bb279e9a5e10.p8PiEM8BVorE2b-lJBiHg_JI6tGl56sdXaYpWN-B3ww
+ hash: v1.k794b7964.fd12a180d82b7fdaa9656b349b6772db22db42d2c5420d278cc9a4a29ab53bd7.z80OD8wV95-cjP_d3ROg7m6u-y25eLBYY6TXZG1odVg
components-activitylog--persons-activity--dark:
hash: v1.k794b7964.181dbbaf2ccb179e04600427183aa3156c5cf08429e08ddfad59340b04d95af8.4lnNMMaZ0lVO9EB8-WY6aeZKSr2NFaSeihK2gjggxZs
components-activitylog--persons-activity--light:
hash: v1.k794b7964.9c02ba8257e578b5e3951e49a132430dc77bdc6cee1f805df601952be1413b2b.QInEhub7NrwIFuvOlL0KjEO1fJIv3ALoSlfrHRG-WCI
components-activitylog--team-activity--dark:
- hash: v1.k794b7964.bce3a7b94aab027bb5a6cb53aa51b4052c66d122f3f68be21faa4717731eb0f0.qfpJaRgqmUboND-De4PWq0JpOSf6yVazqkjVsZNTDjs
+ hash: v1.k794b7964.bc25a618afb2de26c3eff106868ab4fbd3e52b19c7ac52d47c4427db32dd732c.bXtU3DwI_WpnlCnHAOu_8lbo2gMt9qQA4zp3UEhjf04
components-activitylog--team-activity--light:
- hash: v1.k794b7964.733d6b15db658b26d85a490f4ea0c0635b476e3a8c497cd597098ca16c32e967.afWwVB-H3EUCp2FkFOOFnSBTu1x4Li7wcsZ2mzhjvhE
+ hash: v1.k794b7964.10d5353835f51b3db0c19a80aa9f457523e6d698389a02b72bdf360a636807bd.2Fjfwjkw22VkdyEm_oYP64jgiEZbtSYUV2P_snheeHU
components-activitylog--with-caption--dark:
- hash: v1.k794b7964.639501eb6e20d60d49fa76c98a560b81e83766cbb1c4865d8815f789c07a88a4.ZqOsJ7xeAv7dne1wnObeay4kcUjd6fsiQJGxeiwbUSs
+ hash: v1.k794b7964.d47109e68a75102903a3c0773b280d888a6f18b25a2ab5521d7cf210231c4098.n9Ph9PHPw6LDyrJ47TifVEyeqocAj-YdQskRnJjleD8
components-activitylog--with-caption--light:
- hash: v1.k794b7964.ca824d044db859b43ce8caa88d6a50038925371a07db613b79f88043f4a22d48.D4F3TUJ12yoyRmecYTnwmKhOUjYqum0OCgMENi4CxqI
+ hash: v1.k794b7964.20e59716d386749675ff10e2b6c84b703463050f22196c15e5f326ee44483b25.WjQBpdfxfDuHG4dJ4KrYa1loSG5opyt9wD-rftojrJM
components-activitylog--with-no-data--dark:
hash: v1.k794b7964.f5fdcf0a533fc161ac18675eb65aeda181a3576854311f843bec32b3dfbe837b.VelIEEWqmJcIpjJBCsaY1f8-j9IgEC5az1ty5JLdtvE
components-activitylog--with-no-data--light:
@@ -5279,9 +5279,9 @@ snapshots:
scenes-app-batchexports--history-empty--light:
hash: v1.k794b7964.6e59b0f0726dd11daf6b7718d9f32d720e336a6753c19131e62098a40931961e.nZDF42SgAaRmgUR6tFKyVXF-M4LgD7Z55mwCTy_UeDM
scenes-app-batchexports--history-with-activity--dark:
- hash: v1.k794b7964.d7002af5a0f737339404b15a55a1c679e9f7740c1959679a9ee7fec09095a750.5ilMNemWTHacw8ZP4D-CJMeQjswlWn-6jmSLQnck46o
+ hash: v1.k794b7964.047ea02963790378acdd8aee67dbde3a6f8a14558477fd079d049ac54ac016e0.AxL4eaTLOQ7Nk9YNv0NrenX-mBA2LcNfmUZeGQZ8Zz0
scenes-app-batchexports--history-with-activity--light:
- hash: v1.k794b7964.032a89ce5488d6e44b35b476f66651a047c8dc8ee2be88cca6b35b9271bd5493.BnmkWTsTv3WZiuO7PBA7EiZg32zir8GpRXSsdD_pQL4
+ hash: v1.k794b7964.258d61da8bfdf1965ca21687fd1e3267e82cbc40f92ff0953df7dd5865eafffb.tbvK_J8jZZr-6jdU-hbv_sYd8CeHmkPjziHPtUGYbzY
scenes-app-batchexports--logs--dark:
hash: v1.k794b7964.ba725da206f3bf072c49d556df9b19cea3fbaa8e48a205c036ac94f9c100f047.zRJXSI8W8bULOYj3wJIqyRXNm4hDtlKkOBEFJUV7aNE
scenes-app-batchexports--logs--light:
diff --git a/frontend/src/lib/components/ActivityLog/ActivityLog.tsx b/frontend/src/lib/components/ActivityLog/ActivityLog.tsx
index 91402b4c22fb..3f41c3b54683 100644
--- a/frontend/src/lib/components/ActivityLog/ActivityLog.tsx
+++ b/frontend/src/lib/components/ActivityLog/ActivityLog.tsx
@@ -7,7 +7,7 @@ import { router } from 'kea-router'
import { Suspense, useEffect, useRef, useState } from 'react'
import { IconCollapse, IconExpand } from '@posthog/icons'
-import { LemonButton, LemonDivider, LemonTabs, Spinner } from '@posthog/lemon-ui'
+import { LemonButton, LemonDivider, LemonTabs, LemonTag, Spinner, Tooltip } from '@posthog/lemon-ui'
import { ActivityLogLogicProps, activityLogLogic } from 'lib/components/ActivityLog/activityLogLogic'
import { ActivityChange, HumanizedActivityLogItem } from 'lib/components/ActivityLog/humanizeActivity'
@@ -191,8 +191,15 @@ export const ActivityLogRow = ({
{logItem.extendedDescription && (
<div className="ActivityLogRow__description__extended">{logItem.extendedDescription}</div>
)}
- <div className="text-secondary">
+ <div className="text-secondary flex items-center gap-1.5">
<TZLabel time={logItem.created_at} />
+ {logItem.client && (
+ <Tooltip title="Self-reported by the API client in the x-posthog-client request header">
+ <LemonTag size="small" type="muted">
+ via {logItem.client === 'mcp' ? 'MCP' : logItem.client}
+ </LemonTag>
+ </Tooltip>
+ )}
</div>
</div>
{logItem.id && (
diff --git a/frontend/src/lib/components/ActivityLog/humanizeActivity.tsx b/frontend/src/lib/components/ActivityLog/humanizeActivity.tsx
index 38f2ae9c3605..d9f47764276c 100644
--- a/frontend/src/lib/components/ActivityLog/humanizeActivity.tsx
+++ b/frontend/src/lib/components/ActivityLog/humanizeActivity.tsx
@@ -76,6 +76,8 @@ export type HumanizedActivityLogItem = {
name?: string
isSystem?: boolean
wasImpersonated?: boolean
+ /** SDK or integration that triggered this action (from x-posthog-client header). */
+ client?: string | null
description: Description
extendedDescription?: ExtendedDescription // e.g. an insight's filters summary
created_at: dayjs.Dayjs
@@ -123,6 +125,7 @@ export function humanize(
: impersonatedUserName,
isSystem: logItem.is_system,
wasImpersonated: logItem.was_impersonated,
+ client: logItem.client,
description,
extendedDescription,
created_at: dayjs(logItem.created_at),
diff --git a/posthog/api/test/notebooks/test_notebook.py b/posthog/api/test/notebooks/test_notebook.py
index 5199ae612c8a..b9dfd5d98607 100644
--- a/posthog/api/test/notebooks/test_notebook.py
+++ b/posthog/api/test/notebooks/test_notebook.py
@@ -38,6 +38,8 @@ class TestNotebooks(APIBaseTest, QueryMatchingTest):
activity: list[dict] = activity_response.json()["results"]
for item in activity:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.maxDiff = None
assert activity == expected
diff --git a/posthog/api/test/test_activity_log.py b/posthog/api/test/test_activity_log.py
index 125d96bbf26b..007ac26c6f9a 100644
--- a/posthog/api/test/test_activity_log.py
+++ b/posthog/api/test/test_activity_log.py
@@ -7,12 +7,16 @@ from freezegun.api import FrozenDateTimeFactory, StepTickTimeFactory, TickingDat
from posthog.test.base import APIBaseTest, QueryMatchingTest
from unittest.mock import patch
+from django.utils import timezone
+
from parameterized import parameterized
from rest_framework import status
from posthog.constants import AvailableFeature
-from posthog.models import Organization, OrganizationMembership, Team, User
-from posthog.models.activity_logging.activity_log import Detail, log_activity
+from posthog.models import Organization, OrganizationMembership, PersonalAPIKey, Team, User
+from posthog.models.activity_logging.activity_log import ActivityLog, Detail, log_activity
+from posthog.models.oauth import OAuthAccessToken, OAuthApplication
+from posthog.models.utils import generate_random_token_personal, hash_key_value
def _feature_flag_json_payload(key: str) -> dict:
@@ -428,3 +432,62 @@ class TestOrganizationAdvancedActivityLogsAvailableFilters(APIBaseTest):
assert {"FeatureFlag", "Insight"}.issubset(scopes)
activities = {entry["value"] for entry in body["static_filters"]["activities"]}
assert {"created", "updated"}.issubset(activities)
+
+
+class TestActivityLogBearerAuthAttribution(APIBaseTest):
+ CONFIG_AUTO_LOGIN = False
+
+ def _create_experiment_and_get_activity(self, auth_header: str, flag_key: str) -> ActivityLog:
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/experiments/",
+ {"name": "Bearer auth experiment", "feature_flag_key": flag_key},
+ headers={"authorization": auth_header},
+ )
+ assert response.status_code == status.HTTP_201_CREATED, response.json()
+ return ActivityLog.objects.get(scope="Experiment", activity="created", item_id=str(response.json()["id"]))
+
+ def test_personal_api_key_write_is_attributed_to_key_owner(self) -> None:
+ value = generate_random_token_personal()
+ PersonalAPIKey.objects.create(label="Test", user=self.user, secure_value=hash_key_value(value), scopes=["*"])
+
+ log = self._create_experiment_and_get_activity(f"Bearer {value}", "pat-attribution-flag")
+
+ assert log.is_system is False
+ assert log.user == self.user
+
+ def _create_oauth_token(self, impersonated_by: User | None = None) -> OAuthAccessToken:
+ application = OAuthApplication.objects.create(
+ name="Test OAuth App",
+ client_type=OAuthApplication.CLIENT_CONFIDENTIAL,
+ authorization_grant_type=OAuthApplication.GRANT_AUTHORIZATION_CODE,
+ redirect_uris="https://example.com/callback",
+ algorithm="RS256",
+ organization=self.organization,
+ user=self.user,
+ )
+ return OAuthAccessToken.objects.create(
+ user=self.user,
+ application=application,
+ token="pha_activity_attribution_token",
+ expires=timezone.now() + timedelta(hours=1),
+ scope="experiment:write feature_flag:write",
+ impersonated_by=impersonated_by,
+ )
+
+ def test_oauth_token_write_is_attributed_to_token_user(self) -> None:
+ token = self._create_oauth_token()
+
+ log = self._create_experiment_and_get_activity(f"Bearer {token.token}", "oauth-attribution-flag")
+
+ assert log.is_system is False
+ assert log.user == self.user
+ assert log.was_impersonated is False
+
+ def test_impersonation_minted_oauth_token_write_is_marked_impersonated(self) -> None:
+ staff_user = User.objects.create_and_join(self.organization, "[email protected]", None)
+ token = self._create_oauth_token(impersonated_by=staff_user)
+
+ log = self._create_experiment_and_get_activity(f"Bearer {token.token}", "oauth-impersonation-flag")
+
+ assert log.user == self.user
+ assert log.was_impersonated is True
diff --git a/posthog/api/test/test_cohort.py b/posthog/api/test/test_cohort.py
index 5799b6978f12..f55c19f2c90c 100644
--- a/posthog/api/test/test_cohort.py
+++ b/posthog/api/test/test_cohort.py
@@ -105,6 +105,8 @@ class TestCohort(TestExportMixin, ClickhouseTestMixin, APIBaseTest, QueryMatchin
activity: list[dict] = activity_response["results"]
for item in activity:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.maxDiff = None
# Sort 'changes' lists for order-insensitive comparison
diff --git a/posthog/api/test/test_person.py b/posthog/api/test/test_person.py
index a4b816548c00..a0cfa3efe32b 100644
--- a/posthog/api/test/test_person.py
+++ b/posthog/api/test/test_person.py
@@ -1757,6 +1757,8 @@ class TestPerson(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
activity: list[dict] = activity_response["results"]
for item in activity:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.maxDiff = None
self.assertCountEqual(activity, expected)
diff --git a/posthog/api/test/test_team.py b/posthog/api/test/test_team.py
index 66836497ff25..9d3eff3b4cfb 100644
--- a/posthog/api/test/test_team.py
+++ b/posthog/api/test/test_team.py
@@ -65,6 +65,8 @@ def team_api_test_factory():
results = starting_log_response.json()["results"]
for item in results:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
assert results == expected
def _assert_organization_activity_log(self, expected: list[dict]) -> None:
@@ -73,6 +75,8 @@ def team_api_test_factory():
results = starting_log_response.json()["results"]
for item in results:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
assert results == expected
def _assert_activity_log_is_empty(self) -> None:
diff --git a/posthog/auth.py b/posthog/auth.py
index 18ece6854021..2072cc635c40 100644
--- a/posthog/auth.py
+++ b/posthog/auth.py
@@ -33,6 +33,7 @@ from posthog.constants import AvailableFeature
from posthog.helpers.two_factor_session import enforce_two_factor
from posthog.internal_api_secret import usable_internal_api_secrets
from posthog.jwt import PosthogJwtAudience, decode_jwt, get_oidc_verification_keys
+from posthog.models.activity_logging.utils import activity_storage
from posthog.models.oauth import OAuthAccessToken, OAuthApplication, OAuthApplicationAuthBrand
from posthog.models.organization import Organization, OrganizationMembership
from posthog.models.personal_api_key import (
@@ -323,6 +324,13 @@ class PersonalAPIKeyAuthentication(authentication.BaseAuthentication):
api_key_label=personal_api_key_object.label,
)
+ # ActivityLoggingMiddleware only captures session-authenticated users (it runs before
+ # DRF auth), so signal-driven activity logging would otherwise record bearer-token
+ # requests as system actions. Only write when the middleware owns cleanup: outside a
+ # request cycle (e.g. authenticate() called directly) the thread-local would leak.
+ if activity_storage.is_request_scoped():
+ activity_storage.set_user(personal_api_key_object.user)
+
self.personal_api_key = personal_api_key_object
self.personal_api_key_source = source
@@ -865,6 +873,18 @@ class OAuthAccessTokenAuthentication(authentication.BaseAuthentication):
access_method=AccessMethod.OAUTH,
)
+ # ActivityLoggingMiddleware only captures session-authenticated users (it runs
+ # before DRF auth), so signal-driven activity logging would otherwise record
+ # bearer-token requests as system actions. Only write when the middleware owns
+ # cleanup: outside a request cycle (e.g. authenticate() called directly) the
+ # thread-local would leak.
+ if activity_storage.is_request_scoped():
+ activity_storage.set_user(access_token.user)
+ # Tokens minted during staff impersonation must keep the impersonation
+ # marker in the audit trail.
+ if access_token.impersonated_by_id is not None:
+ activity_storage.set_was_impersonated(True)
+
return access_token.user, None
except AuthenticationFailed:
diff --git a/posthog/middleware.py b/posthog/middleware.py
index a3266f69cb9d..259c010a05a4 100644
--- a/posthog/middleware.py
+++ b/posthog/middleware.py
@@ -1111,6 +1111,10 @@ class ActivityLoggingMiddleware:
self.get_response = get_response
def __call__(self, request: HttpRequest):
+ # Lets bearer-auth code (which runs later, inside the view) attribute activity safely,
+ # knowing the finally block below will clean up.
+ activity_storage.mark_request_scoped()
+
# Set user in activity storage if authenticated
if request.user.is_authenticated:
activity_storage.set_user(request.user)
diff --git a/posthog/models/activity_logging/model_activity.py b/posthog/models/activity_logging/model_activity.py
index 6f5b42c5f815..61db25fb15d9 100644
--- a/posthog/models/activity_logging/model_activity.py
+++ b/posthog/models/activity_logging/model_activity.py
@@ -170,12 +170,19 @@ class ImpersonatedContext:
from posthog.helpers.impersonation import is_impersonated # noqa: PLC0415
self.was_impersonated = is_impersonated(request)
+ self.previous = False
def __enter__(self):
if self.was_impersonated:
+ # Save and restore rather than clear on exit, so this context can't erase an
+ # impersonation flag set for the whole request (by middleware or bearer auth).
+ self.previous = activity_storage.get_was_impersonated()
activity_storage.set_was_impersonated(True)
return self
def __exit__(self, exc_type, exc_value, traceback):
if self.was_impersonated:
- activity_storage.clear_was_impersonated()
+ if self.previous:
+ activity_storage.set_was_impersonated(True)
+ else:
+ activity_storage.clear_was_impersonated()
diff --git a/posthog/models/activity_logging/serializers.py b/posthog/models/activity_logging/serializers.py
index d5997be6207a..92f88911bd7c 100644
--- a/posthog/models/activity_logging/serializers.py
+++ b/posthog/models/activity_logging/serializers.py
@@ -51,6 +51,17 @@ class ActivityLogSerializer(serializers.Serializer):
item_id = serializers.CharField(read_only=True)
detail = DetailSerializer(required=False)
created_at = serializers.DateTimeField(read_only=True)
+ is_system = serializers.BooleanField(
+ read_only=True, help_text="Whether the activity was performed by the system rather than a user."
+ )
+ was_impersonated = serializers.BooleanField(
+ read_only=True, help_text="Whether the acting user was being impersonated by PostHog staff."
+ )
+ client = serializers.CharField(
+ read_only=True,
+ allow_null=True,
+ help_text="API client that triggered the activity, from the x-posthog-client request header (e.g. 'mcp'). Null for requests that did not send the header.",
+ )
@extend_schema_field({"type": "object", "nullable": True})
def get_user(self, activity_log: ActivityLog):
diff --git a/posthog/models/activity_logging/utils.py b/posthog/models/activity_logging/utils.py
index f4b93b9f1c2a..80bd5af94458 100644
--- a/posthog/models/activity_logging/utils.py
+++ b/posthog/models/activity_logging/utils.py
@@ -24,6 +24,20 @@ class ActivityLoggingStorage:
def __init__(self):
self._local = Local()
+ # ActivityLoggingMiddleware marks the storage as request-scoped and guarantees cleanup in a
+ # finally block. Code without its own cleanup path (e.g. DRF authentication classes) must only
+ # write here when the middleware owns the lifecycle, otherwise the thread-local leaks past the
+ # request and later activity gets attributed to a stale user.
+ def mark_request_scoped(self) -> None:
+ self._local.request_scoped = True
+
+ def is_request_scoped(self) -> bool:
+ return getattr(self._local, "request_scoped", False)
+
+ def clear_request_scoped(self) -> None:
+ if hasattr(self._local, "request_scoped"):
+ delattr(self._local, "request_scoped")
+
def set_user(self, user: Any) -> None:
self._local.user = user
@@ -75,6 +89,7 @@ class ActivityLoggingStorage:
delattr(self._local, "trigger")
def clear_all(self) -> None:
+ self.clear_request_scoped()
self.clear_user()
self.clear_was_impersonated()
self.clear_client()
diff --git a/products/cdp/backend/api/test/test_plugin.py b/products/cdp/backend/api/test/test_plugin.py
index bd67287af6cf..11fd832edcc3 100644
--- a/products/cdp/backend/api/test/test_plugin.py
+++ b/products/cdp/backend/api/test/test_plugin.py
@@ -61,6 +61,8 @@ class TestPluginAPI(APIBaseTest, QueryMatchingTest):
activity: list[dict] = activity_response["results"]
for item in activity:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.maxDiff = None
self.assertEqual(activity, expected)
diff --git a/products/error_tracking/backend/tests/api/test_error_tracking_api.py b/products/error_tracking/backend/tests/api/test_error_tracking_api.py
index e4f6f50aecc3..03072d7557e9 100644
--- a/products/error_tracking/backend/tests/api/test_error_tracking_api.py
+++ b/products/error_tracking/backend/tests/api/test_error_tracking_api.py
@@ -1204,6 +1204,8 @@ class TestErrorTracking(APIBaseTest):
activity: list[dict] = activity_response["results"]
for item in activity:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.maxDiff = None
self.assertEqual(activity, expected)
diff --git a/products/exports/backend/api/test/test_exports.py b/products/exports/backend/api/test/test_exports.py
index e42329c6e7f8..a96f5e0c693c 100644
--- a/products/exports/backend/api/test/test_exports.py
+++ b/products/exports/backend/api/test/test_exports.py
@@ -561,6 +561,8 @@ class TestExports(APIBaseTest):
activity: list[dict] = activity_response["results"]
for item in activity:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.maxDiff = None
self.assertEqual(activity, expected)
diff --git a/products/feature_flags/backend/api/test/test_feature_flag.py b/products/feature_flags/backend/api/test/test_feature_flag.py
index 7c54fca470d5..24054b7142b8 100644
--- a/products/feature_flags/backend/api/test/test_feature_flag.py
+++ b/products/feature_flags/backend/api/test/test_feature_flag.py
@@ -6361,6 +6361,8 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
activity: list[dict] = activity_response["results"]
for item in activity:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.maxDiff = None
assert activity == expected
diff --git a/products/feature_flags/frontend/generated/api.schemas.ts b/products/feature_flags/frontend/generated/api.schemas.ts
index 2c10332eb15d..76e389d44c92 100644
--- a/products/feature_flags/frontend/generated/api.schemas.ts
+++ b/products/feature_flags/frontend/generated/api.schemas.ts
@@ -1090,6 +1090,15 @@ export interface ActivityLogEntryApi {
readonly item_id: string
detail?: DetailApi
readonly created_at: string
+ /** Whether the activity was performed by the system rather than a user. */
+ readonly is_system: boolean
+ /** Whether the acting user was being impersonated by PostHog staff. */
+ readonly was_impersonated: boolean
+ /**
+ * API client that triggered the activity, from the x-posthog-client request header (e.g. 'mcp'). Null for requests that did not send the header.
+ * @nullable
+ */
+ readonly client: string | null
}
/**
diff --git a/products/product_analytics/backend/api/test/test_insight.py b/products/product_analytics/backend/api/test/test_insight.py
index bfd8afbd2df3..2bd4143be3dc 100644
--- a/products/product_analytics/backend/api/test/test_insight.py
+++ b/products/product_analytics/backend/api/test/test_insight.py
@@ -3524,6 +3524,8 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
activity: list[dict] = activity_response["results"]
for item in activity:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.maxDiff = None
assert activity == expected
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index 549889557dae..9a3d6a4118e4 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -7636,6 +7636,15 @@ export interface ActivityLogEntryApi {
readonly item_id: string
detail?: DetailApi
readonly created_at: string
+ /** Whether the activity was performed by the system rather than a user. */
+ readonly is_system: boolean
+ /** Whether the acting user was being impersonated by PostHog staff. */
+ readonly was_impersonated: boolean
+ /**
+ * API client that triggered the activity, from the x-posthog-client request header (e.g. 'mcp'). Null for requests that did not send the header.
+ * @nullable
+ */
+ readonly client: string | null
}
/**
diff --git a/products/surveys/backend/api/test/test_survey.py b/products/surveys/backend/api/test/test_survey.py
index 20a79970c60f..d73ead41480d 100644
--- a/products/surveys/backend/api/test/test_survey.py
+++ b/products/surveys/backend/api/test/test_survey.py
@@ -3156,6 +3156,8 @@ class TestSurvey(APIBaseTest):
results = activity["results"]
for item in results:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.assertEqual(results, expected)
def test_validate_schedule_on_create(self):
@@ -6471,6 +6473,8 @@ class TestSurveyResponseArchive(ClickhouseTestMixin, APIBaseTest):
results = activity["results"]
for item in results:
item.pop("id", None)
+ for envelope_key in ("is_system", "was_impersonated", "client"):
+ item.pop(envelope_key, None)
self.assertEqual(results, expected)
@freeze_time("2024-05-01 12:00:00")
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 7fd69f2dd9f2..d387343a3464 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -2277,6 +2277,15 @@ export namespace Schemas {
readonly item_id: string;
detail?: Detail;
readonly created_at: string;
+ /** Whether the activity was performed by the system rather than a user. */
+ readonly is_system: boolean;
+ /** Whether the acting user was being impersonated by PostHog staff. */
+ readonly was_impersonated: boolean;
+ /**
+ * API client that triggered the activity, from the x-posthog-client request header (e.g. 'mcp'). Null for requests that did not send the header.
+ * @nullable
+ */
+ readonly client: string | null;
}
/**