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

feat: Implement EventTracker abstraction and Amplitude implementation #3650

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

spalmurray-codecov
Copy link
Contributor

draft

@codecov-staging
Copy link

codecov-staging bot commented Jan 10, 2025

❌ 37 Tests Failed:

Tests completed Failed Passed Skipped
1527 37 1490 0
View the top 3 failed tests by shortest run time
src/shared/utils/provider.test.ts > getProviderPullURL > return bb PR URL
Stack Traces | 0.000442s run time
AssertionError: expected undefined to be 'https://bitbucket.org/codecov/python/…' // Object.is equality

- Expected: 
"https://bitbucket..../python/pull-requests/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:142:73
src/shared/utils/provider.test.ts > getProviderPullURL > return gle PR URL
Stack Traces | 0.000447s run time
AssertionError: expected undefined to be 'https://gitlab.mycompany.org/codecov/…' // Object.is equality

- Expected: 
"https://gitlab.mycompany..../-/merge_requests/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:156:74
src/shared/utils/provider.test.ts > getProviderPullURL > return github PR URL
Stack Traces | 0.000485s run time
AssertionError: expected undefined to be 'https://github..../codecov/python/pul…' // Object.is equality

- Expected: 
"https://github..../codecov/python/pull/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:137:73

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Jan 10, 2025

❌ 37 Tests Failed:

Tests completed Failed Passed Skipped
1527 37 1490 0
View the top 3 failed tests by shortest run time
src/shared/utils/provider.test.ts > getProviderPullURL > return bb PR URL
Stack Traces | 0.000442s run time
AssertionError: expected undefined to be 'https://bitbucket.org/codecov/python/…' // Object.is equality

- Expected: 
"https://bitbucket..../python/pull-requests/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:142:73
src/shared/utils/provider.test.ts > getProviderPullURL > return gle PR URL
Stack Traces | 0.000447s run time
AssertionError: expected undefined to be 'https://gitlab.mycompany.org/codecov/…' // Object.is equality

- Expected: 
"https://gitlab.mycompany..../-/merge_requests/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:156:74
src/shared/utils/provider.test.ts > getProviderPullURL > return github PR URL
Stack Traces | 0.000485s run time
AssertionError: expected undefined to be 'https://github..../codecov/python/pul…' // Object.is equality

- Expected: 
"https://github..../codecov/python/pull/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:137:73

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

Copy link

❌ 37 Tests Failed:

Tests completed Failed Passed Skipped
1527 37 1490 0
View the top 3 failed tests by shortest run time
src/shared/utils/provider.test.ts > getProviderPullURL > return bb PR URL
Stack Traces | 0.000442s run time
AssertionError: expected undefined to be 'https://bitbucket.org/codecov/python/…' // Object.is equality

- Expected: 
"https://bitbucket..../python/pull-requests/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:142:73
src/shared/utils/provider.test.ts > getProviderPullURL > return gle PR URL
Stack Traces | 0.000447s run time
AssertionError: expected undefined to be 'https://gitlab.mycompany.org/codecov/…' // Object.is equality

- Expected: 
"https://gitlab.mycompany..../-/merge_requests/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:156:74
src/shared/utils/provider.test.ts > getProviderPullURL > return github PR URL
Stack Traces | 0.000485s run time
AssertionError: expected undefined to be 'https://github..../codecov/python/pul…' // Object.is equality

- Expected: 
"https://github..../codecov/python/pull/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:137:73

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Jan 10, 2025

❌ 37 Tests Failed:

Tests completed Failed Passed Skipped
1527 37 1490 0
View the top 3 failed tests by shortest run time
src/shared/utils/provider.test.ts > getProviderPullURL > return bb PR URL
Stack Traces | 0.000442s run time
AssertionError: expected undefined to be 'https://bitbucket.org/codecov/python/…' // Object.is equality

- Expected: 
"https://bitbucket..../python/pull-requests/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:142:73
src/shared/utils/provider.test.ts > getProviderPullURL > return gle PR URL
Stack Traces | 0.000447s run time
AssertionError: expected undefined to be 'https://gitlab.mycompany.org/codecov/…' // Object.is equality

- Expected: 
"https://gitlab.mycompany..../-/merge_requests/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:156:74
src/shared/utils/provider.test.ts > getProviderPullURL > return github PR URL
Stack Traces | 0.000485s run time
AssertionError: expected undefined to be 'https://github..../codecov/python/pul…' // Object.is equality

- Expected: 
"https://github..../codecov/python/pull/12"

+ Received: 
undefined

 ❯ .../shared/utils/provider.test.ts:137:73

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!


const AMPLITUDE_API_KEY = process.env.REACT_APP_AMPLITUDE_API_KEY

export interface EventTracker {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using an abstract class instead of an interface is a little more explicit of this Class's purpose

): void
}

class StubbedEventTracker implements EventTracker {
Copy link
Contributor

Choose a reason for hiding this comment

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

I love the idea of having a stubbed / generic event tracker instance; maybe we can throw some errors in the functions instead for some higher visibility

Additionally, pulling this out into a separate file would help reduce some cognitive load when parsing this file

}

class StubbedEventTracker implements EventTracker {
identify(_userOwnerId: string | number, _username: string): void {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Having this be a string | number seems a little smelly, is there a way around this?


export interface EventTracker {
// Identifies the user this session belongs to.
identify(userOwnerId: number | string, username: string): void
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I really like having functions utilize an object syntax for input parameters for explicit defining instead of relying on proper placement from developers

so in this case we'd have identify({userOwnerId, username}: {userOwnerId: number | string, username: string})

which would prevent a situation where someone accidentally puts the username as the first param unknowingly (since it also accepts a string)

// Adding event types this way provides type safety for event properties.
// E.g., every 'Button Clicked' event must have the buttonType property.
track(
eventType: 'Button Clicked',
Copy link
Contributor

Choose a reason for hiding this comment

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

Having a central const somewhere of "EventTypes" might help with readability

@@ -26,6 +31,11 @@ function InactiveRepo({
repo: repoName,
},
}}
onClick={() =>
eventTracker(provider, owner, repoName).track('Button Clicked', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to instantiate the event tracker somewhere as a singleton and then call track against that instance? Currently every time we want to call track we need to create a new instance of an AmplitudeEventTracker which seems a little expensive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants