feat(console): allow to configure PostHog (#9135)

# Which Problems Are Solved

The console has no information about where and how to send PostHog
events.

# How the Problems Are Solved

A PostHog API URL and token are passed through as plain text from the
Zitadel runtime config to the environment.json. By default, no values
are configured and the keys in the environment.json are omitted.

# Additional Context

- Closes https://github.com/zitadel/zitadel/issues/9070
- Complements https://github.com/zitadel/zitadel/pull/9077
This commit is contained in:
Elio Bischof
2025-01-07 15:38:13 +01:00
committed by GitHub
parent 56427cca50
commit 11d36fcd00
2 changed files with 13 additions and 2 deletions

View File

@@ -611,6 +611,9 @@ Console:
# 168h is 7 days, one week # 168h is 7 days, one week
SharedMaxAge: 168h # ZITADEL_CONSOLE_LONGCACHE_SHAREDMAXAGE SharedMaxAge: 168h # ZITADEL_CONSOLE_LONGCACHE_SHAREDMAXAGE
InstanceManagementURL: "" # ZITADEL_CONSOLE_INSTANCEMANAGEMENTURL InstanceManagementURL: "" # ZITADEL_CONSOLE_INSTANCEMANAGEMENTURL
PostHog:
URL: "" # ZITADEL_CONSOLE_POSTHOG_URL
Token: "" # ZITADEL_CONSOLE_POSTHOG_TOKEN
EncryptionKeys: EncryptionKeys:
DomainVerification: DomainVerification:

View File

@@ -28,6 +28,10 @@ type Config struct {
ShortCache middleware.CacheConfig ShortCache middleware.CacheConfig
LongCache middleware.CacheConfig LongCache middleware.CacheConfig
InstanceManagementURL string InstanceManagementURL string
PostHog struct {
Token string
URL string
}
} }
type spaHandler struct { type spaHandler struct {
@@ -117,7 +121,7 @@ func Start(config Config, externalSecure bool, issuer op.IssuerFromRequest, call
return return
} }
limited := limitingAccessInterceptor.Limit(w, r) limited := limitingAccessInterceptor.Limit(w, r)
environmentJSON, err := createEnvironmentJSON(url, issuer(r), instance.ConsoleClientID(), customerPortal, instanceMgmtURL, limited) environmentJSON, err := createEnvironmentJSON(url, issuer(r), instance.ConsoleClientID(), customerPortal, instanceMgmtURL, config.PostHog.URL, config.PostHog.Token, limited)
if err != nil { if err != nil {
http.Error(w, fmt.Sprintf("unable to marshal env for console: %v", err), http.StatusInternalServerError) http.Error(w, fmt.Sprintf("unable to marshal env for console: %v", err), http.StatusInternalServerError)
return return
@@ -150,13 +154,15 @@ func csp() *middleware.CSP {
return &csp return &csp
} }
func createEnvironmentJSON(api, issuer, clientID, customerPortal, instanceMgmtUrl string, exhausted bool) ([]byte, error) { func createEnvironmentJSON(api, issuer, clientID, customerPortal, instanceMgmtUrl, postHogURL, postHogToken string, exhausted bool) ([]byte, error) {
environment := struct { environment := struct {
API string `json:"api,omitempty"` API string `json:"api,omitempty"`
Issuer string `json:"issuer,omitempty"` Issuer string `json:"issuer,omitempty"`
ClientID string `json:"clientid,omitempty"` ClientID string `json:"clientid,omitempty"`
CustomerPortal string `json:"customer_portal,omitempty"` CustomerPortal string `json:"customer_portal,omitempty"`
InstanceManagementURL string `json:"instance_management_url,omitempty"` InstanceManagementURL string `json:"instance_management_url,omitempty"`
PostHogURL string `json:"posthog_url,omitempty"`
PostHogToken string `json:"posthog_token,omitempty"`
Exhausted bool `json:"exhausted,omitempty"` Exhausted bool `json:"exhausted,omitempty"`
}{ }{
API: api, API: api,
@@ -164,6 +170,8 @@ func createEnvironmentJSON(api, issuer, clientID, customerPortal, instanceMgmtUr
ClientID: clientID, ClientID: clientID,
CustomerPortal: customerPortal, CustomerPortal: customerPortal,
InstanceManagementURL: instanceMgmtUrl, InstanceManagementURL: instanceMgmtUrl,
PostHogURL: postHogURL,
PostHogToken: postHogToken,
Exhausted: exhausted, Exhausted: exhausted,
} }
return json.Marshal(environment) return json.Marshal(environment)