Skip to content

fix(llma): use distinct_id from outer context if not provided#449

Open
ethanporcaro wants to merge 2 commits intoPostHog:masterfrom
ethanporcaro:distinct-id-context-fix
Open

fix(llma): use distinct_id from outer context if not provided#449
ethanporcaro wants to merge 2 commits intoPostHog:masterfrom
ethanporcaro:distinct-id-context-fix

Conversation

@ethanporcaro
Copy link

Related to #443

Right now, the LLM analytics wrappers accept a posthog_distinct_id parameter, but override any existing distinct_id, even if the parameter is None.

The utility functions pass

ph_client.capture(
                    distinct_id=posthog_distinct_id or posthog_trace_id,
...

However, if posthog_distinct_id is None (default) it will default to the posthog_trace_id, even if an ID exists on the outer context.

This PR modifies the logic to do the following:

  • If a custom distinct_id is passed by parameter, it is used in identify_context
  • If no context exists (meaning the above never happened, and no existing context is available), identify with the trace_id.
  • Call ph_client.capture without the distinct_id parameter, so that it uses whatever was set from the above steps.

Let me know if any changes are needed or if I should implement this differently.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@andrewm4894 andrewm4894 requested a review from a team March 3, 2026 17:23
@ethanporcaro
Copy link
Author

Some of these failed tests are passing on my machine. Do the tests set an outer distinct_id?

@ethanporcaro
Copy link
Author

Nevermind, I realize I was running them incorrectly. I think I found the issue and will push a commit soon

@ethanporcaro
Copy link
Author

Should be good to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants