👷 Make json-schemas sync reliable: authenticate API requests and format output deterministically - #4832
Conversation
`yarn json-schemas:sync` resolves the latest rum-events-format commit via an unauthenticated GitHub API call, capped at 60 requests/hour per IP. Behind a shared NAT that budget is exhausted by everyone on the same address, producing a 403 rate-limit error. Use the developer's `gh auth token` to authenticate the request (5000/hour). If `gh` is unavailable or not logged in, warn and fall back to the previous unauthenticated behavior instead of failing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 35906e8 | Docs | Datadog PR Page | Give us feedback! |
Bundles Sizes Evolution
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a947cff29d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // behind a shared NAT. Authenticate with the user's `gh` CLI token to get the 5000/hour limit. | ||
| let token = '' | ||
| try { | ||
| token = command`gh auth token`.run().trim() |
There was a problem hiding this comment.
Pin gh token lookup to github.com
issue: If a developer has GH_HOST set to a GitHub Enterprise host, gh auth token can return that host's token—the GitHub CLI manual says gh auth token chooses a default host without --hostname (https://cli.github.com/manual/gh_auth_token) and GH_HOST supplies that host (https://cli.github.com/manual/gh_help_environment). This code then sends the token to the hard-coded api.github.com URL, so yarn json-schemas:sync can fail instead of falling back and may expose the wrong token; request the token with gh auth token --hostname github.com for this GitHub.com API call.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Let's keep it simple and not rely on env variables
| }, | ||
| "devDependencies": { | ||
| "@datadog/rum-events-format": "DataDog/rum-events-format#commit=02c94b31a2676458a156ed627f3edcd87254beb7", | ||
| "@datadog/rum-events-format": "DataDog/rum-events-format#commit=eb646464de64b1296c61738d98f87bf0a84ec207", |
There was a problem hiding this comment.
Normalize unknown quota reasons before using the new schema
issue: This bump brings in a schema that enumerates _dd.profiling.quota_reason, but the SDK still forwards arbitrary backend reason strings: parseQuotaResult casts attrs.reason directly in packages/browser-rum/src/domain/profiling/quotaCheck.ts:23-24, and the existing spec covers unknown_reason in datadogProfiler.spec.ts:1184-1194. If the quota API returns a new reason, startProfilingContext attaches that value to VIEW/LONG_TASK/ACTION/VITAL events, so those events no longer validate against the schema used by our format checks; map unknown reasons to an allowed value (or update the schema) with this bump.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Let's drop the middle commit, it should work anyway
json-schema-to-typescript formats its output with whatever prettier it resolves at runtime, which differs between environments and collapsed union types onto a single line in CI, breaking the check-schemas job. Format with the repo's prettier instead so generation is deterministic and matches `prettier --check .`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
a947cff to
35906e8
Compare
Motivation
Two issues made
yarn json-schemas:syncunreliable:Rate limiting — the branch-resolution step resolves the latest
rum-events-formatcommit through an unauthenticated GitHub REST API call, capped at 60/hour per IP. Behind a shared corporate NAT that budget is consumed by everyone on the same address, so the sync fails with HTTP 403:Non-deterministic formatting —
json-schema-to-typescriptformats the generated*.types.tsfiles with whatever prettier it resolves at runtime, which differs between environments (e.g. a nested prettier left by a prior fork build locally vs. a freshly built fork in CI). In CI this collapsed union types onto a single line, so thecheck-schemasjob reported a diff against the committed (repo-prettier-formatted) files and failed.Changes
Both changes are in
scripts/json-schemas.ts:ghCLI token (authenticated limit: 5000/hour). Trygh auth token; on success attach anAuthorization: token …header (style matches the existing call inscripts/lib/gitUtils.ts). Ifghis missing or the user isn't logged in, print a warning and fall back to the previous unauthenticated behavior rather than failing. No env-var setup is required.format: false) and format the compiled output with the repo's pinned prettier (parser: 'typescript') before writing. Generation is now identical across environments and matchesprettier --check ., socheck-schemasstays green.(The PR also includes a routine
rum-events-formatschema bump produced by running the now-reliable sync end-to-end.)Test instructions
gh):ghunavailable):node scripts/check-schemas.tsexits 0.Checklist
🤖 Generated with Claude Code