Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
refactor(telemetry): send config info in the usage event
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Jan 10, 2024
1 parent b294cc9 commit 723e667
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package telemetry

import (
"context"
"maps"
"os"
"runtime"
"sync"
Expand Down Expand Up @@ -137,12 +138,24 @@ func (t *Tracker) collectUsage() {
t.mu.Lock()
defer t.mu.Unlock()

t.Send("usage", t.observations)
props := t.appProperties()
maps.Copy(props, t.observations)

t.Send("usage", props)
}

func (t *Tracker) bootProperties() map[string]interface{} {
props := posthog.NewProperties()

props.Set("version", version.Version())
props.Set("os", runtime.GOOS)

return props
}

func (t *Tracker) appProperties() map[string]interface{} {
props := posthog.NewProperties()

// Basic info
props.Set("version", version.Version())
props.Set("os", runtime.GOOS)
Expand Down Expand Up @@ -173,6 +186,10 @@ func (t *Tracker) bootProperties() map[string]interface{} {
props.Set("prom", t.config.Metrics.HTTPEnabled())
props.Set("rpc-impl", t.config.RPC.Impl())

// AnyCable+
_, ok := os.LookupEnv("ANYCABLEPLUS_APP_NAME")
props.Set("plus", ok)

return props
}

Expand Down
2 changes: 1 addition & 1 deletion telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func TestTracking(t *testing.T) {

assert.Equal(t, "boot", event.Event)
assert.Equal(t, version.Version(), event.Properties["version"])
assert.Equal(t, "ecs-fargate", event.Properties["deploy"])

time.Sleep(100 * time.Millisecond)

Expand All @@ -95,6 +94,7 @@ func TestTracking(t *testing.T) {
event = client.captured[1]

assert.Equal(t, "usage", event.Event)
assert.Equal(t, "ecs-fargate", event.Properties["deploy"])
assert.Equal(t, 14, int(event.Properties["clients_max"].(uint64)))
assert.Equal(t, 100, int(event.Properties["mem_sys_max"].(uint64)))

Expand Down

0 comments on commit 723e667

Please sign in to comment.