Repository navigation
feat: CLI - send invitation analytics events from zitadel invitation create and cancel - #3177
Conversation
Restores the invitation analytics on top of the list and cancel-flow branch, which now merges first: trackEvent, invitation_created and invitation_cancelled, the catalog, the ADR 086 amendment and their tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: efd6a58 The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
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 |
…tation-analytics-events
There was a problem hiding this comment.
🟡 Changes recommended
Cancellation can incorrectly emit telemetry if an invitee declines during confirmation, and create/replacement telemetry lacks tests for successful emission and required suppression paths.
2 open issues
What changed in this PR
Adds invitation analytics to the CLI, building on #3176’s cancellation flow and implementing the CLI portion of #2859.
Changes:
- Emits create and cancellation events with role and journey ID through the existing telemetry consent gate.
- Adds cancellation, shared telemetry, and catalog checks.
- Updates analytics documentation, CLI guidance, and release notes; console events remain planned.
| File | Description |
|---|---|
docs/product-analytics-events.yaml |
Registers invitation events and journey properties. |
docs/adrs/README.md |
Summarizes invitation amendments. |
docs/adrs/086-invitations.md |
Defines cancellation analytics semantics. |
apps/docs/content/docs/reference/cli/telemetry.mdx |
Documents invitation events and privacy limits. |
apps/cli/tests/unit/lib/telemetry/catalog.test.ts |
Checks product-event properties against the catalog. |
apps/cli/tests/unit/lib/oclif/base-telemetry.test.ts |
Tests shared event context and consent gating. |
apps/cli/tests/unit/cli/commands/invitation/cancel.test.ts |
Tests cancellation emission and suppression paths. |
apps/cli/src/lib/oclif/base.ts |
Adds the shared product-event helper. |
apps/cli/src/lib/backend/services/invitation.ts |
Maps invitation grants to analytics role values. |
apps/cli/src/lib/backend/index.ts |
Exports the grant helper. |
apps/cli/src/cli/commands/invitation/create.ts |
Emits creation analytics after API success. |
apps/cli/src/cli/commands/invitation/cancel.ts |
Emits cancellation analytics for pending invitations. |
apps/cli/AGENTS.md |
Clarifies when commands send product events. |
.changeset/cli-invitation-analytics.md |
Adds the CLI release note. |
Review effort: Balanced
…tation-analytics-events # Conflicts: # apps/cli/tests/unit/cli/commands/invitation/cancel.test.ts
invitation_created goes out once the API creates or replaces the invitation, with the role and journey it returned, and not when the create fails, on a dry run or when the person says no. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The release note incorrectly claims all non-pending invitations are refused, contradicting the command behavior and test showing rejected invitations can be removed.
1 open issue
2 resolved since last review
Review effort: Balanced
…tation-analytics-events
…changeset Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tation-analytics-events
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mridang
left a comment
There was a problem hiding this comment.
Looked at this as a fresh read of the diff against the repo and its AGENTS.md files. The event design matches the ADR, the consent gate is respected, and CI is green. Two things outside the diff first: the description says "Closes #2859 for the CLI", but GitHub will close #2859 on merge while the console events and its Mixpanel sink remain under it, so that line should be Refs #2859. The inline comments are mostly about how the events are tested.
|
|
||
| /** Watches the product events the command sends. */ | ||
| function trackedEvents() { | ||
| return vi.spyOn( |
There was a problem hiding this comment.
These tests spy on BaseCommand.prototype.trackEvent through an as unknown as cast, so they prove that a protected method was called, not that the event reached the telemetry client with the header, the consent gate and the right properties. I would drop the spy and inject a recording telemetry client, as base-telemetry.test.ts already does with RecordingTelemetry, then assert the events that client received. The five near-identical it bodies would also collapse into one it.for table over the scenarios (pending, declined, failed, dry run, said no). The same applies to create.test.ts.
|
|
||
| /** Watches the product events the command sends. */ | ||
| function trackedEvents() { | ||
| return vi.spyOn( |
There was a problem hiding this comment.
Same spy as in cancel.test.ts: it asserts the call to the protected method, not what the telemetry client received. Reuse one recording client (a helper beside base-telemetry.test.ts's RecordingTelemetry) for both commands.
| await unlocked.cancel(invitation.id); | ||
| // A declined journey already ended with invitation_rejected. | ||
| if (invitation.status === "pending") { | ||
| this.trackEvent(INVITATION_CANCELLED, { |
There was a problem hiding this comment.
The event is only tested for a cancel that names an id. A bare cancel takes its invitation from the picker, so its role and invitation_journey_id come from a list item rather than from get. Nothing proves the list response carries journey_id and that this path sends the event. A test for the picked path closes it.
| * @param invitation - The invitation. | ||
| * @returns The type and role combined. | ||
| */ | ||
| export function invitationGrant(invitation: Invitation): string { |
There was a problem hiding this comment.
invitationGrant is new exported logic with two branches and no unit test: invitation.test.ts is untouched, and the only value any test sees is project_viewer through the create and cancel tests. A table in tests/unit/lib/backend/services/invitation.test.ts over viewer, editor and admin pins the strings the catalog lists (project_viewer, project_editor, project_admin), which are the whole point of the property. The team_member branch cannot be reached by any test today; that is worth saying in the TSDoc so nobody trusts it.
| * context every CLI event carries. Only for an event an ADR names; a | ||
| * command's own facts are dimensions ({@link recordTelemetry}). | ||
| */ | ||
| protected trackEvent(event: string, properties: Properties): void { |
There was a problem hiding this comment.
event is a plain string, so a typo in a new trackEvent call compiles and is only caught by the catalog test's source scan, which throws for any name that is neither a literal nor a same-file const. Lifecycle events are constants exported from command-telemetry.ts. Putting the two product-event names there (or typing event as a union of them) makes the compiler the first gate and the catalog test the second.
| }); | ||
|
|
||
| describe("CLI telemetry against the catalog", () => { | ||
| it("sends exactly the properties the catalog lists on each product event", async () => { |
There was a problem hiding this comment.
This checks every trackEvent call against the catalog, but not the other direction: an event the catalog lists as emitted for the CLI that no command sends passes silently, so a removed trackEvent call leaves a false emitted entry. Assert that each emitted non-lifecycle CLI event has at least one trackedEvents() entry.
|
|
||
| `cli_command_started`, `cli_command_completed` and `cli_command_failed` fire | ||
| from `BaseCommand` for every command. Add a dimension rather than an event: | ||
| from `BaseCommand` for every command. Send a product event of its own |
There was a problem hiding this comment.
apps/cli/AGENTS.md (Telemetry) says "Send nothing that identifies a person, machine or credential ... Allowed values are enums, booleans, counts and versions." invitation_journey_id is an opaque random id, which is none of those, and this edit permits product events without amending that rule. The ADR argues the id is a correlation id and not a resource id, which is a fair exception, but the rule should say so (one line naming invitation_journey_id), or a later reviewer will read this PR as a violation. The paragraph also sits under "Adding a dimension", so a reader looking for product events will not find it there.
| - The cancel answers `204` with no body, so `zitadel invitation cancel | ||
| <invitation_id>` reads the invitation before it asks to confirm. The | ||
| question names who the invitation is for and its role, and the event takes | ||
| its role and journey from that read. A cancel with no id picks from the |
There was a problem hiding this comment.
This still says a cancel with no id "picks from the pending list". With #3176 the picker offers pending and declined invitations, and the 2026-11-13 amendment below makes a declined one cancellable. Updating the sentence keeps the amendment true once the stack lands.
mridang
left a comment
There was a problem hiding this comment.
Approving. I read the source, tests, docs, ADR and catalog changes against the repo and its AGENTS.md files, and CI is green.
What I checked and found sound: trackEvent sits behind the same consent gate as the lifecycle events, reuses commandEventProperties so the header and invocation id match, and only fires after the API confirms the create or cancel. A dry run, a declined confirmation and a failed call send nothing, and the tests cover each of those. A cancel reads the invitation first because the 204 carries no body, so the event's role and journey come from that read, and a declined invitation correctly sends nothing since its journey already ended. catalog.test.ts now holds every trackEvent call's properties to the catalog, and the catalog, the telemetry docs page and the ADR amendment agree on the two events and the invitation_journey_id property. Removing the old role and is_replace dimensions is consistent because the commands are not released yet.
Before merging, one thing outside the diff: the description says "Closes #2859 for the CLI", which GitHub will treat as a closing keyword, while the console events and its Mixpanel sink remain under that issue. Please change it to Refs #2859.
The inline comments from my earlier review stand and none blocks the merge. The ones I would pick up first are replacing the vi.spyOn calls with a recording telemetry client, a unit test table for invitationGrant, a test for the bare-cancel picker path, and updating the ADR sentence that still says a bare cancel picks from the pending list. The invitation_journey_id exception to the AGENTS allowed-values rule should also be written down so the next reader does not take it for a violation.
…tation-analytics-events
…tation-analytics-events
apps/cli/AGENTS.md now names the journey id as the one value outside enums, booleans, counts and versions, and says when a command sends a product event under the telemetry rules rather than under dimensions. The ADR 086 amendment says a bare cancel picks from pending and declined invitations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tation-analytics-events


Replaces #2932, which could not leave its stack. Depends on #3176 — merge after it.
Summary
Relates to #2859 for the CLI (ADR 086 §9). Stacked on #3176.
zitadel invitation create, including--replaces, sendsinvitation_createdonce the API confirms the create, withrole(project_viewer,project_editor,project_admin;team_memberlater) andinvitation_journey_id. It replaces therole/is_replacedimensions feat: CLI - add zitadel invitation create, list, get and cancel #2929 records.zitadel invitation cancelsendsinvitation_cancelledwith the same properties once the API confirms the cancel, per a dated amendment to ADR 086: without it a cancelled journey reads as one nobody opened. The cancel answers204with no body, so the event takes its role and journey from the invitation feat: CLI hide accepted invitations from zitadel invitation list and name the invitation before cancelling #3176 reads before confirming. A declined invitation sends none: its journey already ended withinvitation_rejected.BaseCommand.trackEventsends a product event with the header and context every CLI event carries, behind the same consent gate.product-analytics-events.yamllists the CLI's two events asemitted, the console'sinvitation_created,invitation_accepted,invitation_rejectedandinvitation_cancelledasplanned(Analytics: invitation events #2859), and theinvitation_journey_idproperty.catalog.test.tsholds everytrackEventcall's properties to the catalog.apps/cli/AGENTS.mdsay when a command sends an event of its own.Notes
[mixpanel, vercel]. The copy keeps only the eight header keys, never the journey id. Restricting it to Mixpanel would need a sink filter.🤖 Generated with Claude Code