mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 06:12:55 +00:00
9a59d6a459
This commit adds support for centralized metrics. There are two providers as of now, and we haven't quite decided which one to go for, so for the time being both are supported. It also introduces a new endpoint InitializeApplication that replaces OpenAccounts
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package common
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
var (
|
|
ErrInvalidEventName = errors.New("centralized-metric: invalid-event-name")
|
|
ErrInvalidPlatform = errors.New("centralized-metric: invalid-platform")
|
|
ErrInvalidVersion = errors.New("centralized-metric: invalid-version")
|
|
)
|
|
|
|
type Metric struct {
|
|
ID string `json:"id"`
|
|
UserID string `json:"userId"`
|
|
EventName string `json:"eventName"`
|
|
EventValue map[string]any `json:"eventValue"`
|
|
Timestamp int64 `json:"timestamp"`
|
|
Platform string `json:"platform"`
|
|
AppVersion string `json:"appVersion"`
|
|
}
|
|
|
|
type MetricProcessor interface {
|
|
Process(metrics []Metric) error
|
|
}
|
|
|
|
func (m *Metric) Validate() error {
|
|
if len(m.EventName) == 0 {
|
|
return ErrInvalidEventName
|
|
}
|
|
if len(m.Platform) == 0 {
|
|
return ErrInvalidPlatform
|
|
}
|
|
if len(m.AppVersion) == 0 {
|
|
return ErrInvalidVersion
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *Metric) EnsureID() {
|
|
|
|
if len(m.ID) != 0 {
|
|
return
|
|
}
|
|
m.ID = uuid.New().String()
|
|
}
|