Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Add v2 telemetry infrastructure to browser extensions and native inte…#63458

Merged
dadlerj merged 6 commits into
mainfrom
v2t-bext
Jul 3, 2024
Merged

Add v2 telemetry infrastructure to browser extensions and native inte…#63458
dadlerj merged 6 commits into
mainfrom
v2t-bext

Conversation

@dadlerj

@dadlerj dadlerj commented Jun 24, 2024

Copy link
Copy Markdown
Member

…grations

This PR adds v2t telemetry infrastructure to the Sourcegraph browser extensions and native integrations code base.

Test plan

Changelog

@dadlerj dadlerj requested a review from bobheadxi June 24, 2024 23:50
@cla-bot cla-bot Bot added the cla-signed label Jun 24, 2024
@dadlerj dadlerj removed the request for review from bobheadxi June 25, 2024 04:16
import type { TelemetryEventInput, TelemetryExporter } from '@sourcegraph/telemetry'

// todo(dan) update with new recordeventresult type?
import type { logEventResult } from '../../graphql-operations'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Dumb question... the recordEvents mutation always returns alwaysNil. Do I have to go generate a new GQL typing for this specific mutation return value? Or is there some default alwaysNilResult type I can use instead?

I'm not really sure if this question makes sense but hopefully it does 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it really matters, since we don't make use of anything from the results anyway

Comment thread client/browser/src/shared/telemetry/gqlTelemetryExporter.ts
return isFirefox() ? 'firefox-extension' : 'chrome-extension'
}

export function getTelemetryClientName(): string {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I distinguish between "native integrations" (i.e., those with a .integration suffix) and "browser extensions" (.browserExtension). I could be convinced to change this if you have any suggestions @bobheadxi

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see anything wrong with this, if they're meaningfully different clients that you want to be able to distinguish in telemetry 😁 Naming scheme aligning with feature/action is also nice

@dadlerj dadlerj requested a review from bobheadxi June 25, 2024 16:44
@dadlerj dadlerj marked this pull request as ready for review June 25, 2024 16:45
@dadlerj dadlerj requested a review from vovakulikov June 25, 2024 16:45
@dadlerj

dadlerj commented Jun 25, 2024

Copy link
Copy Markdown
Member Author

@vovakulikov I tagged you on this because you have v2t context. But if anyone else (I see Felix and Valery were suggested by GitHub) is better equipped to review the bext code, feel free to tag them in instead!

@bobheadxi bobheadxi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure I have the required expertise to approve the setup/teardown/etc but overall LGTM 😁

@vovakulikov vovakulikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No major requests, left a few comments.


useEffect(
() => () => {
if (telemetryRecorder !== noOpTelemetryRecorder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@dadlerj why do we need this conditional unsubscribe? it looks like this check will work when we previously had noOpTelemetryRecorder and now we have a real one (so we're turning on telemetry I guess) and we call unsubscribe on the real telemetryRecorder

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was giving me an error since noOpTelemetryRecorder doesn't have an unsubscribe() method. The other solution here would be to add a no-op unsubscribe to noOpTelemetryRecorder, I suppose. Would that be better here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh I missed that this is an unsub function for useEffect, in this case it's ok to have this, but in general yeah, I think if noOpTelemetryRecorder implements the same interface and common recorder it should have unsub method as well to reduce checks like this here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this specific case, this is a little bit hard to do, since I'm importing a pre-existing factory class (NoOpTelemetryRecorderProvider) that generates the noOpTelemetryRecorder. So in order to add an unsubscribe method, I'd have to override both of those classes. I'm going to go ahead and merge this as-is and accept the awkwardness here, if that's alright, just to avoid adding a bunch of extra boilerplate... Feel free to DM me if you think it would be beneficial to do that!

Comment thread client/browser/src/shared/telemetry/gqlTelemetryExporter.ts
@dadlerj dadlerj merged commit 4c824b4 into main Jul 3, 2024
@dadlerj dadlerj deleted the v2t-bext branch July 3, 2024 23:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants