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

update telemetry to support more anonymized project id #3713

Merged
merged 3 commits into from
Jun 27, 2022

Conversation

FredKSchott
Copy link
Member

Changes

  • Oh no, Fred's back in the codebase!
  • Update how we calculate projectId to be more anonymous: it's now based on a commit hash instead of your git remote. This means that even if the hash is somehow reversed, it is no longer possible to identify the project.
  • I'm really excited that we figured this one out! I believe we're the first of the site builders / frameworks to do this much more secure method of anonymous project identification. More information is documented in the project-info.ts file.

Refactoring

  • Move events into Astro: these were astro-specific, and the codebase was having trouble keeping this logic up to date outside of the astro codebase (for example, types were out of date). Moving these into the astro package makes more sense, and updating old types also fixed some bugs.
  • Refactored the CLI to reduce copy-paste, especially around telemetry calls.
  • Refactored the telemetry package and added some missing docs.

Testing

  • All existing tests updated.
  • Two small new tests added just to cover the basics.
  • This package could benefit from a few more unit tests, if anyone else on the team has time.

Docs

  • Docs added in the codebase.
  • Next step is adding a telemetry page to the docs site.

@changeset-bot
Copy link

changeset-bot bot commented Jun 25, 2022

🦋 Changeset detected

Latest commit: 58cf55d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
astro Patch
@astrojs/telemetry Minor
@e2e/astro-component Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jun 25, 2022
const packages = flags._.slice(3) as string[];
telemetry.record(
event.eventCliSession({
astroVersion: process.env.PACKAGE_VERSION ?? '',
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 isn't needed, since astroVersion is passed to the AstroTelemetry constructor above.

viteVersion: getViteVersion(),
nodeVersion: process.version.replace(/^v?/, ''),
configKeys: userConfig ? configKeys(userConfig, '') : undefined,
// Config Values
config: configValues,
flags: cliFlags,
// Optional integrations
optionalIntegrations: userConfig?.integrations?.length - integrations?.length,
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 was added as a "nice-to-have" in a PR that was fixing a different bug, but I don't think this is actually valuable to us so I removed it.

@@ -108,7 +107,7 @@ export function eventCliSession(
: undefined,
markdown: userConfig?.markdown
? {
mode: userConfig?.markdown?.mode,
Copy link
Member Author

Choose a reason for hiding this comment

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

mode is no longer supported but the types were out of date, so this wasn't caught. Removed this and added drafts instead.

export interface AstroTelemetryOptions {
version: string;
}
import { getProjectInfo, ProjectInfo } from './project-info.js';
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: All changes in this file are from refactoring and cleanup and small bug fixing. Lots of little things tackled, but the meat of the change (the new project ID) lives in project-info.js.

return fetch(ASTRO_TELEMETRY_ENDPOINT, {
method: 'POST',
body: JSON.stringify(body),
headers: { 'content-type': 'application/json' },
})
.catch(noop)
Copy link
Member Author

@FredKSchott FredKSchott Jun 25, 2022

Choose a reason for hiding this comment

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

moved this post handling logic into the call telemetry/src/index.ts

@matthewp
Copy link
Contributor

Need a changeset

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Overall I'm EXTREMELY happy with this update! Just had a few comments but nothing blocking.

packages/telemetry/src/project-info.ts Outdated Show resolved Hide resolved
packages/telemetry/src/project-info.ts Show resolved Hide resolved
packages/telemetry/src/system-info.ts Show resolved Hide resolved
packages/telemetry/src/project-id.ts Show resolved Hide resolved
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

LGTM!

@FredKSchott FredKSchott merged commit ebd7e7a into main Jun 27, 2022
@FredKSchott FredKSchott deleted the telemetry-update branch June 27, 2022 21:16
@astrobot-houston astrobot-houston mentioned this pull request Jun 27, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* update telemetry to support more anonymized project id

* Create strange-laws-kick.md

* respond to nate feedback
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.

3 participants