Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINTENANCE] Add wrapper for posthog analytics as well as an initial event #8977

Merged
merged 17 commits into from
Nov 30, 2023

Conversation

wookasz
Copy link
Contributor

@wookasz wookasz commented Nov 17, 2023

Add basic analytics framework and use it in a single "data_context.initialized" event

  • Description of PR changes above includes a link to an existing GitHub issue
  • PR title is prefixed with one of: [BUGFIX], [FEATURE], [DOCS], [MAINTENANCE], [CONTRIB]
  • Code is linted - run invoke lint (uses black + ruff)
  • Appropriate tests and docs have been updated

For more information about contributing, see Contribute.

After you submit your PR, keep the page open and monitor the statuses of the various checks made by our continuous integration process at the bottom of the page. Please fix any issues that come up and reach out on Slack if you need help. Thanks for contributing!

Copy link

netlify bot commented Nov 17, 2023

Deploy Preview for niobium-lead-7998 canceled.

Name Link
🔨 Latest commit 96409b0
🔍 Latest deploy log https://app.netlify.com/sites/niobium-lead-7998/deploys/656786efe77a220008455731

@github-actions github-actions bot added the core label Nov 17, 2023
@ghost
Copy link

ghost commented Nov 17, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@wookasz wookasz force-pushed the m/v1-28/add-analytics branch from 75c5b08 to 4461abf Compare November 18, 2023 00:23
Copy link
Contributor

@tyler-hoffman tyler-hoffman left a comment

Choose a reason for hiding this comment

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

Left some thoughts on the event.action stuff.

I think we should get some basic testing in place on this - does initializing the posthog config actually work? Does submit capture what it looks like we capture? But I won't block the merge on that.

Seems like this should be fairly ergonomic!



class Config(GenericModel):
organization_id: UUID = UUID("00000000-0000-0000-0000-000000000000")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a fake UUID better than None? If so, should/could we make it a named constant e.g. DUMMY_UUID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Tetris preferred dummies in the past

def __post_init__(self):
allowed_actions = self.get_allowed_actions()
if (
allowed_actions is not None
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this protection isn't really protecting us from much; subclasses have to opt in to using it, and then the subclass defines both its action and that the action is allowed. Maybe there are cases I'm missing though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tyler-hoffman in the case of this specific Event, there was only one Action that can be associated with it and to make using the event a bit easier, I set it in the ctor. However, there's another, more general pattern here. For example, a CheckpointEvent may support multiple actions, e.g. checkpoint.created, checkpoint.updated, checkpoint.deleted.

The use of allowed_actions become clearer once we add code to generate an event schema file for use in our analytics pipelines.

_allowed_actions: ClassVar[List[Action]] = [DATA_CONTEXT_INITIALIZED]

def __init__(self):
super().__init__(action=self.action)
Copy link
Contributor

Choose a reason for hiding this comment

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

The flow here feels off to me. This and the parent class both define an action field, and we read this during init and pass it to the parent, which under the hood assigns it to self.action again. I would remove line 8 and just call super().__init__(action=DATA_CONTEXT_INITIALIZED)

@wookasz wookasz added this pull request to the merge queue Nov 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Nov 29, 2023
@wookasz wookasz added this pull request to the merge queue Nov 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Nov 29, 2023
@wookasz wookasz added this pull request to the merge queue Nov 30, 2023
Merged via the queue into develop with commit 26eac90 Nov 30, 2023
58 checks passed
@wookasz wookasz deleted the m/v1-28/add-analytics branch November 30, 2023 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants