Skip to content

Commit eafd586

Browse files
committed
address comment
1 parent 9267dc9 commit eafd586

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

cmd/gateway/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ func main() {
127127
// Initialize login server
128128
loginOptions := []login.LoginServerOption{login.WithConfig(gwConfig.Login), login.WithSessionStore(sessionStore), login.WithTokenStore(tokenStore)}
129129

130-
if gwConfig.Posthog.Enabled {
131-
metricsClient, err := metrics.NewPosthogClient(gwConfig.Posthog.ApiKey, gwConfig.Posthog.Host, gwConfig.Posthog.Environment)
132-
if err != nil {
133-
slog.Error("posthog client initializtion failed", "error", err)
134-
os.Exit(1)
135-
}
136-
loginOptions = append(loginOptions, login.WithMetricsClient(metricsClient))
130+
metricsClient, err := metrics.NewPosthogClient(gwConfig.Posthog)
131+
if err != nil {
132+
slog.Error("posthog client initializtion failed", "error", err)
133+
os.Exit(1)
134+
}
135+
if metricsClient != nil {
137136
defer metricsClient.Close()
138137
}
138+
loginOptions = append(loginOptions, login.WithMetricsClient(metricsClient))
139139
loginServer, err := login.NewLoginServer(loginOptions...)
140140
if err != nil {
141141
slog.Error("login handlers initialization failed", "error", err)

internal/config/other.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type RateLimits struct {
3232

3333
type PosthogConfig struct {
3434
Enabled bool
35-
ApiKey string
35+
ApiKey RedactedString
3636
Host string
3737
Environment string
3838
}

internal/metrics/posthog.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/md5"
55
"encoding/hex"
66

7+
"github.com/SwissDataScienceCenter/renku-gateway/internal/config"
78
"github.com/posthog/posthog-go"
89
)
910

@@ -24,12 +25,12 @@ func (p *PosthogMetricsClient) Close() {
2425
p.posthogClient.Close()
2526
}
2627

27-
func NewPosthogClient(apiKey string, host string, environment string) (*PosthogMetricsClient, error) {
28+
func NewPosthogClient(c config.PosthogConfig) (*PosthogMetricsClient, error) {
2829
client, err := posthog.NewWithConfig(
29-
apiKey,
30+
string(c.ApiKey),
3031
posthog.Config{
31-
Endpoint: host,
32-
DefaultEventProperties: posthog.Properties{"environment": environment},
32+
Endpoint: c.Host,
33+
DefaultEventProperties: posthog.Properties{"environment": c.Environment},
3334
},
3435
)
3536
if err != nil {

0 commit comments

Comments
 (0)