Update dependency posthog to v7 - #2765
Conversation
5f99506 to
2e80889
Compare
0ebd496 to
7eacc99
Compare
081ca27 to
450b7fb
Compare
70c7b6f to
4417b6e
Compare
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
| opentelemetry-instrumentation-requests = ">=0.52b0" | ||
| opentelemetry-sdk = ">=1.31.0" | ||
| pluggy = "^1.3.0" | ||
| posthog = "^5.0.0" | ||
| posthog = "^7.0.0" | ||
| psycopg = "^3.2.4" | ||
| psycopg2 = "^2.9.6" | ||
| pycountry = "^24.6.1" |
There was a problem hiding this comment.
Bug: Calls to PostHog functions like posthog.capture use positional arguments that may have become keyword-only in the upgraded version, potentially causing a TypeError at runtime.
Severity: MEDIUM
Suggested Fix
Update all calls to posthog.capture, posthog.get_all_flags, and posthog.get_feature_flag to use explicit keyword arguments to match the new API. For example, change posthog.capture(user.id, ...) to posthog.capture(distinct_id=user.id, ...).
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: pyproject.toml#L84-L90
Potential issue: The `posthog` library was upgraded, and versions since v6 have
introduced breaking changes to function signatures. Calls to `posthog.capture`,
`posthog.get_all_flags`, and `posthog.get_feature_flag` in the codebase use positional
arguments (e.g., `posthog.capture(user.id, ...)`). The newer library versions may
require these arguments to be passed as keyword arguments (e.g., `distinct_id=user.id`).
If backward compatibility is not maintained in v7, these function calls will raise a
`TypeError` at runtime. This potential issue is not covered by the test suite because
the `posthog` functions are mocked, preventing signature validation against the actual
library.
| "opentelemetry-sdk>=1.31.0", | ||
| "pluggy>=1.3.0,<2", | ||
| "posthog>=5.0.0,<6", | ||
| "posthog>=7.9.4,<8", |
There was a problem hiding this comment.
Bug: The call to posthog.capture() in main/middleware/apisix_user.py uses a positional argument for the user ID, but the upgraded PostHog library requires a keyword argument (distinct_id=...).
Severity: CRITICAL
Suggested Fix
In main/middleware/apisix_user.py, change the call to posthog.capture() to use the keyword argument distinct_id for the user ID. The corrected call should be posthog.capture(distinct_id=user.id, event=..., properties={...}).
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: pyproject.toml#L83
Potential issue: The `posthog` library was upgraded to v7, which requires keyword
arguments for the `capture` method. The code in `main/middleware/apisix_user.py` calls
`posthog.capture(user.id, ...)` using a positional argument for the distinct ID. In
PostHog v7, this positional argument is interpreted as the `event` parameter. Since the
`event` keyword argument is also supplied in the call, this will raise a `TypeError` at
runtime due to a duplicate argument. This error will occur whenever a new user account
is created, preventing the account creation process from completing successfully.
| "opentelemetry-sdk>=1.31.0", | ||
| "pluggy>=1.3.0,<2", | ||
| "posthog>=5.0.0,<6", | ||
| "posthog>=7.9.4,<8", |
There was a problem hiding this comment.
Bug: A temporary Posthog instance in apisix_user.py is garbage collected before its asynchronously queued events can be sent, causing silent event loss.
Severity: HIGH
Suggested Fix
To ensure the event is sent, either call posthog.shutdown() after the .capture() call, instantiate the client with sync_mode=True, or use the existing singleton posthog.default_client from main/features.py.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: pyproject.toml#L83
Potential issue: In `main/middleware/apisix_user.py`, a one-off `Posthog` instance is
created to track user creation events. The PostHog v7 SDK sends events asynchronously by
default, queuing them to be sent by a background thread. However, because the `Posthog`
instance is not stored and no `posthog.shutdown()` or `posthog.flush()` is called, the
instance is garbage collected before the background thread can send the queued event.
This results in the silent loss of all user creation events, which are critical for
telemetry and usage analysis.
| "opentelemetry-sdk>=1.31.0", | ||
| "pluggy>=1.3.0,<2", | ||
| "posthog>=5.0.0,<6", | ||
| "posthog>=7.9.7,<8", |
There was a problem hiding this comment.
Bug: The posthog.capture() call uses a positional argument for distinct_id, which is incompatible with the PostHog v7 API and will cause a runtime failure.
Severity: HIGH
Suggested Fix
Update the posthog.capture() call in main/middleware/apisix_user.py to use a keyword argument for the user's ID. Change the call from posthog.capture(user.id, event=...) to posthog.capture(distinct_id=user.id, event=...) to match the v6+ API.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: pyproject.toml#L83
Potential issue: The upgrade of the `posthog` library from v5 to v7 introduces a
breaking API change. The `posthog.capture()` method in `main/middleware/apisix_user.py`
is called with a positional argument for the user's ID (`user.id`), following the old v5
pattern. However, PostHog v6 and later require this to be a keyword argument,
`distinct_id=user.id`. This will cause a runtime error, likely a `TypeError`, or a
silent failure when a new user is created via the APISIX authentication pathway. As a
result, account creation events will not be tracked. This issue is not caught by
existing tests because the `Posthog` class is mocked without signature validation.
| "opentelemetry-sdk>=1.31.0", | ||
| "pluggy>=1.3.0,<2", | ||
| "posthog>=5.0.0,<6", | ||
| "posthog>=7.9.8,<8", |
There was a problem hiding this comment.
Bug: The call to posthog.capture() uses an outdated positional argument for user.id, which will cause a TypeError with the updated PostHog v7 library during user creation.
Severity: HIGH
Suggested Fix
Update the posthog.capture() call in main/middleware/apisix_user.py to use keyword arguments as required by the new version of the library. The distinct_id should be passed as a keyword argument, not a positional one. The corrected call should look like: posthog.capture(event=PostHogEvents.ACCOUNT_CREATED.value, distinct_id=user.id, properties={...}).
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: pyproject.toml#L83
Potential issue: The upgrade of the `posthog` library from version 5 to 7 introduces a
breaking API change that is not accounted for. The `posthog.capture()` method in
`main/middleware/apisix_user.py` is called with a positional argument for the user ID:
`posthog.capture(user.id, event=...)`. In PostHog v7, the first argument is expected to
be the event name, and the `distinct_id` (user ID) must be passed as a keyword argument.
This mismatch will cause a `TypeError` at runtime whenever a new user account is
created, breaking the user creation flow.
|
This PR contains the following updates:
>=5.0.0,<6→>=7.30,<8Warning
Some dependencies could not be looked up. Check the Dependency Dashboard for more information.
Release Notes
posthog/posthog-python (posthog)
v7.30.0Compare Source
Minor changes
$session_idand the client identity (harness) across pods via a self-encodedMcp-Session-Idtoken minted atinitializeand replayed on every request. Auto-wired on theinstrument()FastMCP path (stateless_http=True); customPostHogMCPdispatchers addPostHogMcpStatelessSessionMiddlewareand readget_mcp_session(). — Thanks @gesh!v7.29.0Compare Source
Minor changes
f9a163c Refactored capture internals to support multiple delivery lanes per client. Added an internal test lane for heavy AI events.
Events captured after
shutdown()are now dropped with a warning instead of being silently queued with no consumer to deliver them. — Thanks @carlos-marchal-ph!v7.28.0Compare Source
Minor changes
client.metricsconfig can now be set through module-level settings: assignposthog.metrics = {"service_name": ..., ...}alongsideposthog.api_keyand the dict is applied whensetup()builds the global client. Previously module-configured apps had no way to pass the metrics config, so every series recorded through the global client shippedservice.name='unknown_service'. Late assignment (e.g. a Djangoready()hook running after an earlysetup()) still applies on the nextsetup()call, as long as the metrics API hasn't been used yet. — Thanks @DanielVisca!Patch changes
6766309 Harden the alpha
posthog.metricsclient based on review follow-ups.count()/gauge()/histogram()can no longer rewrite an already-recorded series' attributes on the wire.metricsclient config (non-dict config orresource_attributes, non-numericflush_interval, non-integermax_series_per_flush, non-callablebefore_send) now degrades to defaults with a warning instead of raising from the firstclient.metrics.count()call, matching the client's no-throw contract. — Thanks @DanielVisca!v7.27.1Compare Source
Patch changes
v7.27.0Compare Source
Minor changes
5ef2c23
$feature_flag_calledevents are now minimized for non-experiment flags when the server enables it. When the/flagsv2 response (minimalFlagCalledEvents) or the local-evaluation payload (minimal_flag_called_events) reports the gate as enabled and the evaluated flag has no linked experiment (has_experimentisfalse), the event's properties are reduced to a strict allowlist ($feature_flag,$feature_flag_response,$feature_flag_has_experiment, the$feature_flag_*debug scalars,locally_evaluated,$groups,$process_person_profile,$session_id,$lib,$lib_version,$is_server,$geoip_disable,$os,$os_version,$os_distro,$python_runtime,$python_version). Everything else — including super properties and custom event properties — is stripped from those events.If the server does not report the gate, if the flag's
has_experimentsignal is missing, or if the flag is linked to an experiment, the full property set is sent unchanged. There is no SDK-side configuration; the gate is controlled per-team by the server. Forevaluate_flags()snapshots, the gate is pinned when the snapshot is created, so deferred flag accesses are shaped by the evaluation that produced them.Custom
flag_definition_cacheproviders now receive an additionalminimal_flag_called_eventskey in the definitions payload, so the gate survives external cache round-trips.When the server reports
has_experimentfor a flag, every$feature_flag_calledevent also carries a$feature_flag_has_experimentboolean property. — Thanks @haacked!v7.26.0Compare Source
Minor changes
labeloption toPrompts.get()to fetch the prompt version a label (e.g.production) currently points to. Labeled fetches are cached separately, andPromptResultcarries the resolvedlabel. Requires a PostHog version with prompt labels; older servers ignore the parameter and return the latest version. — Thanks @jurajmajerik!v7.25.0Compare Source
Minor changes
$trace_idand$span_idto events captured withcapture_exception. — Thanks @hpouillot!v7.24.0Compare Source
Minor changes
$feature_flag_calledevents now carry a$feature_flag_has_experimentboolean property when the server reports whether the flag is linked to an experiment. When the server does not report the signal (older deployments), the property is omitted. — Thanks @haacked!v7.23.0Compare Source
Minor changes
5e42b1e Add the
posthog.metricsAPI (count,gauge,histogram) — alpha.Backend services can now record metrics through the same statsd-style pre-aggregating client the browser SDK ships, with no OpenTelemetry setup:
Samples aggregate in memory and flush as OTLP/JSON to
/i/v1/metrics(one data point per series per window, delta temporality). Pending metrics are flushed onshutdown(); buffered windows are retried on transient failures and dropped loudly after 3 consecutive failed flushes. Themetricsclient option acceptsservice_name,service_version,environment,resource_attributes,flush_interval(seconds),max_series_per_flush(cardinality guardrail, default 1000), and abefore_sendhook. — Thanks @DanielVisca!v7.22.4Compare Source
Patch changes
$raw_user_agent, the standardized property PostHog's server-side classification (e.g. bot detection) reads — Thanks @lricoy!v7.22.3Compare Source
Patch changes
/flagsendpoint on every evaluation. 7.22.1 made these conditions fall back to the server, which could massively increase billable/flagsrequest volume for flag definitions containing legacy/malformed dependency conditions. — Thanks @patricio-posthog!v7.22.2Compare Source
Patch changes
v7.22.1Compare Source
Patch changes
flag_evaluates_to: falsecondition: such conditions never matched, forcing the dependent flag tofalsefor every locally-evaluated user. — Thanks @matheus-vb!v7.22.0Compare Source
Minor changes
d459b57 Add an opt-in
capture_modefor the Capture V1 ingestion protocol (POST /i/v1/analytics/events). Setcapture_mode="v1"on the client (or thePOSTHOG_CAPTURE_MODE=v1environment variable) to use Bearer auth, per-event results, and partial retry. Defaults to"v0"(the legacy/batch/endpoint), so existing setups are unaffected.When using
capture_mode="v1", request bodies can be compressed viacapture_compression(orPOSTHOG_CAPTURE_COMPRESSION):"gzip","deflate","zstd"(requires the optionalposthog[zstd]extra), or"none"(default). The legacygzip=Trueflag is honored as a fallback.Per-event server verdicts are surfaced through the existing
on_errorhandler: events the backend explicitly drops, or fails to accept after retries, raise aCaptureV1Errorcarrying the affected event UUIDs — so a rejection is never silently lost, even when the HTTP request itself succeeded. — Thanks @eli-r-ph for your first contribution 🎉!v7.21.3Compare Source
Patch changes
v7.21.2Compare Source
Patch changes
v7.21.1Compare Source
Patch changes
v7.21.0Compare Source
Minor changes
posthog.mcp, a Python SDK for PostHog MCP analytics (justpip install posthog; the MCP SDK is a peer dependency ofinstrument(), not bundled).instrument(server, posthog_client)wraps aFastMCPor low-levelmcp.server.Serverso every tool call, agent intent, tools/list, initialize, and failure is captured to PostHog as a$mcp_*event. Also addsPostHogMCP, aClientsubclass for custom dispatchers (needs nothing beyond posthog), plus opt-incontextintent capture,identify,report_missing(get_more_tools), andconversation_id. Beta. — Thanks @lucasheriques for your first contribution 🎉!v7.20.5Compare Source
Patch changes
v7.20.4Compare Source
Patch changes
v7.20.3Compare Source
Patch changes
code_variables_detect_secretsoption (defaultTrue). — Thanks @ablaszkiewicz!v7.20.2Compare Source
Patch changes
passwordare redacted by attribute name instead of leaking viarepr(), and credentials embedded in connection strings are scrubbed. Adds thecode_variables_mask_url_credentialsoption (defaultTrue). — Thanks @ablaszkiewicz!v7.20.1Compare Source
Patch changes
v7.20.0Compare Source
Minor changes
v7.19.2Compare Source
Patch changes
v7.19.1Compare Source
Patch changes
v7.19.0Compare Source
Minor changes
enable_exception_autocapture_rate_limitingclient option and tune viaexception_autocapture_bucket_size(default 50),exception_autocapture_refill_rate(default 10), andexception_autocapture_refill_interval_seconds(default 10). — Thanks @hpouillot!v7.18.3Compare Source
Patch changes
base_urlpoints at the PostHog AI Gateway. The gateway emits its own$ai_generation, so each call would be captured (and billed) twice. The wrapper only warns and never drops the event. Detection covers the wrapper funnels (OpenAI, Anthropic, LangChain) and the OTel span path. — Thanks @richardsolomou!v7.18.2Compare Source
Patch changes
v7.18.1Compare Source
Patch changes
$ai_*events to a dedicated capture endpoint in their own batch, gated behind the unstable_dedicated_ai_endpointclient option (off by default, not for general use). — Thanks @carlos-marchal-ph!v7.18.0Compare Source
Minor changes
early_exitcondition option in local evaluation. When a flag enables early exit, evaluation now stops and returnsFalseas soon as a condition group's property filters match but the rollout percentage excludes the user, instead of falling through to later groups — matching the server-side evaluation behavior. — Thanks @gustavohstrassburger!v7.17.0Compare Source
Minor changes
$is_serverevent property (defaulttrue) so PostHog can identify server-side events. Setis_server=Falsewhen using posthog-python as a client/CLI so the device OS is attributed normally. — Thanks @turnipdabeets for your first contribution 🎉!v7.16.4Compare Source
Patch changes
async withas well asasync for. Previously, consuming a stream viaasync with(e.g. with pydantic-ai) raisedTypeError: 'async_generator' object does not support the asynchronous context manager protocol. — Thanks @turnipdabeets for your first contribution 🎉!v7.16.3Compare Source
Patch changes
v7.16.2Compare Source
Patch changes
v7.16.1Compare Source
Patch changes
$feature_flag_calleddedupe key so group-scoped flags fire a separate event for each group a user is evaluated under, instead of being dedup-ed against the first group context the same(distinct_id, flag, response)was seen under. — Thanks @gustavohstrassburger!v7.16.0Compare Source
Minor changes
v7.15.4Compare Source
Patch changes
v7.15.3Compare Source
Patch changes
1.07.3are not valid semver and should not match targeting conditions. Both override values and flag values are now validated; invalid inputs raiseInconclusiveMatchErrorso the condition does not match. — Thanks @dmarticus!v7.15.2Compare Source
Patch changes
v7.15.1Compare Source
Patch changes
v7.15.0Compare Source
Minor changes
v7.14.2Compare Source
Patch changes
v7.14.1Compare Source
Patch changes
v7.14.0Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@7.13.2...7.14.0
v7.13.2Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@7.13.1...7.13.2
v7.13.1Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@7.13.0...7.13.1
v7.13.0Compare Source
What's Changed
New Contributors
Full Changelog: PostHog/posthog-python@v7.12.0...7.13.0
v7.12.0Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.11.2...v7.12.0
v7.11.2Compare Source
What's Changed
New Contributors
Full Changelog: PostHog/posthog-python@v7.11.1...v7.11.2
v7.11.1Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.11.0...v7.11.1
v7.11.0Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.10.3...v7.11.0
v7.10.3Compare Source
What's Changed
New Contributors
Full Changelog: PostHog/posthog-python@v7.10.2...v7.10.3
v7.10.2Compare Source
What's Changed
New Contributors
Full Changelog: PostHog/posthog-python@v7.10.1...v7.10.2
v7.10.1Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.10.0...v7.10.1
v7.10.0Compare Source
What's Changed
New Contributors
Full Changelog: PostHog/posthog-python@v7.9.12...v7.10.0
v7.9.12Compare Source
What's Changed
New Contributors
Full Changelog: PostHog/posthog-python@v7.9.11...v7.9.12
v7.9.11Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.9.10...v7.9.11
v7.9.10Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.9.9...v7.9.10
v7.9.9Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.9.8...v7.9.9
v7.9.8Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.9.7...v7.9.8
v7.9.7Compare Source
What's Changed
New Contributors
Full Changelog: PostHog/posthog-python@v7.9.6...v7.9.7
v7.9.6Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.9.5...v7.9.6
v7.9.5Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.9.4...v7.9.5
v7.9.4Compare Source
What's Changed
New Contributors
Full Changelog: PostHog/posthog-python@v7.9.3...v7.9.4
v7.9.3Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.9.2...v7.9.3
v7.9.2What's Changed
sampoby @rafaeelaudibert in PostHog#398Full Changelog: PostHog/posthog-python@v7.9.0...v7.9.2
v7.9.0: 7.9.0Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.8.6...v7.9.0
v7.8.6: 7.8.6Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.8.5...v7.8.6
v7.8.5: 7.8.5Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.8.4...v7.8.5
v7.8.4: 7.8.4Compare Source
What's Changed
Full Changelog: PostHog/posthog-python@v7.8.3...v7.8.4
v7.8.3: 7.8.3Compare Source
What's Changed
Configuration
📅 Schedule: (in timezone US/Eastern)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.