Skip to content

feat: add PostHog telemetry events for SSO, App Connection, Secret Rotation V2, and Gateway#5731

Merged
0xArshdeep merged 8 commits intomainfrom
devin/1773712232-add-telemetry-events
Mar 17, 2026
Merged

feat: add PostHog telemetry events for SSO, App Connection, Secret Rotation V2, and Gateway#5731
0xArshdeep merged 8 commits intomainfrom
devin/1773712232-add-telemetry-events

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot commented Mar 17, 2026

Context

Adds PostHog telemetry events for four feature areas that previously had no usage tracking:

  • SSO Configuration (SSO Configured) — tracks SAML, OIDC, and LDAP config creation and updates, with provider and action properties
  • App Connections (App Connection Created / App Connection Deleted) — tracks connection lifecycle with app (typed as AppConnection enum) and method properties
  • Secret Rotation V2 (Secret Rotation V2 Created / Deleted / Executed) — tracks rotation lifecycle with type (typed as SecretRotation enum), projectId, environment, and secretPath
  • Gateway (Gateway Cert Exchanged) — tracks gateway certificate exchange via the exchange-cert endpoint

All events follow the existing fire-and-forget pattern (void ... .catch((err) => logger.error(...))). All events pass organizationId at the top level (sourced from req.permission.orgId) for proper org-level grouping in PostHog.

Updates since last revision

Addressed all review feedback (Devin Review + Greptile + human reviewer) across multiple rounds:

  • Replaced all empty .catch(() => {}) blocks with .catch((err) => logger.error(err, "...")) across all 6 router files (12 catch blocks) so telemetry failures are logged instead of silently swallowed
  • Added import { logger } from "@app/lib/logger" to the 4 files that didn't already have it (gateway-router, oidc-router, secret-rotation-v2-endpoints, app-connection-endpoints)
  • Added organizationId: req.permission.orgId to all three Secret Rotation V2 events for proper org-level PostHog grouping
  • Removed redundant orgId from properties across SSO, App Connection, and Gateway events (org association is handled by the top-level organizationId field)
  • Renamed gatewayId to certificateSerialNumber in the Gateway event to clarify it holds a TLS cert serial number, not a DB gateway ID
  • Renamed event from GatewayCreated to GatewayCertExchanged since exchange-cert fires on both first-time provisioning and cert renewals
  • Removed if (authProvider) guard on SAML update handler — now always fires telemetry with authProvider ?? "saml" fallback, consistent with LDAP/OIDC update handlers
  • Changed app property type from string to AppConnection enum in TAppConnectionCreatedEvent and TAppConnectionDeletedEvent for stronger typing
  • Added environment and secretPath to SecretRotationV2Deleted and SecretRotationV2Executed events (sourced from secretRotation.environment.slug and secretRotation.folder.path) for consistency with the Created event
  • Changed all SSO telemetry events (LDAP, OIDC, SAML — both create and update) to use req.permission.orgId instead of req.body.organizationId to prevent spoofed org attribution
  • Changed type property in all three Secret Rotation V2 event types from string to SecretRotation enum for compile-time safety
  • Fixed import sort order in telemetry-types.ts to satisfy simple-import-sort/imports lint rule

Items for human reviewer attention

  • Gateway uses certificateSerialNumber: The DB gateway ID is not returned by exchangeAllocatedRelayAddress. If correlating telemetry events with DB records is important, the service would need to be updated to also return the gateway ID.
  • SAML update fallback: When authProvider is not in the PATCH body, the telemetry event uses "saml" as the provider value. Verify this default is acceptable.
  • method as string cast in app-connection-endpoints.ts: The generic method parameter is cast to string for the telemetry properties type. This is safe but worth a glance.
  • Deleted/Executed rotation events access nested fields: secretRotation.environment.slug and secretRotation.folder.path are used — verify these are always populated on the object returned by deleteSecretRotation and rotateSecretRotation.

Steps to verify the change

  1. Confirm new enum values and type definitions in telemetry-types.ts are correctly typed (including AppConnection and SecretRotation enum usage)
  2. Verify each router file has the telemetry call placed after the service call succeeds and (where applicable) after the audit log write
  3. Verify all events pass organizationId: req.permission.orgId at the top level (not inside properties, and not from req.body)
  4. Verify all .catch() blocks use logger.error with a descriptive message
  5. Run npx tsc --noEmit in backend/ to confirm no type errors

Type

  • Fix
  • Feature
  • Improvement
  • Breaking
  • Docs
  • Chore

Checklist

Link to Devin session: https://app.devin.ai/sessions/ff644e7024c8430f847cc431a8ef22b0
Requested by: @0xArshdeep


Open with Devin

…tation V2, and Gateway

- Add new PostHogEventTypes: SSOConfigured, AppConnectionCreated, AppConnectionDeleted, SecretRotationV2Created, SecretRotationV2Deleted, SecretRotationV2Executed, GatewayCreated
- Add corresponding TypeScript type definitions for each event
- Instrument SAML/OIDC/LDAP routers with SSO telemetry on create and update
- Instrument app-connection-endpoints with create/delete telemetry
- Instrument secret-rotation-v2-endpoints with create/delete/execute telemetry
- Instrument gateway router exchange-cert handler with creation telemetry
- All events follow existing fire-and-forget pattern

Co-Authored-By: arsh <[email protected]>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@maidul98
Copy link
Copy Markdown
Collaborator

maidul98 commented Mar 17, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

devin-ai-integration[bot]

This comment was marked as resolved.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 17, 2026

Greptile Summary

This PR adds PostHog telemetry instrumentation to four previously untracked feature areas — SSO (SAML/OIDC/LDAP), App Connections, Secret Rotation V2, and Gateway — following the existing fire-and-forget pattern used throughout the codebase. All previous review feedback has been addressed: organizationId is sourced from req.permission.orgId on every event, enum types (AppConnection, SecretRotation) are used instead of loose string types where applicable, the Gateway event was renamed to GatewayCertExchanged to accurately reflect renewals vs. provisioning, and environment/secretPath were added to the Deleted and Executed rotation events.

Key observations:

  • All 7 new event types are correctly wired into the TPostHogEvent discriminated union and the PostHogEventTypes enum.
  • secretRotation.environment.slug and secretRotation.folder.path are safe to access in the Deleted and Executed handlers — the DAL's expandSecretRotation always populates both fields via join, confirmed by reviewing the DAL implementation.
  • The provider field in TSSOConfiguredEvent accepts values from SamlProviders enum (for SAML) and plain string literals for LDAP/OIDC — a union type would improve compile-time safety.
  • The SecretRotationV2Created event reads environment/secretPath from req.body while the Deleted/Executed events use the DB-confirmed values — functionally equivalent but inconsistent in approach.

Confidence Score: 5/5

  • This PR is safe to merge — it only adds fire-and-forget telemetry calls after successful service operations, with no risk to core functionality.
  • All telemetry events fire after the primary service call succeeds and use the fire-and-forget pattern (void … .catch(() => {})), so any telemetry failure cannot affect the API response. All previous review feedback has been addressed. The two remaining suggestions (provider union type, environment source consistency) are style-level improvements, not functional issues.
  • No files require special attention — all changes are additive telemetry instrumentation.

Important Files Changed

Filename Overview
backend/src/services/telemetry/telemetry-types.ts Adds 7 new PostHog event types (SSO, App Connections x2, Secret Rotation V2 x3, Gateway) with appropriate enum-typed properties (AppConnection, SecretRotation). Union type and enum are properly extended. Import sort order is correct.
backend/src/ee/routes/v1/saml-router.ts Adds telemetry for SAML create/update. Both handlers await the service call and fire telemetry after. The update handler correctly falls back to "saml" when authProvider is absent from the PATCH body. authProvider is required on create (z.nativeEnum(SamlProviders)), so no undefined risk there.
backend/src/ee/routes/v1/ldap-router.ts Adds telemetry for LDAP create/update using req.permission.orgId for organizationId. Both events use hardcoded provider: "ldap" and the correct action string. Fire-and-forget pattern is consistent with the rest of the codebase.
backend/src/ee/routes/v1/oidc-router.ts Adds telemetry for OIDC update (~line 279) and create (~line 416). Both use req.permission.orgId and hardcoded provider: "oidc". Events are placed correctly after service calls succeed.
backend/src/ee/routes/v2/secret-rotation-v2-routers/secret-rotation-v2-endpoints.ts Adds telemetry for SecretRotationV2 Created/Deleted/Executed. All three events include organizationId, environment, and secretPath. The Deleted and Executed events correctly access secretRotation.environment.slug and secretRotation.folder.path, which are always populated by the DAL's expandSecretRotation helper via non-null assertion.
backend/src/server/routes/v1/app-connection-routers/app-connection-endpoints.ts Adds telemetry for AppConnectionCreated and AppConnectionDeleted. Created event includes method (cast as string from generic I["method"]), app (AppConnection enum), and appConnectionId. Deleted event omits method since it's unavailable in the delete service call's return signature. Both events correctly use req.permission.orgId.
backend/src/ee/routes/v1/gateway-router.ts Adds GatewayCertExchanged telemetry after exchangeAllocatedRelayAddress succeeds. certificateSerialNumber (TLS cert serial) and identityId are included. Event name correctly reflects that this fires on both provisioning and renewals.

Last reviewed commit: 5d21b7c

greptile-apps[bot]

This comment was marked as resolved.

devin-ai-integration bot and others added 2 commits March 17, 2026 02:26
… remove redundant orgId, rename gatewayId

Co-Authored-By: arsh <[email protected]>
…Exchanged, remove SAML update guard

Co-Authored-By: arsh <[email protected]>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

All Greptile comments have been addressed in commits 2da6f50 and d2c6829:

  1. Missing organizationId on rotation events (Comment 10) — Added organizationId: req.permission.orgId to all three Secret Rotation V2 events
  2. Redundant orgId in properties (Comment 11) — Removed orgId from properties of SSO, App Connection, and Gateway events
  3. gatewayId contains cert serial number (Comment 8) — Renamed to certificateSerialNumber
  4. GatewayCreated fires on every cert exchange (Comment 9) — Renamed event to GatewayCertExchanged to accurately reflect semantics
  5. SAML update telemetry skipped (Comment 12) — Removed if (authProvider) guard, using authProvider ?? "saml" fallback

@0xArshdeep
Copy link
Copy Markdown
Contributor

@greptileai

greptile-apps[bot]

This comment was marked as resolved.

@0xArshdeep
Copy link
Copy Markdown
Contributor

@greptileai

@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

Addressed the latest Greptile comment in commit 8fdada8: app property in TAppConnectionCreatedEvent and TAppConnectionDeletedEvent now uses the AppConnection enum type instead of string, with the import added to telemetry-types.ts.

greptile-apps[bot]

This comment was marked as resolved.

@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

Addressed in 2ff8945SecretRotationV2Deleted and SecretRotationV2Executed events now include environment (from secretRotation.environment.slug) and secretPath (from secretRotation.folder.path), consistent with SecretRotationV2Created. Type definitions updated accordingly.

@0xArshdeep
Copy link
Copy Markdown
Contributor

@greptileai

greptile-apps[bot]

This comment was marked as resolved.

@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

Addressed in f0940de:

  1. Comment 24 (P1): Changed all SSO telemetry events (LDAP create/update, OIDC create/update, SAML create/update) to use req.permission.orgId instead of req.body.organizationId — consistent with Gateway, App Connection, and Secret Rotation V2 events.

  2. Comment 25 (P2): Changed type property in TSecretRotationV2CreatedEvent, TSecretRotationV2DeletedEvent, and TSecretRotationV2ExecutedEvent from string to SecretRotation enum — consistent with app: AppConnection pattern in App Connection events.

@0xArshdeep
Copy link
Copy Markdown
Contributor

@greptileai

@0xArshdeep 0xArshdeep merged commit cc2082a into main Mar 17, 2026
12 checks passed
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.

3 participants