| 79 | } |
| 80 | |
| 81 | func Init(telemetryConfig Config) error { |
| 82 | if !telemetryConfig.Enabled { |
| 83 | _config = nil |
| 84 | return nil |
| 85 | } |
| 86 | |
| 87 | if telemetryConfig.UserID == "" { |
| 88 | return ErrorUserIDNotSpecified() |
| 89 | } |
| 90 | |
| 91 | err := sentry.Init(sentry.ClientOptions{ |
| 92 | Dsn: getSentryDSN(), |
| 93 | Release: consts.CortexVersion, |
| 94 | Environment: telemetryConfig.Environment, |
| 95 | }) |
| 96 | if err != nil { |
| 97 | _config = nil |
| 98 | return err |
| 99 | } |
| 100 | |
| 101 | var segmentLogger analytics.Logger |
| 102 | if !telemetryConfig.LogErrors { |
| 103 | sentry.Logger.SetOutput(silentSentryLogger{}) |
| 104 | segmentLogger = silentSegmentLogger{} |
| 105 | } |
| 106 | |
| 107 | writeKey := _segmentWriteKey |
| 108 | if envVar := os.Getenv("CORTEX_TELEMETRY_SEGMENT_WRITE_KEY"); envVar != "" { |
| 109 | writeKey = envVar |
| 110 | } |
| 111 | |
| 112 | _segment, err = analytics.NewWithConfig(writeKey, analytics.Config{ |
| 113 | BatchSize: 1, |
| 114 | Logger: segmentLogger, |
| 115 | DefaultContext: &analytics.Context{ |
| 116 | App: analytics.AppInfo{ |
| 117 | Version: consts.CortexVersion, |
| 118 | }, |
| 119 | Device: analytics.DeviceInfo{ |
| 120 | Type: telemetryConfig.Environment, |
| 121 | }, |
| 122 | }, |
| 123 | }) |
| 124 | if err != nil { |
| 125 | _config = nil |
| 126 | return err |
| 127 | } |
| 128 | |
| 129 | _config = &telemetryConfig |
| 130 | return nil |
| 131 | } |
| 132 | |
| 133 | func Event(name string, properties ...map[string]interface{}) { |
| 134 | integrations := map[string]interface{}{ |