Skip to content

feat: CLI - send invitation analytics events from zitadel invitation create and cancel - #3177

Merged
vitorbari merged 13 commits into
2853-cli-invitation-list-and-cancelfrom
2859-cli-invitation-analytics-events
Nov 18, 2026
Merged

vitorbari merged 13 commits into
2853-cli-invitation-list-and-cancelfrom
2859-cli-invitation-analytics-events

Conversation

@vitorbari

@vitorbari vitorbari commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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, sends invitation_created once the API confirms the create, with role (project_viewer, project_editor, project_admin; team_member later) and invitation_journey_id. It replaces the role/is_replace dimensions feat: CLI - add zitadel invitation create, list, get and cancel #2929 records.
  • zitadel invitation cancel sends invitation_cancelled with 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 answers 204 with 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 with invitation_rejected.
  • BaseCommand.trackEvent sends a product event with the header and context every CLI event carries, behind the same consent gate.
  • product-analytics-events.yaml lists the CLI's two events as emitted, the console's invitation_created, invitation_accepted, invitation_rejected and invitation_cancelled as planned (Analytics: invitation events #2859), and the invitation_journey_id property.
  • catalog.test.ts holds every trackEvent call's properties to the catalog.
  • The telemetry docs page and apps/cli/AGENTS.md say when a command sends an event of its own.

Notes

  • The Vercel sink copies every event, so the catalog lists [mixpanel, vercel]. The copy keeps only the eight header keys, never the journey id. Restricting it to Mixpanel would need a sink filter.
  • Mixpanel is paused, so nothing reaches it until its region is fixed.
  • The console events and its Mixpanel sink remain under Analytics: invitation events #2859.

🤖 Generated with Claude Code

vitorbari and others added 2 commits November 16, 2026 23:31
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>
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Nov 18, 2026 1:40pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: efd6a58

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

This PR includes changesets to release 27 packages
Name Type
@zitadel/cli Minor
@zitadel/testing Minor
@zitadel/server Minor
@zitadel/server-darwin-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-win32-x64 Minor
@zitadel/api Minor
@zitadel/components Minor
@zitadel/config Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-sveltekit Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/cloud Patch
@zitadel/client-sdk-contract Patch
@zitadel/server-sdk-contract 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

Copilot AI left a comment

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.

🟡 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

vitorbari and others added 2 commits November 17, 2026 00:02
…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>

Copilot AI left a comment

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.

🟡 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

Comment thread .changeset/cli-invitation-analytics.md Resolved
vitorbari and others added 2 commits November 17, 2026 08:05

Copilot AI left a comment

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.

🟢 Approval recommended

There are no active review issues blocking the CLI invitation analytics change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@mridang mridang left a comment

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.

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(

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.

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(

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.

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, {

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.

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 {

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.

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 {

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.

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 () => {

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.

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.

Comment thread apps/cli/AGENTS.md Outdated

`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

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.

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

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.

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 mridang left a comment

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.

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.

vitorbari and others added 2 commits November 18, 2026 12:54
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>
@vitorbari
vitorbari enabled stacked auto-merge November 18, 2026 13:40
@vitorbari
vitorbari disabled stacked auto-merge November 18, 2026 13:40
@vitorbari
vitorbari added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit fc4f245 Nov 18, 2026
17 of 21 checks passed
@vitorbari
vitorbari deleted the 2859-cli-invitation-analytics-events branch November 18, 2026 13:49
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Nov 18, 2026

This branch was successfully deployed

1 active deployment
Preview — efd6a582 Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants