Skip to content

chore: record technical/interaction telemetry using glean#99

Merged
LeoMcA merged 9 commits intomainfrom
glean
Apr 10, 2026
Merged

chore: record technical/interaction telemetry using glean#99
LeoMcA merged 9 commits intomainfrom
glean

Conversation

@LeoMcA
Copy link
Copy Markdown
Member

@LeoMcA LeoMcA commented Mar 2, 2026

@LeoMcA LeoMcA marked this pull request as ready for review April 8, 2026 10:59
@LeoMcA LeoMcA requested review from a team and mdn-bot as code owners April 8, 2026 10:59
@LeoMcA LeoMcA requested a review from caugner April 8, 2026 10:59
Copy link
Copy Markdown
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

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

Initial pass with mostly nits. I'll approve after another review round.

Comment thread glean/generated/error.js
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.

[nit] Do these generated files need to be checked in?

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.

Not checking them in means adding python as a runtime dependency, and I'd like to avoid that

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.

Are you saying npm run glean:generate requires Python? I don't recall this from Yari.

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.

Comment thread tools/get-compat.js
if (res.status === 404) {
throw new NonSentryError(
`Error: We couldn't find "${key}" in the Browser Compatibility Data.`,
"404",
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.

[nit] Should this error be more specific?

Suggested change
"404",
"compat_404",

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.

No need: this string becomes silent_error.reason and the tool name is automatically added to silent_error.tool

Comment thread tools/get-doc.js
if (!res.ok) {
if (res.status === 404) {
throw new NonSentryError(`Error: We couldn't find ${path}`);
throw new NonSentryError(`Error: We couldn't find ${path}`, "404");
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.

dito

Suggested change
throw new NonSentryError(`Error: We couldn't find ${path}`, "404");
throw new NonSentryError(`Error: We couldn't find ${path}`, "doc_404");

Comment thread tools/search.js
Comment on lines 27 to 30
if (!res.ok) {
throw new Error(
`${res.status}: ${res.statusText} for "${query}", perhaps try again.`,
);
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.

[nit] Should this be recorded as search_${res.status}?

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 string ends up displayed to the user, so no; and we don't submit it to glean, it's captured by Sentry (because our Search API really ought not to be erroring out!)

Comment thread tools/search.js
Comment on lines 34 to 56
const searchResponse = await res.json();

/** @type {(SearchDocument | Doc)[]} */
const docs = await Promise.all(
searchResponse.documents.map(async (searchDoc) => {
const { mdn_url } = searchDoc;
const metadataUrl = new URL(
mdn_url + "/metadata.json",
"https://developer.mozilla.org",
);
try {
const metadataRes = await fetch(metadataUrl);
if (!metadataRes.ok) {
return searchDoc;
}
/** @type {Doc} */
const doc = await metadataRes.json();
return doc;
} catch {
return searchDoc;
}
}),
);
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.

[nit] Would an unexpectedly invalid search response crash the MCP server? If so, should this be caught, and recorded as search_invalid_response or similar?

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.

It shouldn't crash the server, just error out on that request, and Sentry would alert us

Comment thread package.json
"test": "node --test --experimental-test-coverage --test-coverage-lines 100 --test-coverage-exclude 'test/**/*' 'test/**/*.test.js'",
"test:watch": "node --test --watch 'test/**/*.test.js'"
"test:watch": "node --test --watch 'test/**/*.test.js'",
"glean:generate": "glean translate glean/metrics.yml -f javascript -o glean/generated/ && glean translate glean/metrics.yml -f typescript -o glean/generated/ && sed -i 's/ DO NOT COMMIT\\.//g' glean/generated/*"
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.

[nit] If not checked in, this could run via postinstall.

Comment thread README.md

As this MCP is experimental it may be withdrawn at any time, in particular, the URL will change before it becomes production ready.

To opt out of first-party analytics, send the `X-Moz-1st-Party-Data-Opt-Out: 1` header along with requests to the MCP.
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.

[nit] Maybe add a quick explanation of what the analytics is used for?

Comment thread tsconfig.json
@@ -10,6 +10,18 @@
"moduleResolution": "nodenext",
// fix for badly-formed types in dependencies:
"skipLibCheck": true,
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.

[nit] I guess this cannot be set to false due to some upstream issues?

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.

Yeah, on my todo list to attempt to turn it off and fix any errors

Comment thread tsconfig.json
"moduleResolution": "nodenext",
// fix for badly-formed types in dependencies:
"skipLibCheck": true,
// fix badly defined imports:
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.

[nit] Can this be fixed upstream, and if so, is there a bug to link 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.

Probably, but we have to be on an old release of glean for it to support server-side pings, so I'm not sure it's worth it (there'd need to be a backport).

@LeoMcA LeoMcA enabled auto-merge (squash) April 10, 2026 11:10
@LeoMcA LeoMcA merged commit 73463ad into main Apr 10, 2026
3 checks passed
@LeoMcA LeoMcA deleted the glean branch April 10, 2026 11:11
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.

Record telemetry around usage

3 participants