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

Refactor telemetry usage flow #7522

Merged
merged 4 commits into from
Jun 30, 2023
Merged

Refactor telemetry usage flow #7522

merged 4 commits into from
Jun 30, 2023

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jun 29, 2023

Changes

  • Use telemetry singleton everywhere.
  • Refactor how tests disable telemetry.

We currently have code that passes it through several functions, because tests can then pass a telemetry stub to disable telemetry. I think it's simpler to set process.env.ASTRO_TELEMETRY_DISABLED = true instead to disable this so we don't leak the test implementation details.

Testing

Tested manually.

Docs

n/a.

@bluwy bluwy requested a review from a team as a code owner June 29, 2023 14:08
@changeset-bot
Copy link

changeset-bot bot commented Jun 29, 2023

⚠️ No Changeset found

Latest commit: 90e5da4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@bluwy bluwy changed the title Refactor environment telemetry flow Refactor telemetry usage flow Jun 29, 2023
@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jun 29, 2023
@@ -1375,7 +1375,6 @@ export interface AstroSettings {
tsConfig: TsConfigJson | undefined;
tsConfigPath: string | undefined;
watchFiles: string[];
forceDisableTelemetry: boolean;
Copy link
Member Author

@bluwy bluwy Jun 29, 2023

Choose a reason for hiding this comment

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

For the code review, you may notice disableTelemetry, forceDisableTelemtry, etc gets removed. I found these options only exists for tests to pass a value.

I removed it to simplify the code and rely on process.env.ASTRO_TELEMETRY_DISABLED = true instead.

@@ -32,7 +32,6 @@ export function createDevelopmentEnvironment(
site: settings.config.site,
ssr: isServerLikeOutput(settings.config),
streaming: true,
telemetry: Boolean(settings.forceDisableTelemetry),
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: There's a bug here before. This should be telemetry: !settings.forceDisableTelemetry. Luckily we aren't recording any telemetry in the tests now that affects this.

Comment on lines +25 to +26
// Disable telemetry when running tests
process.env.ASTRO_TELEMETRY_DISABLED = true;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is where I disable the telemetry. It should affect other integration tests as they import this file too.

container = await createContainer({ root, disableTelemetry: true });
container = await createContainer({ root });
Copy link
Member Author

Choose a reason for hiding this comment

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

For unit tests, I didn't disable telemetry because the only way is to set it through the npm script command, which is a bit ugly.

But:

  1. Our unit tests currently don't trigger any telemetry record
  2. Unit tests probably shouldn't trigger any telemetry at the first place.
  3. Tests run more often in CI than locally, and CI has it disabled.

So I think it's fine 😬

Copy link
Member

Choose a reason for hiding this comment

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

How do we discover if the unit tests will start triggering telemetry events?

Copy link
Member Author

@bluwy bluwy Jun 29, 2023

Choose a reason for hiding this comment

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

I don't know 😄 Currently I do a global search for .record and .notify, and there's only a few places used and I know they are not unit-testable.

I wouldn't mind adding a flag to the npm script to disable it completely if you prefer too.

@bluwy bluwy merged commit fcba0f0 into main Jun 30, 2023
@bluwy bluwy deleted the refactor-telemetry branch June 30, 2023 09:28
matthewp pushed a commit that referenced this pull request Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants